'InvalidArgumentError: input depth must be evenly divisible by filter depth: 3 vs 6

    input_shape=(100,100,6)
    input_tensor=keras.Input(input_shape)


    model.add(Conv2D(32, 3, padding='same', activation='relu', input_shape=input_shape))
    model.add((Conv1D(filters=32, kernel_size=2, activation='relu', padding='same')))
    model.add(MaxPooling2D(pool_size=2))
    model.add(Dropout(0.2))
    model.add(Conv2D(64, 3, padding='same', activation='relu', input_shape=input_shape))
    model.add(MaxPooling2D(pool_size=2))
    model.add(Dropout(0.2))
    model.add(Conv2D(128, 3, padding='same', activation='relu', input_shape=input_shape))
    model.add(MaxPooling2D(pool_size=2))
    model.add(Dropout(0.2))
    model.add(Flatten())
    model.add(Dense(128, activation='relu'))
    model.add(Dropout(0.2))
model.compile(loss='categorical_crossentropy', optimizer="adam", metrics=['accuracy'])

training_set = train_datagen.flow_from_directory('/content/gdrive/My Drive/Data/training_set',
                                                 target_size = (128, 128),
                                                 batch_size = 32,
                                                 class_mode = 'categorical')

history=model.fit(training_set,
                  steps_per_epoch=nb_train_images//batch_size,
                  epochs=100,
                  validation_data=test_set,
                  validation_steps=nb_test_images//batch_size,
                  callbacks=callbacks)

history=model.fit(training_set,
                  steps_per_epoch=nb_train_images//batch_size,
                  epochs=40,
                  validation_data=test_set,
                  validation_steps=nb_test_images//batch_size,
                  callbacks=callbacks)

I have 6 different types of set to classify. where am i going wrong? i have add the input shape in above where i mentioned 1001006 ,can someone help to understand this issue.



Solution 1:[1]

This was happening to me too. The following is my code. The way that I fixed it was that instead of having some different input shape, I just made the input shape the training data's image shape.


train = image_gen.flow_from_directory(
        train_path,
        target_size=(500, 500
        ),
        color_mode='grayscale',
        class_mode='binary',
        batch_size=16
        )
#and then later, when I build the model
model.add(Conv2D(filters[0], (5, 5),  padding='same',kernel_regularizer=12(0.001), activation='relu', input_shape=train.image_shape))
#the important part is the input_shape=train.image_shape

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mr Developer