nvinfer1::DimsCHW parserhelper::getCHW(const nvinfer1::Dims&): Assertion `d.nbDims >= 3' failed

I write a demo about INT8 with caffe. But some errors here:
python: ./parserHelper.h:99: nvinfer1::DimsCHW parserhelper::getCHW(const nvinfer1::Dims&): Assertion `d.nbDims >= 3’ failed.

How can I do to solve it ? Thank you!

The calib return data size is (nums, channels 3, image_h, image_w).

The error occur at line 11:

def build_int8_engine(deploy_file, model_file, calib, batch_size=32):
with trt.Builder(TRT_LOGGER) as builder, builder.create_network() as network, trt.CaffeParser() as parser:
# We set the builder batch size to be the same as the calibrator’s, as we use the same batches
# during inference. Note that this is not required in general, and inference batch size is
# independent of calibration batch size.
builder.max_batch_size = batch_size
builder.max_workspace_size = GiB(1)
builder.int8_mode = True
builder.int8_calibrator = calib
# Parse Caffe model
model_tensors = parser.parse(deploy=deploy_file, model=model_file, network=network, dtype=ModelData.DTYPE)
network.mark_output(model_tensors.find(ModelData.OUTPUT_NAME))
# Build engine and do int8 calibration.
return builder.build_cuda_engine(network)

caffemodel.prototxt: (layer 1)
name: “InceptionResnetV1”
input: “blob1”
input_dim: 1
input_dim: 3
input_dim: 512
input_dim: 512
layer {
name: “conv1”
type: “Convolution”
bottom: “blob1”
top: “conv_blob1”
convolution_param {
num_output: 32
bias_term: false
pad: 0
kernel_size: 3
group: 1
stride: 2
weight_filler {
type: “xavier”
}
dilation: 1
}
}

Hi @Supine,
Request you to share the verbose logs and complete model file, so that I can assist you better .
Thanks!

Can I have your e-mail address? Then I can send files to you. Thanks.

Hi @Supine,
You can DM the files.
Thanks!

I have upload the files. It’s just a demo. Run it by ‘python VGGFace2_INT8.py’.
I want to qualitize VGGFace2 caffe model with TensorRT for NVDLA. The calibarator file (vggface2_calibration.cache) is all what I need.
What’s more, the images folder only has 3 pics, it’s a try. I don’t think this occur the problem. But I’m not sure.
I run it with cuda10.2, cudnn7, TensorRT7, python3.5 and Ubuntu16.04.
And I get error:

python: ./parserHelper.h:99: nvinfer1::DimsCHW parserhelper::getCHW(const nvinfer1::Dims&): Assertion `d.nbDims >= 3’ failed.

when run to

model_tensors = parser.parse(deploy=deploy_file, model=model_file, network=network, dtype=ModelData.DTYPE)

Thank you very much.

[Uploading: VGGFace quanlify.zip…](There are the files)

Uploading: VGGFace quanlify.zip…

I‘m not sure whether the files upload successfully. If not, please tell me. By the way, the caffe model is transformed from a pytorch model. In order to suit tensorRT, I delete the para ‘ceil_model = false’ in every pooling layer. And I modify the max_pool3 layer’s stride from 3 to 4, for keeping the compatibility of feature map in ‘cat17’ layer.

Hi @Supine,
I have not received your model.
Maybe you can try uploading it over drive and share the link .
Also request you to provide the below set of information
o Linux distro and version
o GPU type
o Nvidia driver version
o CUDA version
o CUDNN version
o Python version [if using python]
o Tensorflow and PyTorch version
o TensorRT version

Thanks!

Hi, I have upload files into Google drive and the link is https://drive.google.com/file/d/1VgJoSXNI4iIBw5F7o0a5aNOX4yvTIAWC/view?usp=sharing.
The additional info:

It’s just a demo. Run it by ‘python VGGFace2_INT8.py’.
I want to qualitize VGGFace2 caffe model with TensorRT for NVDLA. The calibarator file (vggface2_calibration.cache) is all what I need.
What’s more, the images folder only has 3 pics, it’s a try. I don’t think this occur the problem. But I’m not sure.
I run it with cuda10.2, cudnn7, TensorRT7, python3.5 and Ubuntu16.04.

The caffe model is transformed from a pytorch modelfacenet. In order to suit tensorRT, I delete the para ‘ceil_model = false’ in every pooling layer. And I modify the max_pool3 layer’s stride from 3 to 4, for keeping the compatibility of feature map in ‘cat17’ layer. It will not effect the params.

I have ran my code with ResNet-50, it worked. But not work on my model.
The error is python: ./parserHelper.h:99: nvinfer1::DimsCHW parserhelper::getCHW(const nvinfer1::Dims&): Assertion `d.nbDims >= 3’ failed.
I’m wondering why it is, thank you very much.

o Linux distro and version: Ubuntu 16.04
o GPU type: GTX Titan X
o Nvidia driver version: 450.57
o CUDA version: 10.2
o CUDNN version: 7
o Python version [if using python]: python 3.5
o Tensorflow and PyTorch version: Pytorch 1.6
o TensorRT version: 7.0.0.11

Hi! I had find why the error occurs.
In the process pytorch to caffe, the reshape/view operation is transformed.

layer {
name: “view1”
type: “Reshape”
bottom: “ave_pool_blob1”
top: “view_blob1”
reshape_param {
shape {
dim: 0
dim: -1
}
}
}
layer {
name: “fc1”
type: “InnerProduct”
bottom: “view_blob1”
top: “fc_blob1”
inner_product_param {
num_output: 512
bias_term: false
weight_filler {
type: “xavier”
}
}
}

The Reshape layer transform n×c×h×w into n×c, but it isn’t what InnerProduct layer what in caffe.
If I delete the Reshape layer, the other error occurs:

TypeError: mark_output(): incompatible function arguments. The following argument types are supported:
1. (self: tensorrt.tensorrt.INetworkDefinition, tensor: tensorrt.tensorrt.ITensor) -> None

Invoked with: <tensorrt.tensorrt.INetworkDefinition object at 0x7f410c1035a8>, None

I don’t know what it’s, can you help me? Thank you.

I have solved the question by modify the paras. It’s over.

1 Like