YOLOv3 on Jetson AGX Xavier ์ฑ๋ฅ ํ๊ฐ
18๋
4์์ ๊ณต๊ฐ๋ YOLOv3๋ฅผ ์ต์ embedded board์ธ Jetson agx xavier
์์ ๊ตฌ๋์์ผ์ FPS๋ฅผ ์ธก์ ํด ๋ณธ๋ค.
๊ทธ๋ฆฌ๊ณ tegra์ฝ์ด๊ฐ ์๋ Geforece 1080๊ณผ์ ์ฑ๋ฅ ๋น๊ต๋ ์ํํด ๋ณธ๋ค.
YOLOv3 ๊ด๋ จ ์ ๋ณด
SSD๊ฐ ์ฃผ๋ฅ๊ฐ๋๊ณ ์ฝ๊ฐ ๋น์ฃผ๋ฅ๊ฐ๋ deep learning๊ธฐ๋ฐ object detection ์๊ณ ๋ฆฌ์ฆ์ด๋ค. ํ์ง๋ง ๋ค๋ฅธ ํ๋ ์์ํฌ๋ฅผ ์ฐ์ง์๊ณ ๋
์์ ์ด๋ฉฐ ์์กด์ฑ์ด ๊ฑฐ์์๋ ๊น๋ํ ์ฝ๋์ด๋ฏ๋ก ํฅํ ๋ถ์ํ๊ธฐ ์ฉ์ดํ๋ฏ๋ก ์ด๊ฒ์ ์ฌ์ฉ ํ๋ค.
pretrained weights
๋ค์ ์๋์ ํ์ ๊ฐ๊ณ ๊ฐ๊ฐ์ Link์์ ๋ค์ด๋ก๋ ํ ์ ์๋ค.
NVIDIA Jetson Xavier์์ YOLOv3 ๋ค์ด ๋ฐ ์ปดํ์ผ
์์ค ๋ฐ ๋ชจ๋ธ ๋ค์ด
์ฐ์ , ์๋์ฃผ์์์ ์์ค์ฝ๋์ ๋ชจ๋ธ ์จ์ดํธ๋ฅผ ๋ค์ด๋ก๋ํ๋ค.
git clone https://github.com/pjreddie/darknet # ์ฝ๋ ๋ค์ด๋ก๋
cd darknet
wget https://pjreddie.com/media/files/yolov3.weights # weights ๋ค์ด๋ก๋
Makefile ์์
๊ทธ ๋ค์ Makefile
์ ์์ ํ๋ค. ์ด ๋ CUDA Compute Capability
๋ฅผ ๋ง์ถฐ์ ์ํ ํด์ผํ๋ค.
NVIDIA GPU: CUDA Compute Capability์ ์ดํด
CUDA๋ฅผ ํ์ฑํํด์ ์ปดํ์ผ ํ ๊ฒฝ์ฐ Compute Capability
์ ์ดํด๋ฅผ ํ์๋ก ํ๋ค.
ํ์ฉํ์ง ์๋ ์ํคํ
์ณ๋ผ๋ฉด ์๋์ ๊ฐ์ ์๋ฌ๋ฅผ ๋ฐ์ ์ํจ๋ค.
nvcc fatal: Unsupported gpu architecture 'compute_XX'
ํด๊ฒฐ๋ฐฉ๋ฒ์ nvcc
์ปดํ์ผ์ ์ํ ํ ๋ FLAG
๋ฅผ ๋ฃ์ผ๋ฉด ๋๋ค.
-gencode arch=compute_XX, code=[sm_XX, compute_XX]
์ด๋ค.
์ํ๋ ์ฅ์น์ ๋ง์ถฐ์ ์ ํํ ์ฝ๋๋ฅผ NVIDIA CUDA-GPUs์ฐพ์์ ๋ฃ์ผ๋ฉด ๋๋ค. GeForece-1080
์ ๊ฒฝ์ฐ 6.1
์ด๋ฏ๋ก-gencode arch=compute_61, code=[sm_61, compute_61]
์ผ๋ก
์ฝ์
ํด์ ๋ฃ์ผ๋ฉด ๋๋ค.
์ฌ์ฉํ ๋ณด๋๋ tegra ๊ฒ์ด์ธ๋ฐ Jetson Xavier๋ ์์ง ๊ฒ์์ด ์ ๋๋ค.
ํฌ๋ผ์์ ์ฐพ์๋ณธ ๊ฒฐ๊ณผ ์ฝ๋๋ -gencode arch=compute_72,code=sm_72
์ด๋ค.
์ถ๊ฐ๋ก, ์ด๋ค ๋จธ์ ์์ ์ ํํ ๋์ง ๋ชจ๋ฅธ๋ค๋ฉด ์ฌ๋ฌ๊ฐ๋ฅผ ์ง์ํ๋๋ก ์ค์ ํ์ฌ ์ปดํ์ผ ํ ์๋ ์๋ค.
์๋์ ๊ฐ์ ํํ๊ฐ YOLOv3
์ makefile์ ๊ตฌ์กฐ์ด๋ค. ์ฌ์ฉํ Jetson Xavier
์ฉ์ ์์ผ๋ฏ๋ก ์ถ๊ฐํด ์ฃผ์.
ARCH= -gencode arch=compute_30,code=[sm_30,compute_30] \
-gencode arch=compute_35,code=[sm_35,compute_35] \
-gencode arch=compute_50,code=[sm_50,compute_50] \
-gencode arch=compute_52,code=[sm_52,compute_52] \
-gencode arch=compute_61,code=[sm_61,compute_61] \
-gencode arch=compute_72,code=[sm_72,compute_72]
์๋จ์ OPENCV=1
GPU=1
CUDNN=1
์ด ์ธ๊ฐ ๋ชจ๋ ํ์ฑํ ํ๋ค.
์๋๋ฅผ ์ํด์ gpu
์ cudnn
์ ํ์ฑํํ๊ณ real-time ๋ฐ๋ชจ๋ฅผ ์ํด์ opencv
๋ ํ์ฑํํ๋ค.
์ปดํ์ผ
๋์ ์๋๋ฅผ ๋น ๋ฅด๊ฒ ์ค์
sudo nvpmodel -m 0
jetson_clocks.sh
make -j4
๋ช
๋ น์ด ์ํ
nvidia@jetson-0423718017159:~/Computer_Vision_Project/yolov3$ make -j4
mkdir -p obj
mkdir -p backup
mkdir -p results
gcc -Iinclude/ -Isrc/ -DOPENCV `pkg-config --cflags opencv` -DGPU -I/usr/local/cuda/include/ -DCUDNN -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -DOPENCV -DGPU -DCUDNN -c ./src/gemm.c -o obj/gemm.o
gcc -Iinclude/ -Isrc/ -DOPENCV `pkg-config --cflags opencv` -DGPU -I/usr/local/cuda/include/ -DCUDNN -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -DOPENCV -DGPU -DCUDNN -c ./src/utils.c -o obj/utils.o
gcc -Iinclude/ -Isrc/ -DOPENCV `pkg-config --cflags opencv` -DGPU -I/usr/local/cuda/include/ -DCUDNN -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -DOPENCV -DGPU -DCUDNN -c ./src/cuda.c -o obj/cuda.o
gcc -Iinclude/ -Isrc/ -DOPENCV `pkg-config --cflags opencv` -DGPU -I/usr/local/cuda/include/ -DCUDNN -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -DOPENCV -DGPU -DCUDNN -c ./src/deconvolutional_layer.c -o obj/deconvolutional_layer.o
./src/gemm.c: In function โtime_gpuโ:
./src/gemm.c:232:9: warning: โcudaThreadSynchronizeโ is deprecated [-Wdeprecated-declarations]
cudaThreadSynchronize();
^~~~~~~~~~~~~~~~~~~~~
In file included from /usr/local/cuda/include/cuda_runtime.h:96:0,
from include/darknet.h:11,
from ./src/utils.h:5,
from ./src/gemm.c:2:
/usr/local/cuda/include/cuda_runtime_api.h:947:57: note: declared here
extern __CUDA_DEPRECATED __host__ cudaError_t CUDARTAPI cudaThreadSynchronize(void);
^~~~~~~~~~~~~~~~~~~~~
gcc -Iinclude/ -Isrc/ -DOPENCV `pkg-config --cflags opencv` -DGPU -I/usr/local/cuda/include/ -DCUDNN -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -DOPENCV -DGPU -DCUDNN -c ./src/convolutional_layer.c -o obj/convolutional_layer.o
...
...
...
bj/col2im_kernels.o obj/blas_kernels.o obj/crop_layer_kernels.o obj/dropout_layer_kernels.o obj/maxpool_layer_kernels.o obj/avgpool_layer_kernels.o
gcc -Iinclude/ -Isrc/ -DOPENCV `pkg-config --cflags opencv` -DGPU -I/usr/local/cuda/include/ -DCUDNN -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -DOPENCV -DGPU -DCUDNN obj/captcha.o obj/lsd.o obj/super.o obj/art.o obj/tag.o obj/cifar.o obj/go.o obj/rnn.o obj/segmenter.o obj/regressor.o obj/classifier.o obj/coco.o obj/yolo.o obj/detector.o obj/nightmare.o obj/instance-segmenter.o obj/darknet.o libdarknet.a -o darknet -lm -pthread `pkg-config --libs opencv` -lstdc++ -L/usr/local/cuda/lib64 -lcuda -lcudart -lcublas -lcurand -lcudnn -lstdc++ libdarknet.a
๋น๋๊ฐ ์๋ฃ๋๋ฉด data
๋๋ ํฐ๋ฆฌ ์์ ๋ช๊ฐ์ ์ํ ์ด๋ฏธ์ง๋ค์ด ์กด์ฌํ๋ค.
์ด๊ฒ๋ค์ ๊ฐ์ง๊ณ ํ
์คํธ ํ ์๋ ์๊ณ ๋น๋์ค ์์์ ๋ค์ด๋ฐ์์ ํ ์๋ ์๋ค.
์คํ ๋ฐ ์ฑ๋ฅ ํ
์คํธ
์ด๋ฏธ์ง ํ
์คํ
์๋๋ ํ๋์ ์ด๋ฏธ์ง์ ๋ํด์ xaiver
์ geforece
์์ ๊ฐ๊ฐ ์ํํด๋ณธ ๊ฒฐ๊ณผ์ด๋ค.
๊ทธ๋ฅ darknet
์์ฒด๋ฅผ ๋ ๊ฒ์ผ๋ก ๋๋ ค์ ์ฑ๋ฅ์ฐจ์ด๋ 3๋ฐฐ์ ๋ ๋ฐ์ํ๋ค.
์๋น์ ๋ ฅ์ด 30W
๋ 120W
์์ค์ ์ฐจ์ด์ด๋ฏ๋ก ์ฑ๋ฅ์ฐจ์ด๋ ์ ๋ค๊ณ ํ ์๋ ์๊ฒ ๋ค.
xavier
`./darknet detect cfg/yolov3.cfg yolov3.weights data/dog.jpg`
Loading weights from yolov3.weights...Done!
data/dog.jpg: Predicted in `0.164729` seconds.
Geforce-1080
Loading weights from yolov3.weights...Done!
data/dog.jpg: Predicted in 0.051647 seconds.
์์ ํ
์คํ
detector
๋ช
๋ น์ด๋ฅผ ์ํํ ๊ฒฝ์ฐ ์์๊ณผ Camera๋ก ์ค์๊ฐ ํ
์คํ
๋ ํ ์ ์๋ค.
./darknet detector demo cfg/coco.data cfg/yolov3.cfg yolov3.weights <video file>
๋์์์ผ๋ก ์๋์ ๊ฐ์ด YOLOv3๋ฅผ xavier์์ ์ํํ ๊ฒฝ์ฐ ๋๋ต 5~6 FPS
๊ฐ ์ธก์ ๋๋ค.
๋ผ์ด๋ธ ๋ฐ๋ชจ๋ Youtube์์ ๋ณผ์ ์๋ค.
์ฐธ๊ณ ์๋ฃ
[1] ๊ณต์ wiki
[2] JK Jung's blog, YOLOv3 on Jetson TX2
[3] [์ค๊ตญ ์ฌ์ดํธ] (http://takesan.hatenablog.com/entry/2018/10/07/003252)