티스토리 뷰

728x90
반응형

Detectron2 는 facebook AI에서 오픈한 object detection 라이브러리이다. 

 

github.com/facebookresearch/detectron2

 

facebookresearch/detectron2

Detectron2 is FAIR's next-generation platform for object detection and segmentation. - facebookresearch/detectron2

github.com

 

도커 이미지 만들기

 

도커 이미지를 만들 수 잇는 Dockerfile이 있으며 설치 방법이 있다. 

github.com/facebookresearch/detectron2/tree/master/docker

 

facebookresearch/detectron2

Detectron2 is FAIR's next-generation platform for object detection and segmentation. - facebookresearch/detectron2

github.com

 

먼저, 소스를 클론 받는다.

$ git clone https://github.com/facebookresearch/detectron2.git

Dockerfile이 위치한 폴더로 찾아가서 docker build 명령으로 도커 이미지를 생성한다. 

$ cd detectron2
$ cd docker
$ docker build --build-arg USER_ID=$UID -t detectron2:v0 .

필자는 첫번째 에러가 나서 해결책을 찾아 빌드 명령을 다시 한번 실행하니 detectron2:v0라는 이미지가 생성되었다. 

 

 

도커 실행 하기

도커를 실행하고 도커안에서 윈도우상에 이미지를 보기 위해 다음 명령어를 입력한다. 간단하게 xhost +local:docker 만 해도 되는데 여기서는 detectron2라는 이름을 가진 도커이미지에게만 접근 권한을 주기 위해 세부적인 옵션을 부여하였다.

$ xhost +local:`docker inspect --format='{{ .Config.Hostname }}' detectron2`

도커는 다음 옵션들을 유의하여 제작한 detectron2:v0 이미지를 실행한다. 연결된 카메라를 도커에 연결하기 위해 --device옵션을 사용한다. 

$ docker run --gpus all -it \
	--shm-size=8gb --env="DISPLAY" --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \
    --device=/dev/video0:/dev/video0 \
	--name=detectron2 detectron2:v0

이외에도 -v (--volume) 옵션을 이용해 필요한 모델 파일을 저장해 두기 위한 로컬 파일 폴더를 연결해두면 좋다.

 

데모 실행 해보기

데모 실행 방법은 다음과 같이 demo.py를 찾아 옵션을 선택하면 된다.

github.com/facebookresearch/detectron2/blob/master/GETTING_STARTED.md

 

facebookresearch/detectron2

Detectron2 is FAIR's next-generation platform for object detection and segmentation. - facebookresearch/detectron2

github.com

이미지 파일을 입력으로 넣지 않기 때문에 입력관련 옵션을 --webcam으로 바꾸어 실행한다. 또한 python3가 아니라 sudo python3로 root권한으로 실행하도록 한다. 

$ cd detectron2_repo/demo
$ sudo python3 demo.py \
      --config-file ../configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml \
      --webcam --opts MODEL.WEIGHTS \
      detectron2://COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl

다음과 같이 instance segmentation 결과가 실행되는 것을 확인할 수 있다.

 

 

Troubleshooting: Failed to load OpenCL runtime

위의 코드가 필자는 바로 실행되지 않고 Failed to load OpenCL runtime 에러가 나왔다. 구글링 결과 OpenCV가 하위 버전으로 설치되어 있기 때문이다. 빌드한 도커에 설치된 OpenCV 버전은 3.2.0인데 이슈리포트에 의하면 3.4이상 되어야 문제가 없어진다고 답변이 있다.

 

다음 명령으로 OpenCV를  설치하면 최신 버전으로 업그레이드가 되어 에러가 사라진다.

$ python -m pip install opencv-python

 

 

728x90
반응형
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/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
글 보관함