Hood Ubuntu TensorFlow Object Detection 2 20211231
From wikidb
Contents
- 1 Core References
- 2 Python Code
- 2.1 Working Directory
- 2.2 Extracting the Extracting Python Source in Notebook
- 2.3 Execute Object Detection Code from Linux Command Line
- 2.4 Execute Object Detection Code from Python Command Line
- 2.5 Partitioned the Extracted Code
- 2.6 Execute Patitioned Code on the Python Command Line
- 2.7 Images Do Not Display
- 2.8 Code Analysis
- 3 Notes and Logs
Core References
Misc References
- Tensorflow Object Detection Zoo
- from TensorFlow Lite Android, iOS and Raspberry Pi
- Object Detection Lite
Python Code
Working Directory
cd ~/Tensorflow_examples/TFObjectDectionTutorial/TFDemo/pythonCode
Extracting the Extracting Python Source in Notebook
Follow these instructions
Extract code from
Press the "Download notebook" button
$ mv ~/Downloads/object_detection.ipynb . $ jupyter nbconvert --to script l03c01 object_detection.ipynb [NbConvertApp] WARNING | pattern 'l03c01' matched no files [NbConvertApp] Converting notebook object_detection.ipynb to script [NbConvertApp] Writing 9679 bytes to object_detection.py $ ls object_detection.ipynb object_detection.py $ cp object_detection.py object_detection.py.org
Execute Object Detection Code from Linux Command Line
$ python3 object_detection.py 2021-12-31 19:47:34.801812: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /home/eepp/image_ws/install/stereo_image_proc/lib:/home/eepp/image_ws/install/realsense_ros/lib:/home/eepp/image_ws/install/realsense_msgs/lib:/home/eepp/image_ws/install/realsense_camera_msgs/lib:/home/eepp/image_ws/install/image_view/lib:/home/eepp/image_ws/install/image_rotate/lib:/home/eepp/image_ws/install/image_proc/lib:/home/eepp/image_ws/install/depth_image_proc/lib:/home/eepp/turtlebot3_ws/install/turtlebot3_msgs/lib:/usr/lib/x86_64-linux-gnu/gazebo-11/plugins:/opt/ros/foxy/opt/yaml_cpp_vendor/lib:/opt/ros/foxy/opt/rviz_ogre_vendor/lib:/opt/ros/foxy/lib/x86_64-linux-gnu:/opt/ros/foxy/lib 2021-12-31 19:47:34.801879: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine. 2.5.0 2021-12-31 19:47:38.330149: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 FMA To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags. 2021-12-31 19:47:38.333302: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcuda.so.1'; dlerror: libcuda.so.1: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /home/eepp/image_ws/install/stereo_image_proc/lib:/home/eepp/image_ws/install/realsense_ros/lib:/home/eepp/image_ws/install/realsense_msgs/lib:/home/eepp/image_ws/install/realsense_camera_msgs/lib:/home/eepp/image_ws/install/image_view/lib:/home/eepp/image_ws/install/image_rotate/lib:/home/eepp/image_ws/install/image_proc/lib:/home/eepp/image_ws/install/depth_image_proc/lib:/home/eepp/turtlebot3_ws/install/turtlebot3_msgs/lib:/usr/lib/x86_64-linux-gnu/gazebo-11/plugins:/opt/ros/foxy/opt/yaml_cpp_vendor/lib:/opt/ros/foxy/opt/rviz_ogre_vendor/lib:/opt/ros/foxy/lib/x86_64-linux-gnu:/opt/ros/foxy/lib 2021-12-31 19:47:38.333347: W tensorflow/stream_executor/cuda/cuda_driver.cc:326] failed call to cuInit: UNKNOWN ERROR (303) 2021-12-31 19:47:38.333388: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:156] kernel driver does not appear to be running on this host (hood): /proc/driver/nvidia/version does not exist The following GPU devices are available: Image downloaded to /tmp/tmpenuxm37h.jpg. 2021-12-31 19:48:37.105879: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:176] None of the MLIR Optimization Passes are enabled (registered 2) 2021-12-31 19:48:37.126158: I tensorflow/core/platform/profile_utils/cpu_utils.cc:114] CPU Frequency: 1895470000 Hz Found 100 objects. Inference time: 52.270376682281494 Image downloaded to /tmp/tmpakhks2xn.jpg. Found 100 objects. Inference time: 17.627694845199585 Inference time: 18.38519525527954 Image downloaded to /tmp/tmpwsuhq0q0.jpg. Found 100 objects. Inference time: 17.668944120407104 Inference time: 18.37464714050293 Image downloaded to /tmp/tmpe70ovps5.jpg. Found 100 objects. Inference time: 17.748656272888184 Inference time: 18.863006114959717
Execute Object Detection Code from Python Command Line
$ python3 Python 3.8.10 (default, Nov 26 2021, 20:14:08) [GCC 9.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> exec(open('objection_detection.py').read()) Traceback (most recent call last): File "<stdin>", line 1, in <module> FileNotFoundError: [Errno 2] No such file or directory: 'objection_detection.py' >>> exec(open('object_detection.py').read()) 2022-01-11 13:14:11.280428: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /home/eepp/image_ws/install/stereo_image_proc/lib:/home/eepp/image_ws/install/realsense_ros/lib:/home/eepp/image_ws/install/realsense_msgs/lib:/home/eepp/image_ws/install/realsense_camera_msgs/lib:/home/eepp/image_ws/install/image_view/lib:/home/eepp/image_ws/install/image_rotate/lib:/home/eepp/image_ws/install/image_proc/lib:/home/eepp/image_ws/install/depth_image_proc/lib:/home/eepp/turtlebot3_ws/install/turtlebot3_msgs/lib:/usr/lib/x86_64-linux-gnu/gazebo-11/plugins:/opt/ros/foxy/opt/yaml_cpp_vendor/lib:/opt/ros/foxy/opt/rviz_ogre_vendor/lib:/opt/ros/foxy/lib/x86_64-linux-gnu:/opt/ros/foxy/lib 2022-01-11 13:14:11.280464: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine. 2.5.0 2022-01-11 13:14:12.909603: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 FMA To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags. 2022-01-11 13:14:12.910054: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcuda.so.1'; dlerror: libcuda.so.1: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /home/eepp/image_ws/install/stereo_image_proc/lib:/home/eepp/image_ws/install/realsense_ros/lib:/home/eepp/image_ws/install/realsense_msgs/lib:/home/eepp/image_ws/install/realsense_camera_msgs/lib:/home/eepp/image_ws/install/image_view/lib:/home/eepp/image_ws/install/image_rotate/lib:/home/eepp/image_ws/install/image_proc/lib:/home/eepp/image_ws/install/depth_image_proc/lib:/home/eepp/turtlebot3_ws/install/turtlebot3_msgs/lib:/usr/lib/x86_64-linux-gnu/gazebo-11/plugins:/opt/ros/foxy/opt/yaml_cpp_vendor/lib:/opt/ros/foxy/opt/rviz_ogre_vendor/lib:/opt/ros/foxy/lib/x86_64-linux-gnu:/opt/ros/foxy/lib 2022-01-11 13:14:12.910086: W tensorflow/stream_executor/cuda/cuda_driver.cc:326] failed call to cuInit: UNKNOWN ERROR (303) 2022-01-11 13:14:12.910107: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:156] kernel driver does not appear to be running on this host (hood): /proc/driver/nvidia/version does not exist The following GPU devices are available: Image downloaded to /tmp/tmpefp0xgee.jpg. INFO:tensorflow:Saver not created because there are no variables in the graph to restore INFO:tensorflow:Saver not created because there are no variables in the graph to restore 2022-01-11 13:14:37.480667: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:176] None of the MLIR Optimization Passes are enabled (registered 2) 2022-01-11 13:14:37.498270: I tensorflow/core/platform/profile_utils/cpu_utils.cc:114] CPU Frequency: 1895510000 Hz Found 100 objects. Inference time: 48.349021196365356 Image downloaded to /tmp/tmpj1x3tlkr.jpg. Found 100 objects. Inference time: 17.584803819656372 Inference time: 18.309814453125 Image downloaded to /tmp/tmp1kzncm4b.jpg. Found 100 objects. Inference time: 17.601308822631836 Inference time: 18.30541157722473 Image downloaded to /tmp/tmpdxd63l04.jpg. Found 100 objects. Inference time: 18.599908113479614 Inference time: 19.57200837135315 >>> plt.show()
The lt.show() opens 5 Matplotlib image windows. Don't understand why I had to execute this at the end. This code appeared in the display_image function found in objection_detection.py.
Partitioned the Extracted Code
Composite code
object_detector.py
Partitioned code to make it easier to modify, test and debug.
Execute Patitioned Code on the Python Command Line
$ python3 Python 3.8.10 (default, Nov 26 2021, 20:14:08) [GCC 9.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> exec(open('TFODImports.py').read()) 2022-01-01 16:46:31.984249: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /home/eepp/image_ws/install/stereo_image_proc/lib:/home/eepp/image_ws/install/realsense_ros/lib:/home/eepp/image_ws/install/realsense_msgs/lib:/home/eepp/image_ws/install/realsense_camera_msgs/lib:/home/eepp/image_ws/install/image_view/lib:/home/eepp/image_ws/install/image_rotate/lib:/home/eepp/image_ws/install/image_proc/lib:/home/eepp/image_ws/install/depth_image_proc/lib:/home/eepp/turtlebot3_ws/install/turtlebot3_msgs/lib:/usr/lib/x86_64-linux-gnu/gazebo-11/plugins:/opt/ros/foxy/opt/yaml_cpp_vendor/lib:/opt/ros/foxy/opt/rviz_ogre_vendor/lib:/opt/ros/foxy/lib/x86_64-linux-gnu:/opt/ros/foxy/lib 2022-01-01 16:46:31.984285: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine. >>> exec(open('TFODSettings.py').read()) TensorFlow Version 2.5.0 The following GPU devices are available: >>> exec(open('TFODHelpers.py').read()) >>> exec(open('TFODApply.py').read()) Image downloaded to /tmp/tmpxplhbky2.jpg. INFO:tensorflow:Saver not created because there are no variables in the graph to restore INFO:tensorflow:Saver not created because there are no variables in the graph to restore Found 100 objects. Inference time: 49.61235237121582
Did the following to display the images
>>> plt.show()
Images Do Not Display
- Stack Overflow: Image Show Wont Display in Picture
- Note: imagemagick was already install
- Note: eog was already add to the DisplayViewer
- Stuck
Code Analysis
- TBD: Figure out how the following from the Apply section works.
- TBD: Hook this up to a video stream.
module_handle = "https://tfhub.dev/google/faster_rcnn/openimages_v4/inception_resnet_v2/1" #@param ["https://tfhub.dev/google/openimages_v4/ssd/mobilenet_v2/1", "https://tfhub.dev/google/faster_rcnn/openimages_v4/inception_resnet_v2/1"] detector = hub.load(module_handle).signatures['default']