티스토리 뷰

다룰 내용

 

- 지난 포스팅에서는 설치, 다운로드 해야할 것들을 정리해

- 이번에는 Visual Studio 설정 빌드하기와

- 실시간 스트리밍, 동영상에서 object detection 해보겠음

 

 

visual studio 설정 빌드

 

- 다양한 경우에 대한 설정, 빌드 방법은 깃헙의 원문을 참조할

- README 상세히 설명되어 있음: https://github.com/AlexeyAB/darknet/

 

저도 시행착오를 거쳐 동작시킨 다시 기억을 더듬어 적는 것이다 보니,

따라하시다 막히시거나 추가로 설정해야 하는 부분을 찾으시면 댓글 달아주시면 도움 되겠습니다.

 

1) darknet.sln 실행

 

- github 에서 다운로드 받은 darknet 소스에서 darknet.sln 실행

 


 

- Visual Studio 에서 Release , x64 선택

 


 

2) 솔루션 속성 >> C/C++

 

- 솔루션 속성 창에서 (Alt+Enter) >> C/C++ >> 추가 포함 디렉토리

- 여기에 OpenCV include, CUDA, cuDNN 경로가 포함되어 있어야 한다.

 


 

C/C++ >> 전처리기 에서 CUDNN 정의

 


 

3) 솔루션 속성 >> 링커

 

- 마찬가지로 OpenCV include, CUDA, cuDNN 경로가 명시되어 있어야 한다.

 


 

 

4) 기타등등

 

- src 폴더안의 모든 .c, .co and http_stream.cpp 파일을 프로젝트에 추가할

 

 

5) 그리고 빌드

 

- 여기까지 따라오시느라 수고 많으셨음.

- 그리고 빌드를 해보자 Ctrl+F5

 

 

실행 준비

 

yolov3.weights

 

- 이미 학습된 yolo v3 weight 다운로드 받아서

- (빌드로 생성된) darknet.exe 파일이 있는 폴더 (darknet\build\darknet\x64) 복사해둔다.

- 다운로드 링크:

yolov3.cfg (236 MB COCO Yolo v3) - requires 4 GB GPU-RAM: https://pjreddie.com/media/files/yolov3.weights

yolov3-tiny.cfg (34 MB COCO Yolo v3 tiny) - requires 1 GB GPU-RAM: https://pjreddie.com/media/files/yolov3-tiny.weights

yolov2.cfg (194 MB COCO Yolo v2) - requires 4 GB GPU-RAM: https://pjreddie.com/media/files/yolov2.weights

yolo-voc.cfg (194 MB VOC Yolo v2) - requires 4 GB GPU-RAM: http://pjreddie.com/media/files/yolo-voc.weights

yolov2-tiny.cfg (43 MB COCO Yolo v2) - requires 1 GB GPU-RAM: https://pjreddie.com/media/files/yolov2-tiny.weights

yolov2-tiny-voc.cfg (60 MB VOC Yolo v2) - requires 1 GB GPU-RAM: http://pjreddie.com/media/files/yolov2-tiny-voc.weights

yolo9000.cfg (186 MB Yolo9000-model) - requires 4 GB GPU-RAM: http://pjreddie.com/media/files/yolo9000.weights

 

OpenCV dll

 

OpenCV dll 가지를, 마찬가지로 (빌드로 생성된) darknet.exe 파일이 있는 폴더에 복사해둔다.

 

opencv_world340.dll

opencv_ffmpeg340_64.dll

 

 

 

드디어 실행

 

스트리밍 object detection

 

- 노트북 웹캠에서 나오는 실시간 스트리밍으로 object detection 해보자

- 그냥 아래 cmd 파일중 darknet_web_cam_voc.cmd 실행했더니 동작함

# play video from Web-Camera number 0

rem darknet.exe detector demo data/voc.data cfg/yolov2-voc.cfg yolo-voc.weights -c 0

darknet.exe detector demo data/coco.data cfg/yolov3.cfg yolov3.weights -c 0

pause

 

동영상 object detection

 

- 원하는 파일을 test.mp4 이름을 변경해서 darknet.exe 있는 폴더에 복사후

- darknet_yolo_v3_video.cmd 실행하면 된다.

darknet.exe detector demo data/coco.data yolov3.cfg yolov3.weights -i 0 -thresh 0.25 -ext_output test.mp4

pause

 

 

참고: 깃헙 원문의 How to use

Example of usage in cmd-files from build\darknet\x64\:

- darknet\build\darknet\x64 폴더의 .cmd 실행

 

darknet_yolo_v3.cmd

- initialization with 236 MB Yolo v3 COCO-model yolov3.weights & yolov3.cfg and show detection on the image: dog.jpg

darknet_voc.cmd

- initialization with 194 MB VOC-model yolo-voc.weights & yolo-voc.cfg and waiting for entering the name of the image file

darknet_demo_voc.cmd

- initialization with 194 MB VOC-model yolo-voc.weights & yolo-voc.cfg and play your video file which you must rename to: test.mp4

darknet_demo_store.cmd

- initialization with 194 MB VOC-model yolo-voc.weights & yolo-voc.cfg and play your video file which you must rename to: test.mp4, and store result to: res.avi

darknet_net_cam_voc.cmd

- initialization with 194 MB VOC-model, play video from network video-camera mjpeg-stream (also from you phone)

darknet_web_cam_voc.cmd

- initialization with 194 MB VOC-model, play video from Web-Camera number #0

darknet_coco_9000.cmd

- initialization with 186 MB Yolo9000 COCO-model, and show detection on the image: dog.jpg

darknet_coco_9000_demo.cmd 

- initialization with 186 MB Yolo9000 COCO-model, and show detection on the video (if it is present): street4k.mp4, and store result to: res.avi

 

How to use on the command line:

- On Linux use ./darknet instead of darknet.exe, like this:./darknet detector test ./cfg/coco.data ./cfg/yolov3.cfg ./yolov3.weights

 

Yolo v3 COCO - image:

darknet.exe detector test data/coco.data cfg/yolov3.cfg yolov3.weights -i 0 -thresh 0.25

Alternative method Yolo v3 COCO - image:

darknet.exe detect cfg/yolov3.cfg yolov3.weights -i 0 -thresh 0.25

Output coordinates of objects:

darknet.exe detector test data/coco.data yolov3.cfg yolov3.weights -thresh 0.25 dog.jpg -ext_output

194 MB VOC-model - image: 

darknet.exe detector test data/voc.data yolo-voc.cfg yolo-voc.weights -i 0

194 MB VOC-model - video: 

darknet.exe detector demo data/voc.data yolo-voc.cfg yolo-voc.weights test.mp4 -i 0

194 MB VOC-model - save result to the file res.avi: 

darknet.exe detector demo data/voc.data yolo-voc.cfg yolo-voc.weights test.mp4 -i 0 -out_filename res.avi

Alternative method 194 MB VOC-model - video: 

darknet.exe yolo demo yolo-voc.cfg yolo-voc.weights test.mp4 -i 0

43 MB VOC-model for video: 

darknet.exe detector demo data/coco.data cfg/yolov2-tiny.cfg yolov2-tiny.weights test.mp4 -i 0

Yolo v3 236 MB COCO for net-videocam - Smart WebCam: 

darknet.exe detector demo data/coco.data cfg/yolov3.cfg yolov3.weights http://192.168.0.80:8080/video?dummy=param.mjpg -i 0

194 MB VOC-model for net-videocam - Smart WebCam: 

darknet.exe detector demo data/voc.data yolo-voc.cfg yolo-voc.weights http://192.168.0.80:8080/video?dummy=param.mjpg -i 0

194 MB VOC-model - WebCamera #0: 

darknet.exe detector demo data/voc.data yolo-voc.cfg yolo-voc.weights -c 0

186 MB Yolo9000 - image: 

darknet.exe detector test cfg/combine9k.data yolo9000.cfg yolo9000.weights

 

Remeber to put data/9k.tree and data/coco9k.map under the same folder of your app if you use the cpp api to build an app

To process a list of images data/train.txt and save results of detection to result.txt use:

darknet.exe detector test data/voc.data yolo-voc.cfg yolo-voc.weights -dont_show -ext_output < data/train.txt > result.txt 

 

 

For using network video-camera mjpeg-stream with any Android smartphone:

 

Download for Android phone mjpeg-stream soft: IP Webcam / Smart WebCam

Smart WebCam - preferably: https://play.google.com/store/apps/details?id=com.acontech.android.SmartWebCam2

IP Webcam: https://play.google.com/store/apps/details?id=com.pas.webcam

Connect your Android phone to computer by WiFi (through a WiFi-router) or USB

 

Start Smart WebCam on your phone

Replace the address below, on shown in the phone application (Smart WebCam) and launch:

194 MB COCO-model: 

darknet.exe detector demo data/coco.data yolo.cfg yolo.weights http://192.168.0.80:8080/video?dummy=param.mjpg -i 0

194 MB VOC-model: 

darknet.exe detector demo data/voc.data yolo-voc.cfg yolo-voc.weights http://192.168.0.80:8080/video?dummy=param.mjpg -i 0

 

 

ToDo List

 

- 기약할 수는 없지만, 위의 다양한 command 들을 하나씩 테스트 해보고 싶음

- 나만의 dataset 만들어서 train 해보고 싶음

 

Trouble Shooting

 

Q. 빌드중 에러메시지 발생

- "the cuda toolkit v9.2 directory '' does not exist. please verify the cuda toolkit is installed properly or define the cudatoolkitdir property to resolve this error."

- cublas64_92.dll 찾지 못하는 경우도 있었음

 

A1. nVidia CUDA, cuDNN 관련한 프로그램, 폴더를 지우고 새로운 마음으로 다시 깔아보자

A2. 대부분은 CUDA 관련한 PATH 설정 문제임

 

* Visual Studio CUDA 설정 관련 참고링크: https://goo.gl/94WKWt


반응형

'deep learning' 카테고리의 다른 글

이미지 임베딩이란?  (0) 2023.04.13
윈도우즈에서 yolo v3 돌려보기 1/2  (0) 2018.08.02
반응형
잡학툰 뱃지
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/04   »
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
글 보관함