tensorflow问题总结

目录

1、tensorflow python framework erros invalidArgmentError:connot batch tensors with different shapes in componet 0. First element had shape [227,227,3] and element 19 had shape [227,227,4]

2、incompatible type conversion requested to type 'uint8' for variable of type 'float32'

3、invalid literal for int() with base 10:

4、image.resize_images()#返回float

5、runtimeerror: Invalid DISPLAY variable

6、无法显示图片可以保存图片:

7、feed数据的时候不可以读进去tensor类型

8、a = sess.run(one_element[0])

9、不可以用两个one_element

10、Rank mismatch: Rank of labels(received 2) should equal rank of logits minus 1(recevied 2)

11、Y = tf.placeholder(tf.float32, [None])

12、Img.resize(227,227)提示unknown resampling filter

13、Tensorflow使用变量出现错误: List of Tensors when single Tensor expected

14、Tensorflow出错:Exception in QueueRunner: Enqueue operation was cancelled


 

 

在进行tensorflow学习的时候遇到各种各样的问题,为了不在同一个坑中踩多次,将问题总结一下。

1、tensorflow python framework erros invalidArgmentError:connot batch tensors with different shapes in componet 0. First element had shape [227,227,3] and element 19 had shape [227,227,4]

 

记得检查数据通道: convert('RGB')

 

2、incompatible type conversion requested to type 'uint8' for variable of type 'float32'

 

读进Conv2D的数据应该是float

 

3、invalid literal for int() with base 10:

 

txt文件下行千万不要有空格

 

4、image.resize_images()#返回float

     image.resize_images_with_crop_or_pad()#返回unit8

 

5、runtimeerror: Invalid DISPLAY variable

 

1.问题:在本地用matplotlib绘图可以,但是在ssh远程绘图的时候会报错 RuntimeError: Invalid DISPLAY variable

2.原因:matplotlib的默认backendTkAgg,而FltkAgg, GTK, GTKAgg, GTKCairo, TkAgg , Wx or WxAgg这几个backend都要求有GUI图形界面的,所以在ssh操作的时候会报错.

import matplotlib.pyplot as plt
Backend TkAgg is interactive backend. Turning interactive mode on.

plt.get_backend()
Out[3]: u'TkAgg'

3.解决方法:指定不需要GUI的backend(Agg, Cairo, PS, PDF or SVG

import matplotlib.pyplot as plt
plt.switch_backend('agg')

 

来自

 

6、无法显示图片可以保存图片:

plt.savefig('./test.png')

 

7、feed数据的时候不可以读进去tensor类型

 

8、a = sess.run(one_element[0])

加【】,数据就会由tensor变为list

 

9、不可以用两个one_element

X = sess.run(one_element[0])

Y = sess.run(one_element[1])

这样其实已经换了一个batch

应该是:x,y = sess.run(one_element)

 

10、Rank mismatch: Rank of labels(received 2) should equal rank of logits minus 1(recevied 2)

一开始总提示这一句错误

Loss_op = tf.reduce_mean(tf.nn.sparse_softmax_cross_entropy_with_logits(logits=out,labels=tf.cast(Y,dtype=tf.int32)))

当时是这样写的:

Y = tf.placeholder(tf.float32,[None,1])

把输入进去的Y形状打出来是(12,)

后改成这个就可以了:

Y = tf.placeholder(tf.float32,[None])

Y是什么形状,占位符就是什么形状,千万别乱加1!!!!

 

 

11、Y = tf.placeholder(tf.float32, [None])

y_one_hot = tf.one_hot(y, 10)

 

12、Img.resize(227,227)提示unknown resampling filter

改:img.resize((227,227))

 

13、Tensorflow使用变量出现错误: List of Tensors when single Tensor expected

原例:

b1 = tf.constant(tf.zeros([1,3]), name='b1')

提示: List of Tensors when single Tensor expected

结论: 因为tf.random_normal返回值是一个Tensor,但是tf.constat传入的形参是list二者类型是不匹配的,所以出现错误

改为:

b1 = tf.Variable(tf.zeros([1,3]), name='b1')

 

14、Tensorflow出错:Exception in QueueRunner: Enqueue operation was cancelled

将:

#没有定义cooed
tf.train.start_queue_runners()

改成:

coord = tf.train.Coordinator()
tf.train.start_queue_runners(coord=coord)

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(深度学习Tensorflow)