Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

AttributeError occured #5

Open
Hiroaki-K4 opened this issue Sep 2, 2020 · 21 comments
Open

AttributeError occured #5

Hiroaki-K4 opened this issue Sep 2, 2020 · 21 comments

Comments

@Hiroaki-K4
Copy link

Hi!
Thank you for your work.
I tried: roslaunch trt_yolo_ros demo.launch

Then such an error occurred. If you know a solution, please let me know.

... logging to /home/nvidia/.ros/log/7194ed44-ecee-11ea-b2e1-2a67aa1ada95/roslaunch-nvidia-17905.log
Checking log directory for disk usage. This may take a while.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://nvidia:34107/

SUMMARY
========

PARAMETERS
 * /rosdistro: melodic
 * /rosversion: 1.14.6
 * /trt_yolo_ros/config_path: /home/nvidia/catk...
 * /trt_yolo_ros/cuda_device: 0
 * /trt_yolo_ros/label_filename: coco_labels.txt
 * /trt_yolo_ros/nms_threshold: 0.3
 * /trt_yolo_ros/num_cam: 1
 * /trt_yolo_ros/obj_threshold: 0.7
 * /trt_yolo_ros/postprocessor_cfg: yolo_postprocess_...
 * /trt_yolo_ros/publish_image: True
 * /trt_yolo_ros/publish_rate: 10
 * /trt_yolo_ros/publisher/bounding_boxes/topic: /trt_yolo_ros/bou...
 * /trt_yolo_ros/publisher/image/topic: /trt_yolo_ros/bou...
 * /trt_yolo_ros/subscriber/image0/topic: /camera/color/ima...
 * /trt_yolo_ros/weights_path: /home/nvidia/catk...
 * /trt_yolo_ros/yolo_type: yolov3-416

NODES
  /
    trt_yolo_ros (trt_yolo_ros/node.py)

auto-starting new master
process[master]: started with pid [17916]
ROS_MASTER_URI=http://localhost:11311

setting /run_id to 7194ed44-ecee-11ea-b2e1-2a67aa1ada95
process[rosout-1]: started with pid [17927]
started core service [/rosout]
process[trt_yolo_ros-2]: started with pid [17934]
[INFO] [1599031947.810237]: [trt_yolo_ros] starting the node
Building new trt engine file
Traceback (most recent call last):
  File "/home/nvidia/catkin_ws/src/trt_yolo_ros/trt_yolo_ros/scripts/node.py", line 11, in <module>
    network = YOLORos()
  File "/home/nvidia/catkin_ws/src/trt_yolo_ros/trt_yolo_ros/src/trt_yolo_ros/trt_yolo_ros.py", line 27, in __init__
    show_image=self.publish_image,
  File "/home/nvidia/catkin_ws/src/trt_yolo_ros/trt_yolo/src/trt_yolo/detector.py", line 60, in __init__
    self.engine = self.get_engine(weights_path, config_path, yolo_type)
  File "/home/nvidia/catkin_ws/src/trt_yolo_ros/trt_yolo/src/trt_yolo/detector.py", line 109, in get_engine
    self.build_trt_from_onnx(weights_path, configs_path, yolo_type)
  File "/home/nvidia/catkin_ws/src/trt_yolo_ros/trt_yolo/src/trt_yolo/detector.py", line 125, in build_trt_from_onnx
    with trt.Builder(self.trt_logger) as builder:
AttributeError: __exit__
[trt_yolo_ros-2] process has died [pid 17934, exit code 1, cmd /home/nvidia/catkin_ws/src/trt_yolo_ros/trt_yolo_ros/scripts/node.py __name:=trt_yolo_ros __log:=/home/nvidia/.ros/log/7194ed44-ecee-11ea-b2e1-2a67aa1ada95/trt_yolo_ros-2.log].
log file: /home/nvidia/.ros/log/7194ed44-ecee-11ea-b2e1-2a67aa1ada95/trt_yolo_ros-2*.log

Thanks!

@kumuji
Copy link
Owner

kumuji commented Sep 2, 2020

Can you specify your environment parameters?
Python, tensorrt versions

@Hiroaki-K4
Copy link
Author

ok.
python 2.7
tensorrt 6.0.1

@kumuji
Copy link
Owner

kumuji commented Sep 2, 2020

ok.
python 2.7
tensorrt 6.0.1

Versions look fine, I have almost same.
It could be the problem that onnx engine was generated wrong. Can you try removing contents of weights folder in trt_yolo and rerun the node?

@Hiroaki-K4
Copy link
Author

I deleted the contents of the weights folder and ran it again, but got the same error.

@kumuji
Copy link
Owner

kumuji commented Sep 3, 2020

Hmm, it seems close to this issue.
Which python minor(2.7.17) version are you using? Could it be related to that?

@Hiroaki-K4
Copy link
Author

Hiroaki-K4 commented Sep 4, 2020

I solved it.
I changed
with trt.Builder(self.trt_logger) as builder:
to
builder = trt.Builder(self.trt_logger)
I also changed the with statement in several places.
But a new error occurred.

SUMMARY
========

PARAMETERS
 * /rosdistro: melodic
 * /rosversion: 1.14.6
 * /trt_yolo_ros/config_path: /home/nvidia/catk...
 * /trt_yolo_ros/cuda_device: 0
 * /trt_yolo_ros/label_filename: coco_labels.txt
 * /trt_yolo_ros/nms_threshold: 0.3
 * /trt_yolo_ros/num_cam: 1
 * /trt_yolo_ros/obj_threshold: 0.7
 * /trt_yolo_ros/postprocessor_cfg: yolo_postprocess_...
 * /trt_yolo_ros/publish_image: True
 * /trt_yolo_ros/publish_rate: 10
 * /trt_yolo_ros/publisher/bounding_boxes/topic: /trt_yolo_ros/bou...
 * /trt_yolo_ros/publisher/image/topic: /trt_yolo_ros/bou...
 * /trt_yolo_ros/subscriber/image0/topic: /camera/color/ima...
 * /trt_yolo_ros/weights_path: /home/nvidia/catk...
 * /trt_yolo_ros/yolo_type: yolov3-416

NODES
  /
    trt_yolo_ros (trt_yolo_ros/node.py)

auto-starting new master
process[master]: started with pid [27898]
ROS_MASTER_URI=http://localhost:11311

setting /run_id to 92fb3db4-ee77-11ea-a597-04ab18464945
WARNING: Package name "efficientNet_proc" does not follow the naming conventions. It should start with a lower case letter and only contain lower case letters, digits, underscores, and dashes.
WARNING: Package name "pyTorch_proc" does not follow the naming conventions. It should start with a lower case letter and only contain lower case letters, digits, underscores, and dashes.
process[rosout-1]: started with pid [27909]
started core service [/rosout]
process[trt_yolo_ros-2]: started with pid [27916]
[INFO] [1599200797.075055]: [trt_yolo_ros] starting the node
Reading engine from file /home/nvidia/catkin_ws/src/trt_yolo_ros/trt_yolo/weights/yolov3-416.trt
Traceback (most recent call last):
  File "/home/nvidia/catkin_ws/src/trt_yolo_ros/trt_yolo_ros/scripts/node.py", line 11, in <module>
    network = YOLORos()
  File "/home/nvidia/catkin_ws/src/trt_yolo_ros/trt_yolo_ros/src/trt_yolo_ros/trt_yolo_ros.py", line 27, in __init__
    show_image=self.publish_image,
  File "/home/nvidia/catkin_ws/src/trt_yolo_ros/trt_yolo/src/trt_yolo/detector.py", line 61, in __init__
    self.inputs, self.outputs, self.bindings, self.stream = self._allocate_buffers()
  File "/home/nvidia/catkin_ws/src/trt_yolo_ros/trt_yolo/src/trt_yolo/detector.py", line 181, in _allocate_buffers
    trt.volume(self.engine.get_binding_shape(binding))
AttributeError: module 'tensorrt' has no attribute 'volume'
[trt_yolo_ros-2] process has died [pid 27916, exit code 1, cmd /home/nvidia/catkin_ws/src/trt_yolo_ros/trt_yolo_ros/scripts/node.py __name:=trt_yolo_ros __log:=/home/nvidia/.ros/log/92fb3db4-ee77-11ea-a597-04ab18464945/trt_yolo_ros-2.log].
log file: /home/nvidia/.ros/log/92fb3db4-ee77-11ea-a597-04ab18464945/trt_yolo_ros-2*.log

Is the version of tensorrt not right?

@kumuji
Copy link
Owner

kumuji commented Sep 4, 2020

Is the version of tensorrt not right?

I use tensorrt 6.0.1.5 for cuda 10 with python 2.7.17, and works fine.
Looks like builder for some reason does not return the context.

@Hiroaki-K4
Copy link
Author

Hiroaki-K4 commented Sep 7, 2020

ok.
Is there a way to check if the builder is working properly?

@kumuji
Copy link
Owner

kumuji commented Sep 7, 2020

I think you can check examples in $TENSORRT_PATH/samples/python/yolov3_onnx, my repo is based on that example. Can you check if it works for you?

@Hiroaki-K4
Copy link
Author

ok. I did.
A permission denied error has occurred.

(tensorrt) nvidia@nvidia:/usr/src/tensorrt/samples/python/yolov3_onnx$ python onnx_to_tensorrt.py 
Downloading from https://github.com/pjreddie/darknet/raw/f86901f6177dfc6116360a13cc06ab680e0c86b0/data/dog.jpg, this may take a while...
Traceback (most recent call last):
  File "onnx_to_tensorrt.py", line 179, in <module>
    main()
  File "onnx_to_tensorrt.py", line 135, in main
    'https://github.com/pjreddie/darknet/raw/f86901f6177dfc6116360a13cc06ab680e0c86b0/data/dog.jpg', checksum_reference=None)
  File "/usr/src/tensorrt/samples/python/yolov3_onnx/yolov3_to_onnx.py", line 741, in download_file
    wget.download(link, local_path)
  File "/home/nvidia/virtualenv/tensorrt/local/lib/python2.7/site-packages/wget.py", line 506, in download
    (fd, tmpfile) = tempfile.mkstemp(".tmp", prefix=prefix, dir=".")
  File "/usr/lib/python2.7/tempfile.py", line 314, in mkstemp
    return _mkstemp_inner(dir, prefix, suffix, flags)
  File "/usr/lib/python2.7/tempfile.py", line 244, in _mkstemp_inner
    fd = _os.open(file, flags, 0600)
OSError: [Errno 13] Permission denied: './dog.jpgNnmJ7r.tmp'

@Hiroaki-K4
Copy link
Author

By the way, do you use virtualenv for your environment?

@kumuji
Copy link
Owner

kumuji commented Sep 9, 2020

I think you should change permissions for the folder you are working in.
I prefer using virtual environment.

@Hiroaki-K4
Copy link
Author

I already tried
chmod -R 777 trt_yolo_ros
But it doesn't success.

@kumuji
Copy link
Owner

kumuji commented Sep 14, 2020

I meant that for the /usr/src/tensorrt/samples/python/yolov3_onnx. Because if the example from nvidia wouldn't work for you, my code wouldn't work either. Can you check if examples work for you?

@Hiroaki-K4
Copy link
Author

Hiroaki-K4 commented Sep 14, 2020

ok.
onnx_to_tensorrt.py resulted in an error on virtualenv. However, python3 onnx_to_tensorrt.py ran successfully locally.

I've probably figured out why it didn't work.
I tried to run the following command to create a symbolic link.

ln -s /usr/local/lib/python2.7/dist-packages/tensorrt $VIRTUAL_ENV/lib/site-packages/

However, there was no folder called tensorrt in /usr/local/lib/python2.7/dist-packages. So instead I ran the following command:

ln -s /usr/local/lib/python3.6/dist-packages/tensorrt $VIRTUAL_ENV/lib/site-packages/

I think this has an effect, what do you think? Is there any way to solve it?
I have one more question to ask. I want to run yolov4 accelerated by tensorrt on ros. Is it possible to combine trt_yolo_ros and tkDNN?
https://github.com/ceccocats/tkDNN

@kumuji
Copy link
Owner

kumuji commented Sep 22, 2020

Hmm, what Jetpack version are you using? I will check, maybe they dropped support for tensorrt in later vereions. Were you able to run the code linking that library? Also, are you sure that your $VIRTUAL_ENV is defined correctly(just in case)? As the result you should be able to un python -m pip show tensorrt and see the package there.
About tkDNN - should be possible, but you will have to write wrapper for that, it is not very compatible with code i have.

@Hiroaki-K4
Copy link
Author

Jetpack version is 4.3. The command below could not be executed.

ln -s /usr/local/lib/python2.7/dist-packages/tensorrt $VIRTUAL_ENV/lib/site-packages/

When I run pip show tensorrt on vertualenv, the following message is displayed.

WARNING: Package(s) not found: tensorrt

@Hiroaki-K4
Copy link
Author

Hiroaki-K4 commented Sep 23, 2020

Is it easier to make the trt_yolo_ros code yolov4 compatible than to combine tkDNN and trt_yolo_ros?
Also, do I need to edit the source code if I want to run trt_yolo_ros on python3?

@kumuji
Copy link
Owner

kumuji commented Sep 23, 2020

Jetpack version is 4.3. The command below could not be executed.

ln -s /usr/local/lib/python2.7/dist-packages/tensorrt $VIRTUAL_ENV/lib/site-packages/

When I run pip show tensorrt on vertualenv, the following message is displayed.

WARNING: Package(s) not found: tensorrt

You are right. I checked on jetpack 4.4 there is no package tensorrt anymore. Let me check where it is gone =)
Because in previous versions it was installed on python2.7 by default

@kumuji
Copy link
Owner

kumuji commented Sep 23, 2020

Is it easier to make the trt_yolo_ros code yolov4 compatible than to combine tkDNN and trt_yolo_ros?
Also, do I need to edit the source code if I want to run trt_yolo_ros on python3?

It is fully written in cpp, and my code is only python, so not very easy.
No, should be fine

@Hiroaki-K4
Copy link
Author

Hiroaki-K4 commented Sep 23, 2020

ok!
Thank you for answering my question many times. Lastly, I would like to ask you one question. What would you do if you wanted to:
・ You want to run the faster yolov4 on ros
・Since there is already a source code for object detection that yolov3 moves on darknet_ros, You would like to implement it as close as possible.

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants