
우리는 우분투에서 yolo 를 실행하기 위해 CUDA, OpenCV, cuDNN 설정을 해줘야 한다. 이 설정에 대한 방법은 추후 본블로그 글에서 확인할 수 있을 것이다.
sudo apt update
pip install opencv-python
sudo apt install libopencv-dev
sudo apt 로 opencv 를 설치 할 수도 있지만 이러면 최신버전인 OpenCV 인 4.xx 가 아닌 3.xx 가 설치되므로 위와 같이 실행하여 설치를 해주자.
다음으로 cuDNN 과 CUDA 가 설정되어 있어야 하는데 이는 다음 글에서 설명하겠다. 참고로 depth 가 나오는 ZED 카메라를 사용하려면 CUDA 버전이 11.5 여야 하므로(우분투 20.04 기준)(18.04 는 10.2) 이를 꼭 참고하여 설정해줘야 한다.
그 다음 원하는 장소에 yolo 설치를 위해 git clone 을 해준다.
https://github.com/AlexeyAB/darknet.git
그 다음 설치된 darknet 폴더 안에 Makefile 을 수정해줘야 한다. Makefile 수정의 이유와 자세한 설명들은 아래 링크를 보면 되고 바로 사용하려면 아래와 같이 수정하면 된다.
https://github.com/AlexeyAB/darknet/#how-to-compile-on-linux-using-make
GitHub - AlexeyAB/darknet: YOLOv4 / Scaled-YOLOv4 / YOLO - Neural Networks for Object Detection (Windows and Linux version of Da
YOLOv4 / Scaled-YOLOv4 / YOLO - Neural Networks for Object Detection (Windows and Linux version of Darknet ) - GitHub - AlexeyAB/darknet: YOLOv4 / Scaled-YOLOv4 / YOLO - Neural Networks for Object ...
github.com
GPU=1
CUDNN=1
CUDNN_HALF=1
OPENCV=1
그 다음 자신의 GPU 에 맞는 ARCH 를 설정해줘야 한다. 이는 아래 링크에서 확인하고 만약 Nvidia GPU 6.1 로 나와 있으면 아래와 같이 61로 변경해서 적으면 된다.
https://developer.nvidia.com/cuda-gpus
CUDA GPUs
Your GPU Compute Capability Are you looking for the compute capability for your GPU, then check the tables below. You can learn more about Compute Capability here. NVIDIA GPUs power millions of desktops, notebooks, workstations and supercomputers around th
developer.nvidia.com
ARCH= -gencode arch=compute_61,code=[sm_61,compute_61]
그 다음 수정된 사항들을 적용시켜주는 명령을 한다. 아래와 같이 하면 된다.
cd darknet
make
그 다음 yolo v4 의 weight 파일을 다운로드 해야한다. 아래와 같이 받으면 된다.
wget https://github.com/AlexeyAB/darknet/releases/download/darknet_yolo_v3_optimal/yolov4.weights
이제 yolo 를 실행시켜보자. 먼저 예시 사진 명령어는 아래와 같다. 두가지 명령어 모두 같은 아웃풋이다.
./darknet detect cfg/yolov4.cfg yolov4.weights data/dog.jpg
./darknet detector test cfg/coco.data cfg/yolov4.cfg yolov4.weights data/dog.jpg
이 명령어는 먼저 ./darknet 은 "현재 darknet 폴더에서" 라는 뜻이고 detect 는 말 그대로 detect 한다는 것이고 cfg/yolov4.cfg 는 우리가 설정한 yolo 의 레이어 대로 실행한다는 뜻이고 yolov4.weights 는 우리가 다운 받거나 직접 학습시켜서 만들어낸 weight file 을 사용한다는 뜻이고 data/dog.jpg 는 data 폴터 안에 dog.jpg 라는 파일을 detect 하라는 뜻이다.
이제 Real-Time Detection 을 웹캠으로 하기 위한 명령어는 아래와 같다.
./darknet detector demo cfg/coco.data cfg/yolov4.cfg yolov4.weights
이 명령어를 노트북에서 실행하면 아마 내장된 웹캠으로 켜질 것이므로 카메라를 바꾸고 싶다면 아래와 같이 위에 -c 1, -c 2 와 같이 설치한 웹캠이 몇번째 카메라인지 찾으며 실행시켜 보면 된다.
./darknet detector demo cfg/coco.data cfg/yolov4.cfg yolov4.weights -c 2
또한 detection 에 대한 디버깅을 하기 위해 녹화된 영상을 yolo 로 돌리기 위해서는 아래와 같은 명령어를 실행시키면 된다.
./darknet detector demo cfg/coco.data cfg/yolov4.cfg yolov4.weights <video file>
./darknet detector demo cfg/coco.data cfg/yolov4.cfg yolov4.weights <video file> -out_filename <output_video file>
다음에는 custom data 를 통해 학습하는 방법을 설명하도록 하겠다.
------------------------------
자주 발생하는 오류 해결 링크
https://stackoverflow.com/questions/55035797/darknet-segmentation-fault-core-dumped
Darknet- Segmentation fault (core dumped)
I'm trying to do object detection using YOLOv2 on my custom dataset(ubuntu 18.04). The following error ocurs:- 115: nan, nan avg loss, 0.001000 rate, 17.887053 seconds, 2760 images Loaded: 0.000045
stackoverflow.com
| Ubuntu 22.04에서 기본 터미널 프로그램을 Hyper로 변경하기 (0) | 2023.05.06 |
|---|---|
| CMake를 이용한 Eigen3과 OpenCV 라이브러리 포함하기 (0) | 2023.05.06 |
| Install Nvidia graphic driver, Cuda Toolkit & Cudnn in Ubuntu 22.04 (0) | 2023.05.04 |
| Anaconda 사용법 - 설치부터 가상환경 생성 및 제거까지 (1) | 2023.04.10 |
| pytorch 기본 개념 , tensor , 차원 (0) | 2023.01.31 |
댓글 영역