1

I'm trying to train a ResNet50 model with grayscale images. Since I need the data augmentation functionality of the ImageDataGenerator, I have to implement the logic in to the preprocessing_function. But I run into an error for the following configuration. Could anybody help with the correct configuration?

    def preprocess_greyscale(images):
      tensor = tf.convert_to_tensor(images)     
      tensor = tf.image.grayscale_to_rgb(tensor)
      return(tensor)

    trainDataGenerator = ImageDataGenerator(
      rescale=1/255,
      preprocessing_function = preprocess_greyscale,
      rotation_range=5,
      zoom_range=[0.95, 1],
      horizontal_flip=True, 
      # vertical_flip=True,
      width_shift_range=0.05,
      height_shift_range=0.1,
      brightness_range=[0.7, 1.0],
      fill_mode="constant",
      cval=75
    )

   trainData = trainDataGenerator.flow_from_directory(
     datasetTrainDirectory,
     batch_size = batchSize,
     class_mode = "binary",
     color_mode = "grayscale",        
     shuffle = True,        
     target_size = (width, height)
   )

Traceback

surtr
  • 65
  • 3

0 Answers0