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

How to convert batches of images with [H,W,C] shape into a dictionary of size [N,H,W,C]?

预处理图像形状和数据类型

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

image_list = np.concatenate(image_list, 轴=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

我想把它改成有图像的字典["train"],图像["valid"] 将大小为 [N,H,W,C] 的图像实例作为值

您需要先创建额外维度。

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)