yolov5 다운로드 및 라이브러리 설치
!git clone https://github.com/ultralytics/yolov5
%cd yolov5
%pip install -qr requirements.txt
yolo 디렉터리 구조 예시
yolov5
+ data
+ images
+ train
- a.jpg
- b.jpg
+ valid
- c.jpg
- d.jpg
+ labels
+ train
- a.txt
- b.txt
+ valid
- c.txt
- d.txt
- coco128.yaml
+ models
- yolov5l.yaml
- yolov5m.yaml
- yolov5n.yaml
- yolov5s.yaml
- yolov5x.yaml
- detect.py
- train.py
- val.py
.
.
.
images : 훈련할 이미지 디렉터리
labels : 훈련할 이미지에 대한 라벨 파일들이 저장된 디렉터리
models : yolo 받을 때 같이 받아지는 yolo 버전별 yaml 파일들 존재
data 디렉터리에 yaml파일 생성
yolo를 받을 때 받아지는 coco128.yaml 파일을 복사하여 자신만의 yaml 파일을 수정한다
path: ../yolov5/data/ # dataset root dir
train: images/train # train images (relative to 'path') 128 images
val: images/train # val images (relative to 'path') 128 images
#test: # test images (optional)
# Classes
nc: 2 # number of classes
names: ['plate','1'
] # class names
path : yaml파일과 images가 있는 yolov5 디렉터리의 data디렉터리를 루트 디렉터리로 설정
train : train이미지들이 있는 디렉터리 경로
val : val 이미지들이 있는 디렉터리 경로
nc : class 개수 (분류할 카테고리 개수)
names : 클래스들을 리스트로 나열
훈련
!python train.py –img 640 –batch 16 –data “yaml 경로” –epochs 10 –cfg ./models/yolov5s.yaml –cfg ./models/yolov5s.yaml –name yolov5_test
기타 오류 해결방안
yolo omp: error #15: initializing libiomp5md.dll, but found libiomp5md.dll already initialized. omp: hint this means that multiple copies of the openmp runtime have been linked into the program. that is dangerous, since it can degrade performance or cause incorrect results. the best thing to do is to ensure that only a single openmp runtime is linked into the process, e.g. by avoiding static linking of the openmp runtime in any library. as an unsafe, unsupported, undocumented workaround you can set the environment variable kmp_duplicate_lib_ok=true to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. for more information, please see http://www.intel.com/software/products/support/.
아래 코드 train.py에 추가 (train.py를 사용해서 상단 에러가 발생했을 경우.)
import os
os.environ['KMP_DUPLICATE_LIB_OK']= 'True'