在用tf.image.random_crop(image,size,seed=None,name=None)
函数的过程中,出现了
assertion failed: [Need value.shape >= size, got ] [300 533 4] [600 600 3]的问题:
源代码如下
import matplotlib.pyplot as plt
import tensorflow as tf
import numpy as np
#读取图像的原始数据
image_raw_data= tf.gfile.FastGFile('C:\\Users\\leeju\\Pictures\\Camera Roll\\9b74aab8459e59476db8b1a8731cdd96.jpg','rb').read()
with tf.Session() as sess:
#对图像进行jpeg的格式解码从而得到图像对应的三维矩阵
img_data = tf.image.decode_jpeg(image_raw_data)
#img_data = tf.image.decode_png(image_raw_data)
#解码之后的结果是一个张量
#print(img_data.eval())
#可视化
plt.imshow(img_data.eval())
plt.show()
with tf.Session() as sess:
img_data = tf.image.decode_jpeg(image_raw_data)
random_croped1 = tf.random_crop(img_data,[600,600,3])
plt.imshow(random_croped1.eval())
plt.show()
原因查找
此处使用的随机裁剪是将图片裁剪为600 * 600的3通道RGB图像,之前用的是499*375的3通道图,如下
经过测试,发现是因为被剪裁的图片小于剪裁要求,故更换1920 * 1080 * 3的图片,问题解决!