概要
JetPack 4.6にはOpenCV 4.1.1が含まれていますが,CUDAサポートがOFFになっています. ここでは比較的手軽にCUDAサポートがONのOpenCVの環境を準備する方法として,NVIDIA L4T MLのDockerイメージを使用する方法をメモしておきます.
Jetson | Jetson Nano |
---|---|
JetPack | 4.6 |
NVIDIA L4T ML | l4t-ml:r32.6.1-py3 |
NIVIDIA NGCとNVIDIA L4T ML
NVIDIA NGCでは,さまざまな用途のための,ディープラーニング,機械学習およびHPC向けのDockerイメージが配布されています. Jetson向けのDockerイメージは下記のリンクから一覧表示できます.
NVIDA NGCで配布されているDockerイメージの1つにNVIDIA L4T MLがあります.これはディープラーニング,機械学習やデータサイエンスの各種フレームワークをPython 3.6上で使用するための環境です. 下記ページの「Package Versions」を確認するとl4t-ml:r32.6.1-py3のリストにはOpenCV 4.5.0 (with CUDA)と記載されており,CUDAサポートがONになっていることがわかります.
Dockerコンテナを起動する
ワーキングディレクトリと起動スクリプトの準備
お好みの場所にワーキングディレクトリを作成し,その中にDockerコンテナの起動スクリプト,run.shを作成します. ここでは既存ディレクトリの/dataの配下にl4t-mlというディレクトリを作成しています.
1 2 3 | $ cd /data $ mkdir l4t-ml $ cd l4t-ml/ |
お好みのテキストエディタでrun.shを作成し,下記リンクのrun.shの内容をコピー・アンド・ペーストしてください. なお,使用するDockerイメージのタグはJetPack 4.6に対応するr32.6.1-py3になっています.違うタグを指定したい場合は,NVIDIA L4T MLのページを参照して任意のタグに置き換えてください.
1 | $ vi run.sh |
Dockerコンテナの起動
少なくともこれ以降の作業は,Jetsonにキーボード,マウスおよびディスプレイを接続して直接GUIログインしていることを前提に説明します. run.shに実行権限を付与し,実行してください.初回はDockerイメージのPullがあり,Dockerコンテナの起動に時間がかかります.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | $ chmod a+x ./run.sh $ ./run.sh access control disabled, clients can connect from any host [sudo] password for username: Unable to find image 'nvcr.io/nvidia/l4t-ml:r32.6.1-py3' locally r32.6.1-py3: Pulling from nvidia/l4t-ml e47a8a86d66c: Pulling fs layer bdce3430dad6: Pulling fs layer c26a6b81c746: Pulling fs layer a70635e646de: Waiting 24cbe60e3161: Waiting c7f64cc97a39: Waiting 8777adb92eda: Waiting 542a24b3572f: Waiting 3d5ade2b8849: Waiting 3e865584f789: Waiting 4811af6cacf1: Waiting db645757aac7: Pull complete 0105dc23dc93: Pull complete c8aff3baf097: Pull complete 5f50b3e38480: Pull complete b5418d85b074: Pull complete d09ffaf0f11a: Pull complete f1cf5625978f: Pull complete 514fd4c3f8c5: Pull complete 0988d0ccf8a6: Pull complete ffce97733d6c: Pull complete 80d5eedfe895: Pull complete d19792019860: Pull complete 3ee7b31a8890: Pull complete 8aca18eb38a5: Pull complete 153000266b1a: Pull complete 23bf7741f5d8: Pull complete d03fa2111a1c: Pull complete 095c23b57578: Pull complete 2de9347ccaf2: Pull complete 0f26c4b0a765: Pull complete ee3bc588c8ee: Pull complete aa25eb953d98: Pull complete 97fd80a69cc6: Pull complete Digest: sha256:1f4ef02343223cab6bbe5bf85d5575364b7ee0ee23d72c2e3b89416ca3806f7e Status: Downloaded newer image for nvcr.io/nvidia/l4t-ml:r32.6.1-py3 allow 10 sec for JupyterLab to start @ http://192.168.110.36:8888 (password nvidia) JupterLab logging location: /var/log/jupyter.log (inside the container) root@jetson-nano:/# |
Dockerコンテナが起動し,Dockerコンテナの端末が表示されました.
dockerコマンドを実行するとエラーになる場合は,下記が解決の参考になるかもしれません.
Python 3でOpenCVライブラリの情報を確認する
下記の投稿で紹介した方法で,Dockerコンテナ上のOpenCVライブラリの情報を確認してみました. CUDAサポートがONになっています.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | root@jetson-nano:/# python3 Python 3.6.9 (default, Jan 26 2021, 15:33:00) [GCC 8.4.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import cv2 >>> print(cv2.__version__) 4.5.0 >>> print(cv2.getBuildInformation()) General configuration for OpenCV 4.5.0 ===================================== Version control: 4.5.0 Extra modules: Location (extra): /opt/opencv_contrib/modules Version control (extra): 4.5.0 Platform: Timestamp: 2021-07-19T21:05:54Z Host: Linux 4.9.201-tegra aarch64 CMake: 3.10.2 CMake generator: Unix Makefiles CMake build tool: /usr/bin/make Configuration: RELEASE CPU/HW features: Baseline: NEON FP16 required: NEON disabled: VFPV3 C/C++: Built as dynamic libs?: YES C++ standard: 11 C++ Compiler: /usr/bin/c++ (ver 7.5.0) C++ flags (Release): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG C++ flags (Debug): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D_DEBUG C Compiler: /usr/bin/cc C flags (Release): -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -fvisibility=hidden -O3 -DNDEBUG -DNDEBUG C flags (Debug): -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -fvisibility=hidden -g -O0 -DDEBUG -D_DEBUG Linker flags (Release): -Wl,--gc-sections -Wl,--as-needed Linker flags (Debug): -Wl,--gc-sections -Wl,--as-needed ccache: NO Precompiled headers: NO Extra dependencies: m pthread cudart_static dl rt nppc nppial nppicc nppicom nppidei nppif nppig nppim nppist nppisu nppitc npps cublas cudnn cufft -L/usr/local/cuda/lib64 -L/usr/lib/aarch64-linux-gnu 3rdparty dependencies: OpenCV modules: To be built: alphamat aruco bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev datasets dnn dnn_objdetect dnn_superres dpm face features2d flann freetype fuzzy gapi hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot python3 quality rapid reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking video videoio videostab xfeatures2d ximgproc xobjdetect xphoto Disabled: world Disabled by dependency: - Unavailable: cnn_3dobj cvv hdf java js julia matlab ovis python2 sfm ts viz Applications: apps Documentation: NO Non-free algorithms: YES GUI: GTK+: YES (ver 3.22.30) GThread : YES (ver 2.56.4) GtkGlExt: NO OpenGL support: NO VTK support: NO Media I/O: ZLib: /usr/lib/aarch64-linux-gnu/libz.so (ver 1.2.11) JPEG: /usr/lib/aarch64-linux-gnu/libjpeg.so (ver 80) WEBP: build (ver encoder: 0x020f) PNG: /usr/lib/aarch64-linux-gnu/libpng.so (ver 1.6.34) TIFF: build (ver 42 - 4.0.10) JPEG 2000: build (ver 2.3.1) OpenEXR: build (ver 2.3.0) HDR: YES SUNRASTER: YES PXM: YES PFM: YES Video I/O: DC1394: YES (2.2.5) FFMPEG: YES avcodec: YES (57.107.100) avformat: YES (57.83.100) avutil: YES (55.78.100) swscale: YES (4.8.100) avresample: YES (3.7.0) GStreamer: YES (1.14.5) v4l/v4l2: YES (linux/videodev2.h) Parallel framework: TBB (ver 2017.0 interface 9107) Trace: YES (with Intel ITT) Other third-party libraries: Lapack: YES (/usr/lib/aarch64-linux-gnu/liblapack.so /usr/lib/aarch64-linux-gnu/libcblas.so /usr/lib/aarch64-linux-gnu/libatlas.so) Eigen: YES (ver 3.3.4) Custom HAL: YES (carotene (ver 0.0.1)) Protobuf: build (3.5.1) NVIDIA CUDA: YES (ver 10.2, CUFFT CUBLAS FAST_MATH) NVIDIA GPU arch: 53 62 72 NVIDIA PTX archs: cuDNN: YES (ver 8.0.0) Python 3: Interpreter: /usr/bin/python3 (ver 3.6.9) Libraries: /usr/lib/aarch64-linux-gnu/libpython3.6m.so (ver 3.6.9) numpy: /usr/lib/python3/dist-packages/numpy/core/include (ver 1.13.3) install path: lib/python3.6/dist-packages/cv2/python-3.6 Python (for build): /usr/bin/python2.7 Java: ant: NO JNI: NO Java wrappers: NO Java tests: NO Install to: /usr/local ----------------------------------------------------------------- >>> exit() |
0 件のコメント:
コメントを投稿