kernel weights has count X but Y was expected

This issue is directly linked to this topic: https://devtalk.nvidia.com/default/topic/1036940/jetson-tx2/uff-parser-errors but as I have not gotten a response for over a month, I am hoping that providing a simpler model that demonstrates the issue could speed up the process. Here is my network model:

def WeightsVariable(shape):
    return tf.Variable(tf.truncated_normal(shape, stddev=0.1, name='weights'))

def BiasVariable(shape):
    return tf.Variable(tf.constant(0.1, shape=shape, name='biases'))

def Conv2d(x, W, b, strides=1):
    # Conv2D wrapper, with bias and relu activation
    filter_size = W.get_shape().as_list()
    pad_size = filter_size[0]//2
    pad_mat = np.array([[0,0],[pad_size,pad_size],[pad_size,pad_size],[0,0]])
    x = tf.pad(x, pad_mat)
    x = tf.nn.conv2d(x, W, strides=[1, strides, strides, 1], padding='VALID')
    x = tf.nn.bias_add(x, b)
    return tf.nn.relu(x)

def network(images):
    # Convolution 1
    img_concat = tf.concat([images,images], -1)
    input_tensor = img_concat
    with tf.name_scope('conv1'):
        weights = WeightsVariable([5,5,2,32])
        biases = BiasVariable([32])
        conv1 = tf.nn.relu(Conv2d(input_tensor, weights, biases))
        flat1 = tf.reshape(conv1, [-1, 28 * 28 * 32])
    # Fully Connected 2
    with tf.name_scope('fc2'):
        weights = WeightsVariable([28 * 28 * 32, 10])
        biases = BiasVariable([10])
        fc2 = tf.nn.relu(tf.matmul(flat1, weights) + biases)
    return fc2

The network run fine in tensorflow, but I am getting TensorRT errors from engine building. Here is the full output info log (using TensorRT 5):

[TensorRT] INFO: UFFParser: parsing Placeholder
[TensorRT] INFO: UFFParser: parsing concat
[TensorRT] ERROR: Parameter check failed at: ../builder/Layers.h::setAxis::334, condition: axis>=0
[TensorRT] INFO: UFFParser: parsing conv1/Variable
[TensorRT] INFO: UFFParser: parsing conv1/Conv2D
[TensorRT] INFO: UFFParser: parsing conv1/Variable_1
[TensorRT] INFO: UFFParser: parsing conv1/BiasAdd
[TensorRT] ERROR: conv1/Conv2D: kernel weights has count 1600 but 22400 was expected
[TensorRT] ERROR: UFFParser: Parser error: conv1/BiasAdd: The input to the Scale Layer is required to have a minimum of 3 dimensions.

How can I modify the network to have it run on TensorRT?

22400/1600 = 14. This expects a single image, maybe you are passing a mini_batch. Just do summary_writer = tf.summary.FileWriter(“logs_viz”,graph=tf.get_default_graph()) within sess.run and visualize the model in tensorboard to do a sanity check on shapes.

Also because it’s expecting a dims=3, make sure the image you feed is of shape [1, 28, 28, 1]

the same probleme with me:

https://devtalk.nvidia.com/default/topic/1044160/tensorrt/kernel-weights-has-count-5514240-but-96499200-was-expected/

I think the reason may be in TensorRT’s reshape op

Hi ,

I receive a similar error message while UFF parsing

[I] …/data/mnist/tf_model.uff
[E] [TRT] Conv1/convolution: kernel weights has count 864 but 138240 was expected
[E] [TRT] Conv1/convolution: count of 864 weights in kernel, but kernel dimensions (3, 3) with 480 input channels, 32 output channels and 1 groups were specified.
[E] [TRT] UffParser: Parser error: bn_Conv1/batchnorm_1/mul_1: The input to the Scale Layer is required to have a minimum of 3 dimensions.
[E] Failure while parsing UFF file
[E] Model load failed
&&&& FAILED TensorRT.sample_uff_mnist # ./sample_uff_mnist

I’ve generated a frozen graph (.pb) using a script (convert_keras_pb.py) below in the link.The .pb file is then converted into a .uff file using the convert_to_uff script of the internal tensorrt uff package.

The .uff file is then used against the sampleUffMnist sample that comes bundled with the Tensorrt package and on UFF parsing the above error is received.

Can someone please look into the issue as I’ve been struggling with this since a month.

Tensorrt# - 5.1.6 + CUDA 10.0
Tensorflow# 1.14

Thanks,
Chirag

https://drive.google.com/open?id=1nM9SjRTWFDUhKtRL7N-AsYnW2IYyJ2JR

Got similar error with this tiny model:

def create_model(input_size=512):                                                                                                                                                                                          

    inputs = tf.keras.layers.Input((input_size, input_size,1))
    c1 = tf.keras.layers.Activation("relu")(inputs)
    c2 = tf.keras.layers.Activation("relu")(c1)
    c2 = tf.keras.layers.concatenate([c2, c1], axis=3)
    outputs = tf.keras.layers.Conv2D(1, (1, 1), activation='sigmoid', padding='same')(c2)
    model = tf.keras.Model(inputs=[inputs], outputs=[outputs])
    model.compile(optimizer='adam', loss=tf.keras.losses.MeanSquaredError(), metrics=['accuracy'])
    return model

The error message is:

[TensorRT] ERROR: conv2d/Conv2D: kernel weights has count 2 but 1024 was expected
[TensorRT] ERROR: conv2d/Conv2D: count of 2 weights in kernel, but kernel dimensions (1, 1) with 1024 input channels, 1 output channels and 1 groups were specified.
[TensorRT] ERROR: UffParser: Parser error: conv2d/BiasAdd: The input to the Scale Layer is required to have a minimum of 3 dimensions.
[TensorRT] ERROR: Network must have at least one output