'UnimplementedError: Fused conv implementation does not support grouped convolutions for now

I am trying to build a CNN model to recognise human sketch using the TU-Berlin dataset. I downloaded the png zip file, imported the data to Google Colab and then split the data into train-test folders. Here is the model:

model = tf.keras.models.Sequential([
    tf.keras.layers.Conv2D(filters = 64, kernel_size = (5,5),padding = 'Same', 
                 activation ='relu', input_shape = target_dims),
    tf.keras.layers.Conv2D(filters = 64, kernel_size = (5,5),padding = 'Same', 
                 activation ='relu'),
    tf.keras.layers.MaxPool2D(pool_size=(2,2)),
    tf.keras.layers.Dropout(0.25),

    tf.keras.layers.Conv2D(filters = 128, kernel_size = (3,3),padding = 'Same', 
                 activation ='relu'),
    tf.keras.layers.Conv2D(filters = 128, kernel_size = (3,3),padding = 'Same', 
                 activation ='relu'),
    tf.keras.layers.MaxPool2D(pool_size=(2,2), strides=(2,2)),
    tf.keras.layers.Dropout(0.25),

    tf.keras.layers.Conv2D(256, kernel_size=4, strides=1, activation='relu', padding='same'),
    tf.keras.layers.Conv2D(256, kernel_size=4, strides=2, activation='relu', padding='same'),
    tf.keras.layers.Dropout(0.25),

    tf.keras.layers.Flatten(),
    tf.keras.layers.Dense(512, activation = "relu"),
    tf.keras.layers.Dropout(0.5),
    tf.keras.layers.Dense(n_classes, activation= "softmax")
])

model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=["accuracy"])

model.fit_generator(train_generator, epochs=10, validation_data=val_generator)

And I am getting the following error:

UnimplementedError:  Fused conv implementation does not support grouped convolutions for now.
     [[node sequential/conv2d/Relu (defined at <ipython-input-9-36d4624b896d>:1) ]] [Op:__inference_train_function_1358]

Function call stack:
train_function

I would be grateful to any kind of help that will solve this issue. Thank you.

(PS - I am running Tensorflow 2.2.0 and no GPU)



Solution 1:[1]

I had this same error using the facial expression recognition dataset, here's how i solved this same error.

From what i understand the dataset is gray color, when you use ImageDataGenerator of tensorflow and flow_from_directory to generate the train and validation set,

you need to specify the color_mode as grayscale or rgb based on the dataset/images, here it will be 'grayscale',

in the model the first layer Conv2D the input_shape should be

input_shape = (height, width, 1), 1 because its grayscale.

Solution 2:[2]

I had a similar error, the problem was with the number of channels for my image and the number of channels I specified in the model. So check the number of dimension of your image and check the value specified in the input shape ensure they are the same

Solution 3:[3]

Just mention the color_mode="grayscale" in flow from directory and check your model input (height,width,1).

Solution 4:[4]

Just as @grande_cifer said, the issue pops up from an incompatibility of number of image channel specified and correct number of channels of real images.

If you are not sure of the exact number of channel, I advice you specify 1 in your parameter target_dims, and forcefully convert all images when loading them to your net as grayscale, using the parameter color_mode = "grayscale" when loading the images to your net.

For more info, check keras online doc.

Solution 5:[5]

You will find this error in 2 cases:

  1. when the number of channels for your image and the number of channels you specified in the model are not same . Here the solution is to make them equal.

  2. When you use group param of Conv2D from tensorflow.keras . Here they have not implemented it with the use of group param , which is Depthwise Convolution in real (use tf.keras.layers.DepthwiseConv2D). For me the work around was pip install tf-nightly==2.10.0.dev20220406 as this package also have some unimplemented keras APIs...as this was not mentioned anywhere when I encountered this error

I hope this is useful

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 Martin Brisiak
Solution 2 grande_cifer
Solution 3 hrokr
Solution 4 Mentor Romarick Yatagha
Solution 5