【Tensorflow】anaconda3配置tensorflow各种报错的解决

1. 安装tensorflow报错

(1)tensorflow 2.X Failed to load the native TensorFlow runtime 问题:

https://blog.csdn.net/roamer314/article/details/106461717

备注:安装 Microsoft Visual C++ downloads 即可解决报错。

(2)AttributeError: module 'tensorflow' has no attribute 'placeholder'问题:

tensorflow2.0运行1.0的代码会报这个错误

解决方案1(在代码中关闭eager运算):

import tensorflow.compat.v1 as tf

tf.disable_eager_execution()

2. keras报错

File "C:\Anaconda3\lib\site-packages\keras\utils\generic_utils.py", line 140, in deserialize_keras_object
    ': ' + class_name)
ValueError: Unknown layer: Merge

备注:在用keras训练好一个模型之后,在另外一个地方导入出错误,这是由于版本问题导致的;需要确保keras的版本相同才行。

比如楼主这个报错,原因是从keras 2开始,Merge layers已经不再被keras使用了。

需要回滚到 Keras-1.2.2

pip install Keras==1.2.2

安装过程中,会提示:Successfully uninstalled Keras-2.2.4,表示卸载了原版本。这个原版本号可能有用,记下来,方便复原。

3. 如果仍然报错,试试更换低版本tensorflow:

笔者就是在新机器上安装tensorflow 3.6,仍然无法运行github上的代码。换回旧机器就能成功运行!

因此,我发现不是python版本问题,而是tensorflow版本的问题。试试这个:

pip install tensorflow==1.12.0

4.header1.10.4和library1.10.5不匹配报错

装完tensorflow2.0版本一直使用正常,然后不知道怎么就同意了更新anaconda, 就出现了header1.10.4和library1.10.5不匹配的问题,百度了很多方法,最后这个有用,非常感谢博主https://blog.csdn.net/qq_44735193/article/details/105003622。

pip uninstall h5py
pip install h5py

 

你可能感兴趣的:(Python编程手册)