0

I'm trying to use VGG, but input request 3 channels but my imput_shape'channel=1 I use nibabel to slice the MRI (nii)

ValueError: The input must have 3 channels; got input_shape=(256, 256, 1)

Here is my code about MRI slices.

code

 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
Community
  • 1
  • 1
张鉷涛
  • 1
  • 1

1 Answers1

0

I too had the same problem, The VGG model is trained on a 3 channel(RGB) input imags but as you are providing Grayscale image which is only 1 channel it shows an error

if you want to solve with TensorFlow use

tf.image.grayscale_to_rgb()

If its Keras

datagen_train = ImageDataGenerator()
train_generator = datagen_train.flow_from_directory(directory_name,
<other parameters>,color_mode="rgb")