最近,在学习tensorflow的过程中,制作tfrecords数据集时,时常会抛出
tensorflow : Input to reshape is a tensor with 16384 values, but the request 49152等问题
花了挺长时间,看了很多的博客,最终发现是制作数据时,有些图片出现问题。我的解决思路就是找到出问题的图片删除,问题自然就解决了,特此提供我寻找问题图片的方法,希望有帮助。
我的查错代码如下:
from PIL import Image
import tensorflow as tf
filenames =glob.glob('./data/PetImages/Cat/*.jpg')
with tf.Session() as sess:
for i in range(3000):
try:
img=Image.open(filenames[i])
img= img.resize((128,128))
img = tf.reshape(img , [128,128,3]).eval()
if not i%1000:
print('检错进度%d'%i)
except :
print(filenames[i])
我将PIL和tf.reshape结合在一起,来查找问题图片,可以实现图片的查找。但是这个程序有个问题,就是执行起来有点慢,有能力的人可以优化一下,顺便告诉我一下。