windows tensorflow keras 安装

系统环境:win10,其它编译环境我不是很清楚,电脑从离职同事那里接手未格式化。
python环境:anaconda 4.9.2;python 3.8.3;
安装步骤:
1.pip install tensorflow
全部自动安装,包括相关依赖,tensorflow接近500M,安装过程耗时较长,版本为2.5.0
2.pip install keras
全部自动安装,版本为2.4.3
3.跑keras的demo脚本mnist_irnn.py失败,报错
AttributeError: module 'keras.utils.generic_utils' has no attribute 'populate_dict_with_module_objects'
发现是anaconda3\Lib\site-packages\keras\utils\generic_utils.py没有函数populate_dict_with_module_objects,去网上copy了一份函数源码写入generic_utils.py,但报新的错:AttributeError:module 'keras.utils.generic_utils' has no attribute 'to_snake_case',
这个也是generic_utils.py里面的缺失,于是到https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/keras/utils/generic_utils.py,复制粘贴所有内容到generic_utils.py,成功运行demo脚本

1、2都很顺利就是简单的pip安装,出问题就是第三步,解决方案参考了https://blog.csdn.net/zcw1234515/article/details/115017105

20210819更新:
我又在python3.7.3的环境进行了安装,python3.7.3是我conda创建的另一个环境
直接pip install tensorflow,自动安装了诸多依赖,其中包括Keras,安装的最新tensorflow是2.6.0,keras是2.6,再使用pip install keras提示已经存在,而且目前keras完全集成在tensorflow之中了,以后使用keras只需要用tf.keras便可,但是我用安好的tensorflow直接跑keras的example mnist_irnn.py和mnist_cnn.py存在报错,无法跑通,引用报错,应该是一些组件的引用位置变过了。我自己在tf 2.5中建的模可以在2.6中载入并且跑通,且最后结果一致。



留言

熱門文章