当前位置:网站首页>ModuleNotFoundError: No module named 'tensorflow.keras' error message solution
ModuleNotFoundError: No module named 'tensorflow.keras' error message solution
2022-08-01 04:51:00 【hi_1900】
ModuleNotFoundError: No module named 'tensorflow.keras’The solution to the error message
Index 目录索引
错误信息
解决方法
适用于Windows用户的方法
适用于Linux用户的方法
using deep learning methods,Training an artificial neural network model egEfficientNet的时候,由于kerasThe reason for the different installation directories of files such as libraries,Various errors may be reported due to incompatibility,This series focuses on documenting the various error resolutions I encountered during training,供大家参考和学习.
错误信息:
话不多说,The error message is thrown first:
Traceback (most recent call last):
File "**/training.py", line 4, in <module>
from tensorflow.keras import models
ModuleNotFoundError: No module named 'tensorflow.keras'
Error messages are a good thing,You have to learn how to unearth useful things from error messages.
The code block corresponding to this error message is as follows:
from tensorflow.keras import models
from tensorflow.keras import layers
from tensorflow.keras import optimizers
from tensorflow.keras.preprocessing.image import ImageDataGenerator
解决方法:
We found that the above error occurred when importing the package,是因为kerasThe reason for the library installation directory incompatibility,We find ourselves firstkeras的本地安装目录,这里分别就Windows用户和LinuxThe user introduction method is as follows:
适用于Windows用户的方法:
Let's create a new one firstpython文件keras_dir.py,用于输出keras的本地安装目录,在新建的python文件中输入如下代码,即可查询keraswhere the local directory is located(It should be noted in the following codepathBoth sides are double underlined).
from tensorflow import keras
print(keras.__path__)
运行keras_dir.pyThe output is displayed as follows:
D:\Anaconda3-5.1.0\envs\tensorflow-gpu\python.exe **/keras_dir.py
['D:\\Anaconda3-5.1.0\\envs\\tensorflow-gpu\\lib\\site-packages\\tensorflow\\tools\\api\\generator\\api\\keras']
Process finished with exit code 0
通过输出的信息,我们可以得知kerasis installed on the local diskD盘下的D:\Anaconda3-5.1.0\envs\tensorflow-gpu\Lib\site-packages\tensorflow\tools\api\generator\api\keras这个目录中.Different computers may find different outputkerasThe directory where it is located can be compared
Look closely at this directory path,我们可以发现keras并不是直接在tensorflow目录下的,在tensorflow和kerasThere are several directories in between,So we can pass the correct inputkerasdirectory location to successfully invokekeras库了,文章最开始的kerasThe calling statement is modified as follows:
from tensorflow.tools.api.generator.api.keras import models
from tensorflow.tools.api.generator.api.keras import layers
from tensorflow.tools.api.generator.api.keras import optimizers
from tensorflow.tools.api.generator.api.keras.preprocessing.image import ImageDataGenerator
修改后再次运行,You can find that this error message will no longer appear.
适用于Linux用户的方法
同样的,still create firstpython文件keras_dir.py,运行keras_dir.pyThe output is displayed as follows:
[**@** EfficientNet]# python keras_dir.py
['/usr/local/python3/lib/python3.6/site-packages/tensorflow/_api/v1/keras']
可以看到keras的安装目录,We modify the program calls according to the directorykeras库的语句:
from tensorflow._api.v1.keras import models
from tensorflow._api.v1.keras import layers
from tensorflow._api.v1.keras import optimizers
from tensorflow._api.v1.keras.preprocessing.image import ImageDataGenerator
至此,We successfully solved itModuleNotFoundError: No module named 'tensorflow.keras’这个错误.
边栏推荐
- [FPGA tutorial case 43] Image case 3 - image sobel edge extraction through verilog, auxiliary verification through MATLAB
- lambda
- (2022牛客多校四)N-Particle Arts(思维)
- Game Theory (Depu) and Sun Tzu's Art of War (42/100)
- 万字逐行解析与实现Transformer,并进行德译英实战(二)
- 时时刻刻保持敬畏之心
- 【目标检测】YOLOv7理论简介+实践测试
- 【愚公系列】2022年07月 Go教学课程 025-递归函数
- Code Interview Guide for Programmers CD15 Generating an Array of Windowed Maximums
- LeetCode 387. 字符串中的第一个唯一字符
猜你喜欢

typescript25-类型断言

(more than 2022 cattle school four) A - Task Computing + dynamic programming (sort)

万字逐行解析与实现Transformer,并进行德译英实战(一)

Mysql基础篇(约束)

II. Binary tree to Offer 68 - recent common ancestor

深圳某游戏研发公司给每个工位都装监控,网友:堪比坐牢!

2022-07-31: Given a graph with n points and m directed edges, you can use magic to turn directed edges into undirected edges, such as directed edges from A to B, with a weight of 7.After casting the m

(2022 Nioke Duo School IV) D-Jobs (Easy Version) (3D prefix or)

MySQL-数据定义语言-DDLdatebase define language

56:第五章:开发admin管理服务:9:开发【文件上传到,MongoDB的GridFS中,接口】;(把文件上传到GridFS的SOP)
随机推荐
August 22 Promotion Ambassador Extra Reward Rules
Typescript20 - interface
typescript21-接口和类型别名的对比
Excel record of integer programming optimization model to solve the problem
25. 这三道常见的面试题,你有被问过吗?
Immutable
深圳某游戏研发公司给每个工位都装监控,网友:堪比坐牢!
初识shell脚本
Logitech Mouse Experience Record
解决ffmpeg使用screen-capture-recorder录屏,有屏幕缩放的情况下录不全的问题
Excuse me, only primary key columns can be queried using sql in table storage. Does ots sql not support non-primary keys?
项目风险管理必备内容总结
【kali-信息收集】枚举——DNS枚举:DNSenum、fierce
56:第五章:开发admin管理服务:9:开发【文件上传到,MongoDB的GridFS中,接口】;(把文件上传到GridFS的SOP)
ICML2022 | Deep Dive into Permutation-Sensitive Graph Neural Networks
数组问题之《两数之和》以及《三数之和 》
请问shake数据库中为什么读取100个collection 后,直接就退出了,不继续读了呢?
PAT serie b write the number 1002
typescript20-接口
剑指 Offer 68 - I. 二叉搜索树的最近公共祖先