运行代码问题

1.出现cannot import name ‘tf2‘是因为keras与tensorflow版本不一

 

2.如果出现网速过慢,无法下载的问题

 使用:pip --default-timeout=100 install 库名称 -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com

此外,镜像网站:
清华:https://pypi.tuna.tsinghua.edu.cn/simple 阿里云:http://mirrors.aliyun.com/pypi/simple/ 中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/ 华中科技大学:http://pypi.hustunique.com/
山东理工大学:http://pypi.sdutlinux.org/ 豆瓣:http://pypi.douban.com/simple/

3.pip安装tensorflow报错:could not find a version that satisfies the requirement grpcio>=1.8.6

 

出错原因:grpcio的版本不够新
在pycharm的命令框Terminal更新grpcio:pip install --upgrade grpcio
再在命令框中使用pip install tensorflow安装tensorflow

又出现ERROR: Could not find a version that satisfies the requirement google-auth<2,>=1.6.3 (from tensorboard<3,>=2.3.0->tensorflow) (from versions: none) ERROR: No matching distribution found for google-auth<2,>=1.6.3 (from tensorboard<3,>=2.3.0->tensorflow)

出错原因:google-auth版本不够新
在pycharm的命令框更新grpcio:pip install --upgrade google-auth

再在命令框中使用pip install tensorflow安装tensorflow

安装成功

4.python安装库最后出现问题:

 

解决方法:

              换一个镜像源安装pip install spleeter -i https://mirrors.aliyun.com/pypi/simple

5.出现

 

解决办法:

pip3 install pillow

6.出现

 

原因:module ‘tensorflow’ has no attribute ‘get_default_graph’
当我使用keras和tensorflow做深度学习的时候,python3.7报了这个错误,这个问题源自于keras和TensorFlow的版本过高导致模块不存在或者已经更改不再兼容

解决办法,1.降级。改为python3.6.5,TensorFlow1.12.0和keras 2.2.4对应关系如下https://docs.floydhub.com/guides/environments/

                  2.使用from tensorflow import keras而不是直接使用:import keras;将from keras import layers改为from tensorflow.keras import layers

7.ImportError: No module named cv2

解决:pip install --user opencv-python -i https://pypi.douban.com/simple/

8.ImportError: Could not import PIL.Image. The use of array_to_img requires PIL.Image

解决:pip3 install pillow(若在terminal中pip不管用,则取cmd运行界面使用)

9.

pycharm调试 Process finished with exit code -1073740791 (0xC0000409)

控制台只提示这个

Process finished with exit code -1073740791 (0xC0000409)

但是根本没有报错原因

首先我们应该改一下pycharm设置

 

 

 

 

勾选这个 

下次跑代码就会有错误原因了,再根据错误进行更改

10.对于python中缺少一个必须的参数"self"    如name 'self' is not defined:

    self定义:https://stackoverflow.com/questions/17534345/typeerror-missing-1-required-positional-argument-self/47620199#47620199

11.TypeError: 'module' object is not callable

解决方法:
更改问题代码。
因为tensorflow不同的版本,语法的使用会有所不同。

#更改前
merge6 = merge([crop4,up6], mode = 'concat', concat_axis = 3)

#更改后
merge6 = Concatenate([drop4,up6],axis=3)

同理更改merge7,8,9:

#更改后
merge7 = Concatenate(axis=3)([conv3, up7])
...
merge8 = Concatenate(axis=3)([conv2, up8])
...
merge9 = Concatenate(axis=3)([conv1, up9])

12.出现TypeError: ('Keyword argument not understood:', 'input')

分析
找到有问题的代码,model = Model(input=inputs, output=[nestnet_output_4])
解决:换成model = Model(inputs=..., outputs=...)

13.出现TypeError: fit() got an unexpected keyword argument 'nb_epoch'

解决:把 nb_epoch 修改 为 epochs

14.pycharm中import导入包呈现灰色问题之解决!

https://blog.csdn.net/pythonxiaohei/article/details/99698027

 

posted @   heyrro  阅读(397)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· winform 绘制太阳,地球,月球 运作规律
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 上周热点回顾(3.3-3.9)
点击右上角即可分享
微信分享提示