Tensorflow学习常见问题汇总

1.导入MNIST失败,ModuleNotFoundError: No module named ‘tensorflow.examples’
使用

`from tensorflow.examples.tutorials.mnist import input_data`

该问题原因:编译环境无指定的数据集,导报错;
解决方法:
第一种:
(1)先要明确编译环境,是自定义环境还是系统默认环境,使用tf.__path__查询,默认环境目录:D:/Anaconda3/envs/环境名称/Lib/site-packages/tensorflow,自定义环境目录:D:/Anaconda3/envs/环境名称/Lib/site-packages/tensorflow
(2)确定环境后,在指定环境中安装使用pip安装对应package,如 pip install sklearn;pip install keras等
(3)还有一种情况,在系统环境中没有添加或者缺少目录,在PYTHONPATH中加入D:/Anaconda3/envs/环境名称/Lib/site-packages/tensorflow

第二种:
参考 https://stackoverflow.com/questions/50313441/modulenotfounderror-no-module-named-tensorflow-examples

(1)I solved this issue by adding tutorial directory into tensorflow_core, usually this issue pops up when lacking of this file
…\anaconda3\envs\tensorflow\Lib\site-packages\tensorflow_core\examples check this directory to see if you have tutorials file. lack of tutorial file
(2)If you do not have, then go to https://github.com/tensorflow/tensorflow download the zip file, and extract all (or open it). download tutorial file or git clone https://github.com/tensorflow/tensorflow (预先安装pip install git )
find tutorials file from tensorflow-master\tensorflow\examples, and copy it to …\anaconda3\envs\tensorflow\Lib\site-packages\tensorflow_core\examples. cp -a tensorflow/examples/ /usr/local/lib/python3.7/site-packages/tensorflow_core/examples/
(3)Issue resolved. run

第三种:
(1)安装tensorflow_datasets(该数据集会和tensorflow在一个目录下(如,D:\ProgramData\Anaconda3\Lib\site-packages),和tensorflow package是并列关系,相当于不从tensorflow下调用,而是单独从tensorflow_datasets这个package调用)

pip install tensorflow_datasets -i https://pypi.tuna.tsinghua.edu.cn/simple

(2)调用

import tensorflow_datasets
mnist = tensorflow_datasets.load('mnist')

第四种:(简单/不出错)
使用keras导入,第一次导入时,系统自动在官网下载数据集,然后在mnist.load自动加载;若数据集已经存在或者copy到指定目录下,可以自动加载,不需用下载。

`from keras.datasets import mnist
`(x_train,y_train),(x_test,y_test) = mnist.load_data('mnist/mnist.npz')

第四种:(比较复杂)
提前下载数据集至指定位置,然后使用二进制读取文件方式读取,该方法比较麻烦,请参考:
https://www.cnblogs.com/xianhan/p/9145966.html

2.Tensorflow导入缺少attribute
AttributeError: module ‘tensorflow’ has no attribute ‘placeholder’
AttributeError: module ‘tensorflow’ has no attribute ‘placeholder’
AttributeError: module ‘tensorflow’ has no attribute ‘version’

`

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值