0

我正在尝试使用 VGG,但输入请求 3 个通道但我的 imput_shape'channel=1 我使用 nibabel 切片 MRI (nii)

ValueError:输入必须有3个通道;得到input_shape=(256, 256, 1)

这是我关于 MRI 切片的代码。

代码

 images = []
     images_ground = []
     for f in range(len(g)):
          a = nib.load(g[f])
          a = a.get_data()
          b = nib.load(g[f])
          b = b.get_data()
          a=a[:,:,48:166]
          b = transform.resize(b, (64, 64, 256))
          b=b[:,:,48:166]

          for i in range(a.shape[2]):
             images_ground.append(a[:,:,i])
             images.append(b[:, :, i])                 
     images_ground = np.array(images_ground)
     images_ground = images_ground.reshape(-1, 256, 256, 1)
     images = np.array(images)
     images = images.reshape(-1, 64, 64, 1)
     m = np.max(images)
     mi = np.min(images)
     images = (images - mi) / (m - mi)
     n=np.max(images_ground)
     ni=np.min(images_ground)
     images_ground=(images_ground-ni)/(n-ni)
     return images,images_ground
4

1 回答 1

0

我也有同样的问题,VGG 模型是在 3 通道(RGB)输入图像上训练的,但是当您提供只有 1 个通道的灰度图像时,它会显示错误

如果你想用 TensorFlow 解决,请使用

tf.image.grayscale_to_rgb()

如果它的 Keras

datagen_train = ImageDataGenerator()
train_generator = datagen_train.flow_from_directory(directory_name,
<other parameters>,color_mode="rgb")
于 2020-06-26T13:08:51.507 回答