Building a docker image, encountered [AttributeError: 'tensorrt.tensorrt.IResizeLayer' object has no attribute 'align_corners']

Jetpack 4.6
Pytorch 1.9.0
Torchvision 0.10.0

Hello,

I’m building a docker image with the instructions here: NVIDIA-AI-IOT/scene-text-recognition
At the very last step of the process, the error below occurs.

Step 21/21 : RUN python3 scene-text-recognition/video_capture.py
 ---> Running in 78c445500d6d
[ WARN:0@10.014] global /io/opencv/modules/videoio/src/cap_v4l.cpp (902) open VIDEOIO(V4L2:/dev/video0): can't open camera by index
Downloading detection model, please wait. This may take several minutes depending upon your network connection.
Error opening video file
Progress: ----------------------------------------------- 100.0% Complete
Downloading recognition model, please wait. This may take several minutes depending upon your network connection.
Progress: ----------------------------------------------- 100.0% Complete
Warning: Encountered known unsupported method torch.zeros
Warning: Encountered known unsupported method torch.Tensor.__hash__
Warning: Encountered known unsupported method torch.Tensor.__hash__
Warning: Encountered known unsupported method torch.Tensor.__hash__
Warning: Encountered known unsupported method torch.Tensor.__hash__
Warning: Encountered known unsupported method torch.Tensor.__hash__
Warning: Encountered known unsupported method torch.Tensor.__hash__
					.
					.
					.
Warning: Encountered known unsupported method torch.Tensor.__hash__
Warning: Encountered known unsupported method torch.Tensor.get_device
Warning: Encountered known unsupported method torch.Tensor.is_complex

/usr/local/lib/python3.6/dist-packages/torch/nn/functional.py:718: UserWarning: Named tensors and all their associated APIs are an experimental feature and subject to change. Please do not use them for anything important until they are released as stable. (Triggered internally at  /media/nvidia/NVME/pytorch/pytorch-v1.9.0/c10/core/TensorImpl.h:1156.)
  return torch.max_pool2d(input, kernel_size, stride, padding, dilation, ceil_mode)
Traceback (most recent call last):
  File "scene-text-recognition/video_capture.py", line 59, in <module>
    reader = easyocr.Reader(['en'], use_trt=True)
  File "/usr/local/lib/python3.6/dist-packages/easyocr-1.4-py3.6.egg/easyocr/easyocr.py", line 276, in __init__
    self.detector = get_detector(detector_path, self.device, quantize, cudnn_benchmark=cudnn_benchmark, use_trt=use_trt)
  File "/usr/local/lib/python3.6/dist-packages/easyocr-1.4-py3.6.egg/easyocr/detection.py", line 165, in get_detector
    net_trt = torch2trt(net,[sample_input])
  File "/usr/local/lib/python3.6/dist-packages/torch2trt-0.2.0-py3.6.egg/torch2trt/torch2trt.py", line 601, in torch2trt
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 1051, in _call_impl
    return forward_call(*input, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/parallel/data_parallel.py", line 166, in forward
    return self.module(*inputs[0], **kwargs[0])
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 1051, in _call_impl
    return forward_call(*input, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/easyocr-1.4-py3.6.egg/easyocr/craft.py", line 66, in forward
    y = F.interpolate(y, size=sources[2].size()[2:], mode='bilinear', align_corners=False)
  File "/usr/local/lib/python3.6/dist-packages/torch2trt-0.2.0-py3.6.egg/torch2trt/torch2trt.py", line 302, in wrapper
  File "/usr/local/lib/python3.6/dist-packages/torch2trt-0.2.0-py3.6.egg/torch2trt/converters/interpolate.py", line 89, in convert_interpolate_trt7
AttributeError: 'tensorrt.tensorrt.IResizeLayer' object has no attribute 'align_corners'
The command '/bin/sh -c python3 scene-text-recognition/video_capture.py' returned a non-zero code: 1

I assume this is to do with torch2trt. How do I approach this?

Thank you in advance.

Hi,

Based on the below error, it seems that the container doesn’t have the access to the camera.

.../videoio/src/cap_v4l.cpp (902) open VIDEOIO(V4L2:/dev/video0): can't open camera by index

Have you mounted it like sudo docker run ... --device /dev/video0 ...?

Thanks.

No I have not. My understanding from the instruction is that, I first finish building the image then run the said image with a camera. The command given is below:

1. docker build -t scene-text-recognition .


2. xhost +
    sudo docker run -it --rm -v ~/workdir:/workdir/ --runtime nvidia --network host -e DISPLAY=$DISPLAY --device /dev/video0: dev/video0 scene-text-recognition

Since my attempt to build the image failed, when I check docker image list there is no image with the tag ‘scene-text-recognition’. Should I skip the video_capture.py part from Dockerfile then build the image? So that I can mount the camera with the image afterwards.

Cheers.

A bit of update:

I’m using a USB Logitech C310 webcam, forgot to mention it.

I’ve rectified the camera access issue by changing

cap = cv2.VideoCapture(0)

to

cap = cv2.VideoCapture('v4l2src device=/dev/video0 ! video/x-raw, width=640, height=480, framerate=(fraction)30/1 ! videoconvert ! video/x-raw, format=(string)BGR ! appsink', cv2.CAP_GSTREAMER)

in video_capture.py

Still, however, the same issue occurred.

Step 21/21 : RUN python3 scene-text-recognition/video_capture.py
 ---> Running in d7f258674671
Downloading detection model, please wait. This may take several minutes depending upon your network connection.
Error opening video file
Progress: ----------------------------------------------- 100.0% Complete
Downloading recognition model, please wait. This may take several minutes depending upon your network connection.
Progress: ----------------------------------------------- 100.0% Complete
Warning: Encountered known unsupported method torch.zeros
Warning: Encountered known unsupported method torch.Tensor.__hash__
Warning: Encountered known unsupported method torch.Tensor.__hash__
Warning: Encountered known unsupported method torch.Tensor.__hash__
Warning: Encountered known unsupported method torch.Tensor.__hash__
Warning: Encountered known unsupported method torch.Tensor.__hash__
Warning: Encountered known unsupported method torch.Tensor.__hash__
					.
					.
					.
Warning: Encountered known unsupported method torch.Tensor.__hash__
Warning: Encountered known unsupported method torch.Tensor.get_device
Warning: Encountered known unsupported method torch.Tensor.is_complex
/usr/local/lib/python3.6/dist-packages/torch/nn/functional.py:718: UserWarning: Named tensors and all their associated APIs are an experimental feature and subject to change. Please do not use them for anything important until they are released as stable. (Triggered internally at  /media/nvidia/NVME/pytorch/pytorch-v1.9.0/c10/core/TensorImpl.h:1156.)
  return torch.max_pool2d(input, kernel_size, stride, padding, dilation, ceil_mode)
Traceback (most recent call last):
  File "scene-text-recognition/video_capture.py", line 64, in <module>
    reader = easyocr.Reader(['en'], use_trt=True)
  File "/usr/local/lib/python3.6/dist-packages/easyocr-1.4-py3.6.egg/easyocr/easyocr.py", line 276, in __init__
    self.detector = get_detector(detector_path, self.device, quantize, cudnn_benchmark=cudnn_benchmark, use_trt=use_trt)
  File "/usr/local/lib/python3.6/dist-packages/easyocr-1.4-py3.6.egg/easyocr/detection.py", line 165, in get_detector
    net_trt = torch2trt(net,[sample_input])
  File "/usr/local/lib/python3.6/dist-packages/torch2trt-0.2.0-py3.6.egg/torch2trt/torch2trt.py", line 601, in torch2trt
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 1051, in _call_impl
    return forward_call(*input, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/parallel/data_parallel.py", line 166, in forward
    return self.module(*inputs[0], **kwargs[0])
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 1051, in _call_impl
    return forward_call(*input, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/easyocr-1.4-py3.6.egg/easyocr/craft.py", line 66, in forward
    y = F.interpolate(y, size=sources[2].size()[2:], mode='bilinear', align_corners=False)
  File "/usr/local/lib/python3.6/dist-packages/torch2trt-0.2.0-py3.6.egg/torch2trt/torch2trt.py", line 302, in wrapper
  File "/usr/local/lib/python3.6/dist-packages/torch2trt-0.2.0-py3.6.egg/torch2trt/converters/interpolate.py", line 89, in convert_interpolate_trt7
AttributeError: 'tensorrt.tensorrt.IResizeLayer' object has no attribute 'align_corners'
The command '/bin/sh -c python3 scene-text-recognition/video_capture.py' returned a non-zero code: 1

The Dockerfile refers to a fork of torch2trt for a temporary fix:

#for torch2trt
RUN git clone --recursive -b jax-jp4.6.1-trt7 https://github.com/akamboj2/torch2trt.git torch2trt && \
    cd torch2trt && \
    python3 setup.py install && \
    cd ../ && \
    rm -rf torch2trt

Is there any chance it could be some sort of trt version conflict? I’d really appreciate any inputs on this.

I’m closing this topic due to there is no update from you for a period, assuming this issue was resolved.
If still need the support, please open a new topic. Thanks

Hi,

It’s possible.
Do you get the error fixed after using the jax-jp4.6.1-trt7 branch?

Thanks.