Tensorflow-各种错误和解决方案

1 Tensorflow-[版本更替]报错解决方案

AttributeError: ‘module’ object has no attribute ‘SummaryWriter’

tf.train.SummaryWriter

	改为:==tf.summary.FileWriter==
AttributeError: ‘module’ object has no attribute ‘summaries’

tf.merge_all_summaries()

	改为:==summary_op = tf.summary.merge_all()==
AttributeError: ‘module’ object has no attribute ‘histogram_summary’

tf.histogram_summary()

	改为:==tf.summary.histogram()==
  • tf.scalar_summary()

      改为:==tf.summary.scalar()==
    
  • tf.image_summary()

      改为:==tf.summary.image()==
    

参考:https://github.com/tensorflow/tensorflow/blob/master/tensorflow/tensorboard/README.md

参考:http://blog.csdn.net/edwards_june/article/details/65652385

RuntimeError: get_session is not available when using TensorFlow 2.0.

说明:说明你的tensorflow版本是2.0的,2.0版本没有这个方法;

解决方式:降低tf的版本;

或者

使用tf.compat.v1.keras.backend.get_session代替K.get_session(),后如果接run,去掉run

2.PIL相关

Python Imaging Library (PIL)

  • from PIL import Image
    ModuleNotFoundError: No module named ‘PIL’

解决办法:

Step 1:打开命令窗口,Win+R打开运行窗口输入:cmd。
Step 2:进入python安装路径下的Scripts目录中,如:cd C:\Users\Administrator\AppData\Local\Programs\Python\Python37\Scripts。
Step 3:再次输入命令:pip install pillow。_

安装PIL(libjpeg.so.9: cannot open shared object file: No such file or directory)
默认anaconda貌似是没有PIL的,根据https://anaconda.org/anaconda/pil,使用下面命令安装:

conda install -c anaconda pil=1.1.7
但是安装后,莫名其妙的提示:

libjpeg.so.9: cannot open shared object file: No such file or directory
在anaconda/lib文件夹内,有libjpeg.so.8,但是没有libjpeg.so.9(安装PIL之前没出问题,安装后出了问题,不清楚具体原因)

https://github.com/conda-forge/cdo-feedstock/issues/9中,ywangd指出,使用如下命令更新libjpeg就行了:

conda update -c conda-forge jpeg
我这边第一次使用上面命令后,还是libjpeg.so.8,后来又试了一次,就变成libjpeg.so.了。。。哎。

标签: python, torch, anaconda

3

https://www.cnblogs.com/jcraft/p/12425663.html

4 加隐层要注意细节

我自己在用tensorflow训练Mnist 时,尝试加一层隐含层,但是因为不细心,没有把全连接层的参数改对
InvalidArgumentError (see above for traceback): Incompatible shapes: [800] vs. [400]
[[node Accura

#First Convolutional Layer
with tf.name_scope('2rd_CNN'):
	W_conv2 = weight_variable([3, 3, 32, 64])
	h_conv2 = conv2d(h_pool1, W_conv2) #[28,28,32]
	h_pool2 = max_pool_2x2 (h_conv2) #[7,7,32]

##!!!
#Densely Connected Layer
with tf.name_scope('Densely_NN'): 
	W_fc1 = weight_variable([ 7* 7* 64, 256])
	h_pool2_flat = tf.reshape(h_pool2, [-1, 7* 7* 64])#就是这里,没有改成链接的最后一层
	h_fc1= tf.matmul(h_pool2_flat , W_fc1) # [256]

通过更改完全连接层中的值来修复错误

这是经过编辑的代码

# Densely Connected Layer
W_fc1 = weight_variable([2 * 2 * 128, 1024])
b_fc1 = bias_variable([1024])

h_pool2_flat = tf.reshape(h_pool4, [-1, 22128])
h_fc1 = tf.nn.relu(tf.matmul(h_pool2_flat, W_fc1) + b_fc1)

  • 5
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值