Loading images using image_dataset_from_directory

I have used to load images from a directory to python using image_dataset_from_directory. After loading the images I have done required preprocessing and then passed to the model, while I fit the model I am getting an error

'InvalidArgumentError:  Incompatible shapes: [20,1] vs. [20,256,256,3]
     [[node mean_squared_error/SquaredDifference (defined at <ipython-input-57-d43d80c563d5>:7) ]] [Op:__inference_train_function_13717]'

. why am I getting this error, is it reading the label_batch including the image_batch? How to send only the image batch and exclude the label_batch?

train_ds = image_dataset_from_directory(
    path,color_mode='rgb', batch_size = 20, image_size=(256,
    256))
for image_batch, labels_batch in train_ds:
  print(image_batch.shape)
  print(labels_batch.shape)
  break
(20, 256, 256, 3)
(20,)

My model and fitting:-
from tensorflow.keras.layers import Conv2D,Dropout, Input,Conv2DTranspose,Concatenate
from keras.layers.normalization import BatchNormalization 
from tensorflow.keras.initializers import orthogonal
from keras.models import Model
import tensorflow.keras.models as models
def AutoEncdoer(input_shape):
  inputs = Input(shape=input_shape)
  rescale = Rescaling(1./255) (inputs)
  encoder1 = Conv2D(64, kernel_size=3, strides=1, activation = 'LeakyReLU',padding='same')(rescale)
  encoder1 = Dropout(0.2)(encoder1)
  . 
  .
  .
  and so on
  return models.Model(inputs=inputs, outputs=output)
model.compile(optimizer=model_opt, loss='mse', metrics=['accuracy'])
history = model.fit(train_ds, validation_data=val_ds,
          epochs=500)
error:-
InvalidArgumentError:  Incompatible shapes: [20,1] vs. [20,256,256,3]
     [[node mean_squared_error/SquaredDifference (defined at <ipython-input-57-d43d80c563d5>:7) ]] [Op:__inference_train_function_13717]

Source: Python Questions

LEAVE A COMMENT