ãã®è¨äºã¯ã岩æçç«å¤§å¦ Advent Calendar 2023ãã®25æ¥ç®(å¾åºã)ã§ãã
qiita.com
ãã¨ã®ã¯ãã¾ã
ç§ã¯GitHubãè¦ã¦ãã¦ããããã®ãªãã¸ããªåãããããªãã¨æã£ãæãã¾ãã¯ãã®ãªãã¸ããªãåãç°å¢ã®Docker imageæ§ç¯ããå§ã¾ãã¾ãã
åããç°å¢ã人ã«å
±æããããããªãã¹ããã¼ã¹ç°å¢ã¯ãããã«ä¿ã¦ãã®ã§ã
ãã¦ããã¤ãéãç°å¢ãæ§ç¯ãããã¨ãã¾ããããªãã¸ããªã«ã¯ä»¥ä¸ã®ãããªè¦ä»¶ãæ示ããã¦ãã¾ããã
github.com
- Ubuntu 16.04
- Python 2.7
- OpenCV 2.4.13 compiled with GPU support
- boost_python 1.65.0
- TensorFlow
- Sonnet
å
¨ä½çã«è¦æ±ç°å¢ãå¤ãã§ããã
ã¨ããã®ãæçµã³ãããã2019å¹´ãªã®ã§ç´å¾ã§ãã
ç°å¢æ§ç¯ã®å°é£ã
ãã®ã¾ã¾ã¢ãã³ãªç°å¢ã§åãã®ã
è¦æ±ç°å¢ã¯å¤ãã§ãããå¥ã«Ubuntu 20.04 + Python3.x + OpenCV 4.x ...ã§ãã®ã¾ã¾åãã¦ããããªãä½ãæ°ã«ãããã¨ã¯ããã¾ããã
ããä»åã®å ´å以ä¸ã®åé¡ãçºçãã¾ãã
- è¨æ³ãéãé¨åããããããPython3ç³»ã«åãããã«Pythonã¹ã¯ãªãããæ¸ãæããå¿
è¦ãã
- OpenCVã®APIäºæããªããæ¸ãæããå¿
è¦ãªé¨åå¤ã
ãã
æ£ç´ãä»åã®ã³ã¼ãè¦æ¨¡ãããã§ããã°å
¨é¨æ¸ãæãã¦ã大ãããã¨ãªãã¨ã¯æãã®ã§ããã
ãã£ã¨å¤§è¦æ¨¡ãªã³ã¼ãã§åãåé¡ã«é¥ã£ã¦ããå ´åã«ã¯ã¢ããã¤ã¼ã¼ã·ã§ã³(使ãæ¹ãã£ã¦ã?)ã«ã¯ä»¥ä¸ã®ãªã¹ã¯ãä¼´ãã¾ãã
- éå»ã«èªåãä½ã£ãã·ã¹ãã ã§ãªãéããã¢ããã¤ã¼ã¼ã·ã§ã³ããå¾ã«èµ·ãã£ããã°ã¯å
ã
ã®ã½ããã¦ã§ã¢ã®ãã°ãèªåãä¿®æ£ãå ããããã§åºããã°ãåãåããã®ãé£ãã
- é¢æ°ã®ããã©ã«ãã¢ã«ã´ãªãºã ãå¤ãã£ã¦ãããããã¨è¨ç®çµæãåããã¤ããï¼ãªãã·ã§ã³ã§éå»ã®ã¢ã«ã´ãªãºã ãé¸æã§ãããã¨ãã»ã¨ãã©ã ãï¼
- ã·ã¹ãã ã®è¦æ¨¡ã«ãããåç´ã«æ¸ãæããæéãChatGPTã¨ãã«ã¢ãã³ã«ãã¦ã£ã¦è¨ãã°ãããªãã«ã±ã±ã£ã¨ã§ãããããããªããããã§ãæéã ããè¨ç®çµæãæ³å®éããããªãã¨æ´ã«é ãæ±ãã
ã¨ãããã¨ã§ãå
ã
ã®ç°å¢ãåç¾ãã¦åããããªããªãã¹ããã®æ¹ããããã¨ã¯æãã¾ãã
ä»åã®éå£
ä»åé¢åãªã®ã¯ä»¥ä¸ã®3ã¤ã®æ¡ä»¶ã§ãã
- Python 2.7
- OpenCV 2.4.13 compiled with GPU support
- TensorFlow
ã¾ããããã¯ä»åã®ä¾ã«éã£ããã¨ã§ã¯ãªãã®ã§ããããã·ã³ã«ã¤ãã¦ããç©çGPUããOpenCVããTensorFlowãå
¨å¡ãç´å¾ããCUDAç°å¢ãæ´ããã®ã¯é常ã«é¢åã§ãã
ã¾ããPython 2.7èªä½ã¯ç¨æããã®ã¯ãªãã¦ãã¨ç¡ãã®ã§ãããPython 2.7ã¨é£æºã§ããTensorFlowããã®ä»ããã±ã¼ã¸ã®ãã¼ã¸ã§ã³ãç¨æããå¿
è¦ãããã¾ãã
ä»åéçºãã·ã³ã«ã¯ãNVIDIA GeForce RTX 3070ããã¤ãã¦ããã®ã§ãã®ã¢ã¼ããã¯ãã£å¯¾å¿ãæèããå¿
è¦ãããã¾ãã
TensorFlow(GPUç)ã®åé¡
TensorFlowã§å¦ç¿ãæ¨è«ãåããªãGPUã¢ã¯ã»ã©ã¬ã¼ã·ã§ã³ã使ãããªããã²ä½¿ãããã¨ããã§ãã
CPUçã§ãã£ã¦ãã¦ã¯ã¨ã¦ããããªããã©é
ããã¦éçºå¹çãæªããã¨ãããã¾ããããã
Python2.7ã¨é£æºã§ããtensorflow-gpuã¯version 1.15.x
ãæå¾ã§ãã
version 1.15.x
ã«å¯¾å¿ããCUDAç°å¢ã¯CUDA:10.0 cuDNN:7
ã«ãªãã¾ãã
ããããããNVIDIA GeForce RTX 3070ãã¯æä½ã§ãCUDA:11.1
ãå¿
è¦ã§ãã
ãã£ã¦ãPython2.7ã®ä½¿ç¨ãç¶ããå ´åãã®æç¹ã§tensorflowã®GPUã¢ã¯ã»ã©ã¬ã¼ã·ã§ã³ã¯è«¦ãããããªããªãè©°ã¿ã¾ãã
å¤ãOpenCV(with CUDA)ã®åé¡
ã§ã¯OpenCVã¯ã©ãã§ãããï¼
OpenCV with CUDA ããã«ãããã«ã¯ä¸ä¾ã§ã¯ããã¾ãã以ä¸ã®ãããªãã«ããªãã·ã§ã³ãå¿
è¦ã§ãã
RUN cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D WITH_CUDA=ON \
-D WITH_CUDNN=ON \
-D OPENCV_DNN_CUDA=ON \
-D CUDA_ARCH_BIN='8.6' \
-D CUDA_ARCH_PTX='8.6' \
-D ENABLE_FAST_MATH=1 \
-D CUDA_FAST_MATH=1 \
-D WITH_CUBLAS=1 \
-D WITH_TBB=ON \
..
éè¦ãªã®ã¯CUDA_ARCH_BIN
ã¨CUDA_ARCH_PTX
ã®ï¼ã¤ã§ãããã«æ¸ãæ°åã¯PCã«æè¼ããã¦ããGPUã«ãã£ã¦æé©ãªæ°åãç°ãªãã¾ãã
CUDAã®ãã¼ã¸ã§ã³ã«ãã£ã¦å¤ããæ°åã§ã¯ãªãã®ã§æ³¨æãå¿
è¦ã§ãã
以ä¸ã®ãªã¹ãããèªåã®GPUã®ååãæ¢ãããCompute Capabilityãã«æ¸ãã¦ããæ°åãåç
§ãã¾ãã
CUDA GPUs - Compute Capability | NVIDIA Developer
ãã£ã¦ããNVIDIA GeForce RTX 3070ãã§ã¯ã8.6ãã¨ãªãã¾ãã
ãã¡ãããCUDA_ARCH_BIN='8.6'
ã§ãã«ãããã«ã¯CUDA:11.1
以éãå¿
è¦ã¨ãªãã¾ãã(åè)ã
ãããªãã¨ä»åè¦æ±ããã¦ããOpenCV 2.4.13
ãµãã¼ãç¯å²å¤ã¨ãªãã¾ãã
ãã®ãããªãCompute Capabilityãã¨OpenCVã®ãã¼ã¸ã§ã³ã®é©å¿é¢ä¿ã¯ä»¥ä¸ã®è¨äºã«ããã¾ã¨ãããã¦ãã¾ãã
qiita.com
ããããããããã©ããã§ãGPUã¢ã¯ã»ã©ã¬ã¼ã·ã§ã³ãªãã®OpenCV 2.4.13
ã¤ã³ã¹ãã¼ã«ãããã§ã¨ããããåãã¦ãã¨æã£ã¦ãã¾ãã¾ããã
ããã§é¢åãªã®ã¯OpenCVã§GPUã¢ã¯ã»ã©ã¬ã¼ã·ã§ã³ã使ã£ãã³ã¼ãããã®è±å´æ¹æ³ã§ãã
TensorFlowãªã©ã§ã¯ã»ã¼ã³ã¼ãã®æ¸ãæããªãã«CPU,GPUã©ã¡ãã®ãªã½ã¼ã¹ã§è¨ç®ãããã¯æ°è»½ã«åãæ¿ããããã®ã§ããã
OpenCVã¯GPUã¢ã¯ã»ã©ã¬ã¼ã·ã§ã³ã使ç¨ãã/ããªãã¯ã³ã¼ãã®è¨è¿°ã«ä¾åããã®ã§ãGPUã¢ã¯ã»ã©ã¬ã¼ã·ã§ã³ããè±å´ããã«ã¯è©²å½ç¯å²ããã¹ã¦CPU対å¿ã«æ¸ãç´ãå¿
è¦ãããã¾ããï¼åç´ãªæ¸ãæãã§ã¯ããã¾ããï¼
æåããCPUã§ãGPUã§ãåãããã«ç°å¢ã«ãã£ã¦åå²ããããã«åªããæ¸ããã¦ããã³ã¼ãã ã¨ãããããã§ãããããã§ãªãå ´å&ã³ã¼ãã®è¦æ¨¡ã大ããå ´åå°ã
æéã§ãã
ãã¨ãã©ãã
ããã¾ã§ã®å¶ç´ãæ´çããã¨
è¦ç´ |
ä¸è¨ |
è¦æ±ãããCUDAç¯å² |
ç©çGPU |
ä¸ä»£ã«ãã£ã¦CUDAã®Minå¤ã¯æ±ºã¾ã |
11.1 < X |
TensorFlow |
Python2.7ã§ä½¿ããtensorflow-gpuã®æ大ã¯1.15.x |
X < 10.0 |
OpenCV |
2ç³»ã¯å¤ãããGPUããè±å´ããã®ãããé¢å |
3.0 < 9.2 |
ããããããã¹ããã¨ã¯ä»¥ä¸ã®ããã«æ´çããã¾ãã
- ãã¼ã¹ã¯ CUDA 11.1
- Pythonã3ç³»ã«ãã¦ãtensorflow-gpuã使ããããã«ãã
- OpenCVã®ãã¼ã¸ã§ã³ãä¸ããããã«ã³ã¼ããæ¸ãæãã
2ã¯ãªãã·ã§ãã«ã§å¥ã«ãããªãã¦ãCPUè¨ç®ã§åãã«ã¯åãã®ã§1ã¨3ããããã¨ã«ãã¾ãã
æçµçãªè§£æ±º
ã¾ãDockerã®ãã¼ã¹imageãUbuntu16.04 + CUDA11.1 + cuDNN8ã®ãã®ã«ãã¾ãã
DockerHubã®nvidia/cuda
ããã¯å¤ããã®ã¯æ¶ããã¦ããã®ã§ããã
nvidia/cuda
ã«ãªãå¤ããã®ãnvcr.io/nvidia/cuda
ããã¨ã£ã¦ãããã¨ãã§ãã¾ãã
catalog.ngc.nvidia.com
OpenCVã¯ãªãã¨ãªã4.5.2ã«ãã¦ã¿ã¾ããã
2ç³»ãã4ç³»ã«ããããããå種APIã®ä»æ§ãå¤ãããã®ã¾ã¾ã§ã¯åãã¾ããã
åãããã«"é å¼µã£ã¦"cppãpythonãæ¸ãæãã¦ã¨ã©ã¼ãæ¶ãã¦ããã¾ãã
ããã§ãã£ã¨åãã¾ãã
ã¾ã¨ã
ç¹ã«ãªãã®åèã«ãªãããããã¾ããããç§ãæ®æ®µæ´æ°ã®å¤ããªãã¸ããªãåããã¨ãã«èãã¦ãããã¨ãæ¸ãåºãã¦ã¿ã¾ããã
çµæçã«ãPython3ã«ãããã¨ããOpenCVã®ãã¼ã¸ã§ã³ãä¸ãããã¨ãããã©ãããããã«æ¸ãæããããç¡ããã¨ãããã¾ããããªãã¹ããã®ã¾ã¾åããããã«ã©ãæ
å ±ãåç
§ãã¹ããã¯ã¾ã¨ã¾ã£ãã¨æãã¾ãã
ãããèªãã ã¿ãªããã"åããªãð¡"ã¨å¤§éã«issueãç«ã¦ããã¦ããªãã¸ããªãåãç°å¢ãæä¾ãã¦ã¿ãã¨ãæããã人é¡ãããããç¥ãã¾ããã
ãã¾ã
ãã®1
ãªããå種ç°å¢ã®tensorflow-gpuã®whlãªã³ã¯ã ãã大éã«ã¾ã¨ãã¦ããµã¤ããããã¾ãã
Links for tensorflow-gpu
ãã®2
TensorFlowã¯å¤ããã¼ã¸ã§ã³ã ã¨pipã®ããã±ã¼ã¸åã«ãã£ã¦ã
- tensorflowã»ã»ã»CPUç
- tensorflow-gpuã»ã»ã»GPUç
ã¨ãããã¦ãã¾ãããæè¿ã®ãã¼ã¸ã§ã³ã¯tensorflow
ãå
¥ããã ãã§ã©ã£ã¡ã«ã対å¿ãã¾ãã
ãã®3
OpenCVをCUDA付きでビルドする際にサポートされる範囲 #OpenCV - Qiita
ãã®è¨äºã ã¨OpenCV 2.4.13.7ã®CUDAã®å¯¾å¿ã¯æ大9.2ã§ããã
CUDA 9ç³» + OpenCV 2.4.13ã§ãã«ããããã¨ããã¨ãªã³ã¯ã¨ã©ã¼ã§ç´ ç´ã«ã¯ãã«ãã§ããªãã®ã§æ³¨æã§ããcmakeãæ¸ãæããå¿
è¦ãããã¾ãã
ãããã¸ãã§è°è«ããã¦ã¾ãã
stackoverflow.com