모듈실행
- parse_opt(입력한 parameter들) 실행 -> opt return
- main(opt) 실행
- run(opt) 실행: 우리가 입력한 모델(yolo5s.pt)과 데이터(img.jpg) 등을 기준으로 추론 및 결과저장 실행
객체인식 모듈(test시) - detect.py
기존 모델로 돌리는 경우, weights에 모델명을 넣는다.
!python detect.py --weights yolov5s.pt --source 0
학습된 모델로 돌리는 경우, runs폴더의 결과 weights를 사용한다.
!python detect.py --weights runs/train/results/weights/best.pt --img 416 --conf 0.4 --source ./test/0_Concern-In-China-As-Mystery-Virus-Spreads_jpg.rf.3135dfc5feab288d76a4ccfd22dfc5bf.jpg
학습 모듈 - train.py
평가 모듈 - val.py
기존모델 - %cat /content/yolov5/models/
- %cat 파일정보 출력
- 모델 스케일이 다름
- 모든 필터 구조에 아래 부분을 곱해서 사용한다.
- yolov5x
- depth_multiple: 1.33 # model depth multiple
- width_multiple: 1.25 # layer channel multiple
- yolov5l
- depth_multiple: 1.0 # model depth multiple
- width_multiple: 1.0 # layer channel multiple
- yolov5m
- depth_multiple: 0.67 # model depth multiple
- width_multiple: 0.75 # layer channel multiple
- yolov5s
- depth_multiple: 0.33 # model depth multiple
- width_multiple: 0.50 # layer channel multiple
- yolov5n
- depth_multiple: 0.33 # model depth multiple
- width_multiple: 0.25 # layer channel multiple
config.yaml, dataset.yaml
- pytorch를 이용하여 학습시킬 때, yaml파일 사용한다.
- %%writetemplate /content/yolov5/config.yaml
- %%writetemplate - 입력 텍스트 그대로 저장
model:
name: yolov5s # Model name (you can choose 'yolov5s', 'yolov5m', 'yolov5l', 'yolov5x')
cfg: /content/yolov5/models/yolov5s.yaml # Path to the model architecture file
dataset:
train: ./train
val: ./valid
test: ./test
nc: 2
names: ['mask', 'no-mask']
training:
epochs: 50 # Number of epochs
batch_size: 16 # Batch size
learning_rate: 0.001 # Learning rate
device: cuda # Device to use for training (cuda or cpu)
- %%writetemplate /content/yolov5/dataset.yaml
train: ./train
val: ./valid
test: ./test
nc: 2
names: ['mask', 'no-mask']
config = yaml.safe_load(f)
yaml 텍스트를 딕셔너리로 처리해 줌.
with open(yaml_path, 'r') as f:
config = yaml.safe_load(f)
return config
best.pt, last.pt - 기록위치(weights)부터 모듈실행
- /content/yolov5/runs/train/results/weights
- EarlyStopping
- paient = 3, 일때, best기록과 마지막 기록