-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyolov5_trainning.py
62 lines (39 loc) · 1.87 KB
/
yolov5_trainning.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# -*- coding: utf-8 -*-
"""yolov5_trainning.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/###
# **사전 설치**
"""
from google.colab import drive
drive.mount('/content/drive')
!git clone https://github.com/ultralytics/yolov5
# Commented out IPython magic to ensure Python compatibility.
# %cd yolov5
# %pip install -qr requirements.txt
"""# **데이터셋 가져오기**
"""
!curl -L "#########--insert your URL--###########" > roboflow.zip;
!unzip roboflow.zip; rm roboflow.zip
"""# **이미지 한번에 긁어모으기 위한 glob 모듈 사용**"""
from glob import glob
tra_img_list = glob('/content/yolov5/train/images/*.jpg') # train 이미지 경로
val_img_list = glob('/content/yolov5/test/images/*.jpg') # 테스트 이미지 경로
with open('/content/yolov5/train.txt', 'w') as f:
f.write('\n'.join(tra_img_list) + '\n')
with open('/content/yolov5/test.txt', 'w') as f:
f.write('\n'.join(val_img_list) + '\n')
"""# **커스텀 학습**"""
!python train.py --img 416 --batch 16 --epochs 40 --data /content/yolov5/data.yaml --weights yolov5m.pt --name result_fire --cfg ./models/yolov5m.yaml
"""# **학습 결과를 다운로드하고 싶다면, 내용 모두 압축하여 저장**"""
!zip -r ../drive/MyDrive/Colab_Notebooks/custom_train_result_ver10.zip runs/train/result_fire3
"""# **검증하기는 생략, 바로 적용해보기**
테스트 결과는 ```/runs/detect/exp``` 경로에 저장
"""
!python detect.py --weights "/content/yolov5/runs/train/result_fire3/weights/best.pt" --source 'https://www.youtube.com/watch?v=ai0-jT6kuoA' # YouTube
!zip -r test_result.zip runs/detect/exp
"""# **코랩 유지에 필요한 코드(F12 Javascript)**"""
function ClickConnect(){
console.log("Working");
document.querySelector("colab-toolbar-button#connect").click()
}setInterval(ClickConnect, 450000)