Commit
·
44cdcc7
1
Parent(s):
ffe9eb4
hyp['anchors'] evolution update
Browse files- train.py +4 -4
- utils/evolve.sh +3 -2
train.py
CHANGED
@@ -68,8 +68,8 @@ def train(hyp, opt, device, tb_writer=None):
|
|
68 |
with torch_distributed_zero_first(rank):
|
69 |
attempt_download(weights) # download if not found locally
|
70 |
ckpt = torch.load(weights, map_location=device) # load checkpoint
|
71 |
-
|
72 |
-
|
73 |
model = Model(opt.cfg or ckpt['model'].yaml, ch=3, nc=nc).to(device) # create
|
74 |
exclude = ['anchor'] if opt.cfg else [] # exclude keys
|
75 |
state_dict = ckpt['model'].float().state_dict() # to FP32
|
@@ -472,7 +472,7 @@ if __name__ == '__main__':
|
|
472 |
'obj_pw': (1, 0.5, 2.0), # obj BCELoss positive_weight
|
473 |
'iou_t': (0, 0.1, 0.7), # IoU training threshold
|
474 |
'anchor_t': (1, 2.0, 8.0), # anchor-multiple threshold
|
475 |
-
|
476 |
'fl_gamma': (0, 0.0, 2.0), # focal loss gamma (efficientDet default gamma=1.5)
|
477 |
'hsv_h': (1, 0.0, 0.1), # image HSV-Hue augmentation (fraction)
|
478 |
'hsv_s': (1, 0.0, 0.9), # image HSV-Saturation augmentation (fraction)
|
@@ -493,7 +493,7 @@ if __name__ == '__main__':
|
|
493 |
if opt.bucket:
|
494 |
os.system('gsutil cp gs://%s/evolve.txt .' % opt.bucket) # download evolve.txt if exists
|
495 |
|
496 |
-
for _ in range(
|
497 |
if os.path.exists('evolve.txt'): # if evolve.txt exists: select best hyps and mutate
|
498 |
# Select parent(s)
|
499 |
parent = 'single' # parent selection method: 'single' or 'weighted'
|
|
|
68 |
with torch_distributed_zero_first(rank):
|
69 |
attempt_download(weights) # download if not found locally
|
70 |
ckpt = torch.load(weights, map_location=device) # load checkpoint
|
71 |
+
if 'anchors' in hyp and hyp['anchors']:
|
72 |
+
ckpt['model'].yaml['anchors'] = round(hyp['anchors']) # force autoanchor
|
73 |
model = Model(opt.cfg or ckpt['model'].yaml, ch=3, nc=nc).to(device) # create
|
74 |
exclude = ['anchor'] if opt.cfg else [] # exclude keys
|
75 |
state_dict = ckpt['model'].float().state_dict() # to FP32
|
|
|
472 |
'obj_pw': (1, 0.5, 2.0), # obj BCELoss positive_weight
|
473 |
'iou_t': (0, 0.1, 0.7), # IoU training threshold
|
474 |
'anchor_t': (1, 2.0, 8.0), # anchor-multiple threshold
|
475 |
+
'anchors': (1, 2.0, 10.0), # anchors per output grid (0 to ignore)
|
476 |
'fl_gamma': (0, 0.0, 2.0), # focal loss gamma (efficientDet default gamma=1.5)
|
477 |
'hsv_h': (1, 0.0, 0.1), # image HSV-Hue augmentation (fraction)
|
478 |
'hsv_s': (1, 0.0, 0.9), # image HSV-Saturation augmentation (fraction)
|
|
|
493 |
if opt.bucket:
|
494 |
os.system('gsutil cp gs://%s/evolve.txt .' % opt.bucket) # download evolve.txt if exists
|
495 |
|
496 |
+
for _ in range(1): # generations to evolve
|
497 |
if os.path.exists('evolve.txt'): # if evolve.txt exists: select best hyps and mutate
|
498 |
# Select parent(s)
|
499 |
parent = 'single' # parent selection method: 'single' or 'weighted'
|
utils/evolve.sh
CHANGED
@@ -4,11 +4,12 @@
|
|
4 |
|
5 |
# Start on 4-GPU machine
|
6 |
#for i in 0 1 2 3; do
|
7 |
-
# t=ultralytics/yolov5:
|
8 |
# sleep 60 # avoid simultaneous evolve.txt read/write
|
9 |
#done
|
10 |
|
11 |
# Hyperparameter evolution commands
|
12 |
while true; do
|
13 |
-
python train.py --batch 64 --weights yolov5m.pt --data voc.yaml --img 512 --epochs 50 --evolve --bucket ult/voc --device $1
|
|
|
14 |
done
|
|
|
4 |
|
5 |
# Start on 4-GPU machine
|
6 |
#for i in 0 1 2 3; do
|
7 |
+
# t=ultralytics/yolov5:evolve && sudo docker pull $t && sudo docker run -d --ipc=host --gpus all -v "$(pwd)"/VOC:/usr/src/VOC $t bash utils/evolve.sh $i
|
8 |
# sleep 60 # avoid simultaneous evolve.txt read/write
|
9 |
#done
|
10 |
|
11 |
# Hyperparameter evolution commands
|
12 |
while true; do
|
13 |
+
# python train.py --batch 64 --weights yolov5m.pt --data voc.yaml --img 512 --epochs 50 --evolve --bucket ult/evolve/voc --device $1
|
14 |
+
python train.py --batch 40 --weights yolov5m.pt --data coco.yaml --img 640 --epochs 30 --evolve --bucket ult/evolve/coco --device $1
|
15 |
done
|