This commit is contained in:
Glenn Jocher
2019-04-17 15:52:51 +02:00
parent 9c5524ba82
commit 0b8a28e3dd
4 changed files with 52 additions and 32 deletions
+8 -3
View File
@@ -50,14 +50,19 @@ git clone https://github.com/ultralytics/yolov3 # master
cp -r weights yolov3
cp -r cocoapi/PythonAPI/pycocotools yolov3
cd yolov3
python3 train.py --nosave --data data/coco_100val.data
python3 train.py --nosave --data data/coco_32img.data --var 4 && mv results.txt results_t2.txt
python3 train.py --nosave --data data/coco_32img.data --var 5 && mv results.txt results_t3.txt
python3 -c "from utils import utils; utils.plot_results()"
gsutil cp results*.txt gs://ultralytics
gsutil cp results.png gs://ultralytics
sudo shutdown
#mv ../utils.py utils
mv ../train.py .
rm results*.txt # WARNING: removes existing results
python3 train.py --nosave --data data/coco_1img.data && mv results.txt results3_1img.txt
python3 train.py --nosave --data data/coco_10img.data && mv results.txt results3_10img.txt
python3 train.py --nosave --data data/coco_100img.data && mv results.txt results3_100img.txt
python3 train.py --nosave --data data/coco_100img.data && mv results.txt results4_100img.txt
python3 train.py --nosave --data data/coco_100img.data --transfer && mv results.txt results3_100imgTL.txt
# python3 train.py --nosave --data data/coco_1000img.data && mv results.txt results_1000img.txt
python3 -c "from utils import utils; utils.plot_results()"
+12 -10
View File
@@ -242,35 +242,37 @@ def wh_iou(box1, box2):
return inter_area / union_area # iou
def compute_loss(p, targets): # predictions, targets
def compute_loss(p, targets, model): # predictions, targets, model
ft = torch.cuda.FloatTensor if p[0].is_cuda else torch.Tensor
lxy, lwh, lcls, lconf = ft([0]), ft([0]), ft([0]), ft([0])
txy, twh, tcls, indices = targets
txy, twh, tcls, indices = build_targets(model, targets)
# Define criteria
MSE = nn.MSELoss()
CE = nn.CrossEntropyLoss()
BCE = nn.BCEWithLogitsLoss()
# Compute losses
h = model.hyp # hyperparameters
bs = p[0].shape[0] # batch size
# gp = [x.numel() for x in tconf] # grid points
k = h['k'] * bs # loss gain
for i, pi0 in enumerate(p): # layer i predictions, i
b, a, gj, gi = indices[i] # image, anchor, gridx, gridy
tconf = torch.zeros_like(pi0[..., 0]) # conf
# Compute losses
k = 8.4875 * bs
if len(b): # number of targets
pi = pi0[b, a, gj, gi] # predictions closest to anchors
tconf[b, a, gj, gi] = 1 # conf
# pi[..., 2:4] = torch.sigmoid(pi[..., 2:4]) # wh power loss (uncomment)
lxy += (k * 0.079756) * MSE(torch.sigmoid(pi[..., 0:2]), txy[i]) # xy loss
lwh += (k * 0.010461) * MSE(pi[..., 2:4], twh[i]) # wh yolo loss
# lwh += (k * 0.010461) * MSE(torch.sigmoid(pi[..., 2:4]), twh[i]) # wh power loss
lcls += (k * 0.02105) * CE(pi[..., 5:], tcls[i]) # class_conf loss
lxy += (k * h['xy']) * MSE(torch.sigmoid(pi[..., 0:2]), txy[i]) # xy loss
lwh += (k * h['wh']) * MSE(pi[..., 2:4], twh[i]) # wh yolo loss
lcls += (k * h['cls']) * CE(pi[..., 5:], tcls[i]) # class_conf loss
# pos_weight = ft([gp[i] / min(gp) * 4.])
# BCE = nn.BCEWithLogitsLoss(pos_weight=pos_weight)
lconf += (k * 0.88873) * BCE(pi0[..., 4], tconf) # obj_conf loss
lconf += (k * h['conf']) * BCE(pi0[..., 4], tconf) # obj_conf loss
loss = lxy + lwh + lconf + lcls
return loss, torch.cat((lxy, lwh, lconf, lcls, loss)).detach()
@@ -296,7 +298,7 @@ def build_targets(model, targets):
# reject below threshold ious (OPTIONAL, increases P, lowers R)
reject = True
if reject:
j = iou > 0.10
j = iou > model.hyp['iou_t'] # hyperparameter
t, a, gwh = targets[j], a[j], gwh[j]
# Indices