Tensorrt: kernel weights has count 589824 but 147456 was expected

Created on 20 Mar 2020  路  7Comments  路  Source: NVIDIA/TensorRT

Here is my error message:
[TensorRT] ERROR: build_feature_pyramid/build_P4/avoid_aliasing/Conv2D: kernel weights has count 589824 but 147456 was expected
[TensorRT] ERROR: build_feature_pyramid/build_P4/avoid_aliasing/Conv2D: count of 589824 weights in kernel, but kernel dimensions (3,3) with 64 input channels, 256 output channels and 1 groups were specified. Expected Weights count is 64 * 3*3 * 256 / 1 = 147456
[TensorRT] ERROR: UffParser: Parser error: build_feature_pyramid/build_P4/avoid_aliasing/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
Traceback (most recent call last):
File "uff_psenet.py", line 99, in
with build_engine(model_path) as engine:
AttributeError: __enter__

here is the net definition:
nodes {
id: "build_feature_pyramid/build_P4/avoid_aliasing/Conv2D"
inputs: "build_feature_pyramid/add"
inputs: "build_feature_pyramid/build_P4/avoid_aliasing/weights"
operation: "Conv"
fields {
key: "dilation"
value {
i_list {
val: 1
val: 1
}
}
}
fields {
key: "implicit_padding"
value {
s: "same"
}
}
fields {
key: "inputs_orders"
value {
ref: "orders_N+C_+CK"
}
}
fields {
key: "strides"
value {
i_list {
val: 1
val: 1
}
}
}
}
nodes {
id: "build_feature_pyramid/build_P4/avoid_aliasing/weights"
operation: "Const"
fields {
key: "dtype"
value {
dtype: DT_FLOAT32
}
}
fields {
key: "shape"
value {
i_list {
val: 3
val: 3
val: 256
val: 256
}
}
}

and here is my code:
p, c = feature_pyramid['P' + str(layer + 1)], C['C' + str(layer)]
up_sample_shape = tf.shape(c)
up_sample = tf.image.resize_nearest_neighbor(p, [up_sample_shape[1], up_sample_shape[2]],
name='layer_%d/ResizeNearestNeighbor' % layer)
c = slim.conv2d(c, num_outputs=256, kernel_size=[1, 1], stride=1,
scope='build_P%d/reduce_dimension' % layer)
p = up_sample + c
p = slim.conv2d(p, 256, kernel_size=[3, 3], stride=1,
padding='SAME', scope='build_P%d/avoid_aliasing' % layer)

in this code, for example. shape of p is [None, 32, 32, 256], and shape of c is [None, 64, 64, 256], and this resize layer was original from TensorRT/plugin/resizeNearestPlugin, i konw the data format in TensorRT was NCHW, it seems this conv layer can't transpose the NHWC format to NCHW, so what should i do?

TensorFlow bug good-reference

All 7 comments

Hi,
Did u solve this bug? cuz I am facing the same issue.

@derekwong66 i found in the code, i use a tf.shape() func to get the shape of a tensor, but when i change tf.shape() to np.shape(), it solves

Thanks for finding the solution @HandsLing , can I close this issue?

@derekwong66 i found in the code, i use a tf.shape() func to get the shape of a tensor, but when i change tf.shape() to np.shape(), it solves

I solved it by reshaping its size before passing it into conv

@derekwong66 i found in the code, i use a tf.shape() func to get the shape of a tensor, but when i change tf.shape() to np.shape(), it solves

I solved it by reshaping its size before passing it into conv

Hi, I found that I met the same issue, could you explained a little bit more about your solution "I solved it by reshaping its size before passing it into conv"?
I change all my tf.shape and Tensor.get_shape() with np.shape, but the error occurs still. following are the Conv2D code:

@staticmethod
def conv2d(inputdata, out_channel, kernel_size, padding='SAME',
    stride=1, w_init=None, b_init=None,
    split=1, use_bias=True, data_format='NHWC', name=None):

    with tf.variable_scope(name):
        in_shape = np.shape(inputdata).as_list()
        channel_axis = 3 if data_format == 'NHWC' else 1
        in_channel = in_shape[channel_axis]
        assert in_channel is not None, "[Conv2D] Input cannot have unknown channel!"
        assert in_channel % split == 0
        assert out_channel % split == 0

        padding = padding.upper()

        if isinstance(kernel_size, list):
            filter_shape = [kernel_size[0], kernel_size[1]] + [in_channel / split, out_channel]
        else:
            filter_shape = [kernel_size, kernel_size] + [in_channel / split, out_channel]

        if isinstance(stride, list):
            strides = [1, stride[0], stride[1], 1] if data_format == 'NHWC' \
                else [1, 1, stride[0], stride[1]]
        else:
            strides = [1, stride, stride, 1] if data_format == 'NHWC' \
                else [1, 1, stride, stride]

        if w_init is None:
            w_init = tf.contrib.layers.variance_scaling_initializer()
        if b_init is None:
            b_init = tf.constant_initializer()

        w = tf.get_variable('W', filter_shape, initializer=w_init)
        b = None

        if use_bias:
            b = tf.get_variable('b', [out_channel], initializer=b_init)

        if split == 1:
            conv = tf.nn.conv2d(inputdata, w, strides, padding, data_format=data_format)
        else:
            inputs = tf.split(inputdata, split, channel_axis)
            kernels = tf.split(w, split, 3)
            outputs = [tf.nn.conv2d(i, k, strides, padding, data_format=data_format)
                       for i, k in zip(inputs, kernels)]
            conv = tf.concat(outputs, channel_axis)

        ret = tf.identity(tf.nn.bias_add(conv, b, data_format=data_format)
                          if use_bias else conv, name=name)

    return ret

little bit more ab
Assuming the shape before passing it into conv is (16, 32, 256). add one more tf.reshape to its shape like tf.reshape(feature, (16, 32, 256)) then it will be solved

@derekwong66 > > little bit more ab

Assuming the shape before passing it into conv is (16, 32, 256). add one more tf.reshape to its shape like tf.reshape(feature, (16, 32, 256)) then it will be solved

Perfectly solved! Thanks so much!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MachineJeff picture MachineJeff  路  5Comments

float123 picture float123  路  6Comments

WangXuanBT picture WangXuanBT  路  3Comments

SvanKeulen picture SvanKeulen  路  5Comments

peijason picture peijason  路  3Comments