titu1994 / keras-coordconv

Keras implementation of CoordConv for all Convolution layers
MIT License
148 stars 33 forks source link

Getting error with rank attribute #20

Open Anurag-Saksena opened 4 months ago

Anurag-Saksena commented 4 months ago

First of all, thank you so much for this code implementation but it's not working for me.

I added the layer in the code as follows:

def build(width, height, depth, classes): inputShape = (height, width, depth) input_layer = Input(shape=inputShape)

    coord1 = CoordinateChannel2D()(input_layer)
    conv1 = Conv2D(32, (3, 3), activation='relu')(coord1)
    pool1 = MaxPooling2D(2, 2)(conv1)
    drop1 = Dropout(0.2)(pool1)
    # coord2 = CoordinateChannel2D()(drop1)
    conv2 = Conv2D(64, (3, 3), activation='relu')(drop1)
    pool2 = MaxPooling2D(2, 2)(conv2)
    drop2 = Dropout(0.2)(pool2)
    flat = Flatten()(drop2)
    dense1 = Dense(128, activation='relu')(flat)
    output_layer = Dense(classes, activation='softmax')(dense1)
    model = Model(inputs=input_layer, outputs=output_layer)
    return model

and I am getting this stack trace as an error.

File "D:\Pycharm Projects\ThesisFinal\Game Theoretical Adversarial Deep Learning\rolling_window_6_categories_8_limit_90_dropout_coord_inp2.py", line 22, in build coord1 = CoordinateChannel2D()(input_layer) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Pycharm Projects\ThesisFinal.venv\Lib\site-packages\tensorflow\python\keras\engine\base_layer.py", line 1026, in call input_spec.assert_input_compatibility(self.input_spec, inputs, self.name) File "D:\Pycharm Projects\ThesisFinal.venv\Lib\site-packages\tensorflow\python\keras\engine\input_spec.py", line 226, in assert_input_compatibility ndim = x.shape.rank ^^^^^^^^^^^^ AttributeError: 'tuple' object has no attribute 'rank'

What am I doing wrong ?