如何将具有[H,W,C]形状的成批图像转换为大小为[N,H,W,C]的字典?

时间:2019-06-09 21:43:12

标签: tensorflow tensorflow-datasets

预处理的图像形状和dtype

(240, 320, 3)
<dtype: 'float32'>

image_list = np.concatenate(image_list,axis = 0) 它确实起作用。

ValueError: zero-dimensional arrays cannot be concatenated

我的上述代码如下

  for count, filename in enumerate(files):
    image = tf.read_file(filename)
    image = tf.image.decode_png(image, channels=3)
    image = tf.image.resize_images(image, [240, 320])
    image /= 255.0  # normalize to [0,1] range

我想将其更改为带有image [“ train”],image [“ valid”]的字典 以大小为[N,H,W,C]的图像实例为值

1 个答案:

答案 0 :(得分:0)

您需要先创建额外的尺寸。

image_list = np.zeros([240, 320, 3])
print(image_list.shape) # (240, 320, 3)

image_list = np.expand_dims(image_list, axis=0)
print(image_list.shape) # (1, 240, 320, 3)

image_list = np.concatenate([image_list, image_list], axis=0)
print(image_list.shape) # (2, 240, 320, 3)