当前位置:网站首页>AttributeError: module ‘tensorflow.keras. utils‘ has no attribute image_ dataset_ from_ Directory - solution
AttributeError: module ‘tensorflow.keras. utils‘ has no attribute image_ dataset_ from_ Directory - solution
2022-07-22 20:08:00 【alphanoblaker】
In raspberry pie , by python3.7 Set up well tensorflow2.4( Brief process of construction ) After the environment of , There are problems like this when running code
First , utilize :
import tensorflow as tf
print(tf.keras.utils.__file__)
Search for tf.keras.utils Modular __init__.py Path to file :
then , Open this tensorflow/keras/utils/__init__.py
file , Find out tensorflow.keras.utils The functions and classes in are from tensorflow.python.keras in import Over here , After with windows Next tensorflow 2.7 Of __init__.py Contrast .
windows Of __init__.py The documents are as follows :
On raspberry pie, follow :
from tensorflow.python.keras.preprocessing.image_dataset import image_dataset_from_directory
I found my path image_dataset_from_directory:
It means raspberry pie tf There is this function , It's just tensorflow/keras/utils/__init__.py
No document import This function , So at runtime, there is no __init__.py This function is found in the file and an error is reported .
You can see ,tensorflow/keras/utils/__init__.py
Files are automatically generated , Not necessarily complete :
So add a pair of image_dataset_from_directory Function reference
Then add :
from tensorflow.python.keras.preprocessing.image_dataset import image_dataset_from_directory
perhaps , Directly in tensorflow/keras/utils/__init__.py
Add... To the file :
from tensorflow.python.keras.preprocessing.image_dataset import image_dataset_from_directory
after , It can be used normally in the code tf.keras.utils.image_dataset_from_directory
了
notes : Similar problems may also be solved through this method of viewing the source code .
such as , The same version of tensorflow Of tf.lite The next level is funcA This function , But in the new environment AttributeError, You can start with :
import tensorflow as tf
print(tf.lite.__file__)
to glance at tf.lite Of __init__.py Path to file :
Then similar to the above method , And can quote normally funcA Functional tensorflow Of __init__.py Contrast , In the new environment __init__.py Add... To the file funcA Function related references are ok
边栏推荐
猜你喜欢
Youboxun helps Shenzhen build a global "city of Hongmeng Oula"
SparkSQL Dataset的创建
记一次win10安装cupy的失败经历(附 cupy与numpy对比)
优博讯助力深圳打造全球“鸿蒙欧拉之城”
Spark loads CSV and JSON files (attached to the virtual machine to execute the jar package)
Spark Jason log analysis
NFT卡牌链游系统Dapp开发搭建
spark Json日志分析
Fluent 2 Advanced (IV): Based on navigator 2.0 packaging
Flutter 2 Advanced (I): practical skills of flutter
随机推荐
if else优化
Flutter 2进阶(五):json_serializable使用
leetcode 209. 长度最小的子数组
Kotlin学习一:变量、函数、条件语句与循环语句
The problem of overwriting array when pushing
Tensor和NumPy相互转换「建议收藏」
Differences among VaR, let and Const
通过shell脚本进行数据库操作
LogBack & MDC & a simple use
微服务——Eruka
try catch
美国土安全局对特勤局删除的国会大厦骚乱期间电子通信记录展开调查
人和产品的五个层次
HTB- Armageddon
左侧宽度固定、右侧宽度自适应
xcode 编译pod 第三方库报错
Kotlin学习三:集合与Lambda
栈题目:基本计算器 II
Development and construction of NFT card chain game system DAPP
Spark Jason log analysis