UFF model fails when there is more than 1 convolution2d layer

hi,

this is my keras model:

inputs = Input(shape=(1,256,1024))
    x = Conv2D(1, (15,15), padding='same', strides=(1,1), name = 'conv1', data_format="channels_first")(inputs)
    x = Activation('relu', name='actv1')(x)
    x = MaxPooling2D((2, 2), strides=(2, 2), name = 'maxpool1')(x)
    x = Conv2D(32, (3,3), padding='same', strides=(1,1), name = 'conv2', data_format="channels_first")(x)
    x = Activation('relu', name='actv2')(x)
    x = MaxPooling2D((2, 2), strides=(2, 2), name = 'maxpool2')(x)
    x = Conv2D(64, (3,3), padding='same', strides=(1,1), name = 'conv3', data_format="channels_first")(x)
    x = MaxPooling2D((2, 2), strides=(2, 2), name = 'maxpool3')(x)
    x = Conv2D(128, (3,3), padding='same', strides=(1,1), name = 'conv4', data_format="channels_first")(x)
    x = MaxPooling2D((2, 2), strides=(2, 2), name = 'maxpool4')(x)
    x = Flatten()(x)
    x = Dense(1000, activation='relu', name = 'dense1')(x)
    x = Dense(500, activation='relu',name = 'dense2')(x)
    x = Dense(2, activation='softmax',name = 'dense3')(x)

My generated UFF model gave a result that was very off from the correct tensorflow results. However, when i removed the blocks of convolution layers:

inputs = Input(shape=(1,256,1024))
    x = Conv2D(1, (15,15), padding='same', strides=(1,1), name = 'conv1', data_format="channels_first")(inputs)
    x = Activation('relu', name='actv1')(x)
    x = MaxPooling2D((2, 2), strides=(2, 2), name = 'maxpool1')(x)
    x = Flatten()(x)
    x = Dense(1000, activation='relu', name = 'dense1')(x)
    x = Dense(500, activation='relu',name = 'dense2')(x)
    x = Dense(2, activation='softmax',name = 'dense3')(x)

The generated UFF model was able to produce consistent results with the tensorflow model.

Is there a bug in TensorRT that is causing some form of wrong optimisation for the convolution block layers? Could someone advise? thanks so much.

Hi,
I’ve fixed the problem by changing the keras flatten layer to tf.reshape. However, I’m not sure why this solved the problem, can someone advise as to what is happening? Thanks!

Hi,

I have a similar probelm as jay. See [url]https://devtalk.nvidia.com/default/topic/1038304/tensorrt/tensorrt-gives-different-output-to-original-tensorflow-model/?offset=3#5276125[/url]

I can just say it isn’t connected to the number of convolution layers, it depends on the filter parameters in the convolution layer. With “filters”=1 (as in your first layer) it works fine. But when filters > 1 it gives a different output.

Can you please provide the code to replace the flatten layer thanks!

Best Johannes