【发布时间】:2020-03-31 16:14:26
【问题描述】:
我正在尝试绘制由我的图像生成器创建的图像。到目前为止,这是我提供给生成器的数据代码:
train_img_gen = train_img_data_gen.flow_from_directory(os.path.join(training_dir, 'images'),
target_size=(img_h, img_w),
batch_size=bs,
class_mode=None, # Because we have no class subfolders in this case
shuffle=True,
interpolation='bilinear',
seed=SEED)
#edited part following the already existing answer on stackoverflow
x_batch, y_batch = next(train_img_gen)
for i in range (0,32):
image = x_batch[i]
plt.imshow(image.transpose(2,1,0))
plt.show()
我关注了这个问题:Keras images,但没有任何成功。
如何绘制(例如)我的imageGenerator 生成的前 n 张图像?
编辑:
我添加了上述问题中使用的代码,但出现此错误:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-7-1a18ce1c1a76> in <module>
54 valid_gen = zip(valid_img_gen, valid_mask_gen)
55
---> 56 x_batch, y_batch = next(train_img_gen)
57 for i in range (0,32):
58 image = x_batch[i]
ValueError: too many values to unpack (expected 2)
【问题讨论】:
-
您收到错误消息了吗?始终将完整的错误消息(从单词“Traceback”开始)作为文本(不是截图)(不是评论)。还有其他有用的信息。
-
编辑错误
-
将结果赋值给一个变量
result = next(train_img_gen)并打印它print(result)- 它似乎只返回一个值,而不是您期望的两个值。也许你需要x_batch = next(train_img_gen)。 -
result 返回具有以下形状的元素矩阵:(4, 256, 256, 3)
-
因此您可能有 4 张尺寸为
256x256和 RGB (3) 颜色的图像。可以尝试显示plt.imshow( result[0] )plt.imshow( result[1] )等
标签: python image-processing keras data-augmentation