파일트리
darknet
ㄴmonday (학습 dir 생성)
ㄴobj.names
ㄴobj.data
ㄴyolov3-tiny.cfg
ㄴback
ㄴtrain.txt
ㄴval.txt
ㄴtrain_img (train_img, train_txt dir)
ㄴtrain_img(1).png
ㄴtrain_img(1).txt
ㄴtrain_img(2).png
ㄴtrain_img(2).txt
ㄴ...
ㄴval_img (val_img, val_txt dir)
ㄴval_img(1).png
ㄴval_img(1).txt
ㄴval_img(2).png
ㄴval_img(2).txt
ㄴ...
<aside> 📌 train_img, val_img 파일의 비율은 8:2 폴더 내에 이미지 파일, txt 파일 둘 다 넣어야 함.
</aside>
train.txt 파일 만드는 코드
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
def list_files(directory, output_file):
with open(output_file, 'w') as file:
with os.scandir(directory) as entries:
for entry in entries:
if entry.is_file() and entry.name.endswith('.png'): #파일중에 이미지 파일만 선택
absolute_path = os.path.abspath(entry)
file.write(absolute_path + '\\n')
directory_path = '/home/road/darknet/monday/train_img' #train_img 파일이 있는 경로
output_file = 'train.txt' #저장할 파일 이름
list_files(directory_path, output_file)
val.txt 파일 만드는 코드
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
def list_files(directory, output_file):
with open(output_file, 'w') as file:
with os.scandir(directory) as entries:
for entry in entries:
if entry.is_file() and entry.name.endswith('.png'): #파일중에 이미지 파일만 선택
absolute_path = os.path.abspath(entry)
file.write(absolute_path + '\\n')
directory_path = '/home/road/darknet/monday/val_img' #train_img 파일이 있는 경로
output_file = 'val.txt' #저장할 파일 이름
list_files(directory_path, output_file)
obj.names 파일 만들기 ‼파일 내에 한글은 없어야 함
person
bicycle
car
#인식할 객체 이름 작성 (labeling 때 순서 꼭 지켜야 함)
obj.data 파일 만들기‼파일 내에 한글은 없어야 함
classes = 3 #학습할 클래스 수
train = monday/train.txt #train.txt 파일 경로
valid = monday/val.txt #val.txt 파일 경로
names = monday/obj.names #obj.names 파일 경로
backup = monday/back/ #가중치 파일 저장 경로
obj.cfg 파일 만들기
darknet/cfg 폴더 내에 있는 cfg 파일들 중 학습하고자 하는 버전에 맞는 cfg 파일을 가져온다.
ex) yolv3_tiny 버전으로 학습할 예정이라면 yolov3-tiny.cfg 파일
yolov4 버전으로 학습할 계획이라면 yolov4.cfg 파일
cfg파일 수정하기
filters=(클래스 수 + 5) * 3
클래스 수가 3이라면, (3 + 5) * 3 = 24
classes=학습 클래스 수
<aside> 📌 Caution