프로젝트 기록/딥러닝 모델 개발_공학설계캡스톤디자인(스마트카ICT)
[YOLOv5] 코랩 GPU가속으로 학습시키기
소요이
2023. 5. 14. 22:37
728x90
가장 먼저
파일> 새 노트북 만들기
런타임> 런타임 유형 변경>GPU선택
을 해야한다.
0. 파일 바로 코랩 디렉토리에 넣기
content > yolov5 > data > test01_custom 폴더에
YOLOv5용 데이터셋 압축파일을 넣은 다음, 시작했다.
1. YOLO v5 설치
!git clone https://github.com/ultralytics/yolov5
%cd yolov5
!pip install -r requirements.txt
2. 업로드한 파일 압축 해제
!unzip ./data/test01_custom/test01_custom.zip -d ./data/test01_custom/
3. yaml파일 경로를 코랩 환경에 맞게 변경 (원래는 로컬 파일 경로였음)
import yaml
with open("./data/test01_custom/test01_custom.yaml") as f:
config = yaml.load(f, Loader=yaml.FullLoader)
config["train"] = "./data/test01_custom/train/images"
config["val"] = "./data/test01_custom/test/images"
with open("./data/test01_custom/test01_custom.yaml", "w") as f:
yaml.dump(config, f)
4. 학습 시작
!python train.py --img 640 --batch 16 --epochs 300 --data ./data/test01_custom/test01_custom.yaml --weights yolov5s.pt --cache
"""epochs = 300 """
5. 학습 완료
6. 테스트(검증) 데이터셋 확인
!python detect.py --weights runs/train/exp2/weights/best.pt --img 640 --conf 0.25 --source ./data/test01_custom/test/images
detect > exp2 폴더의 검증용 사진에 감지 잘 된것 확인
다른 자세를 했을때는 감지가 잘 안됐음.
추가 학습으로 해결될 것 같음