This commit is contained in:
Glenn Jocher 2019-04-16 12:49:34 +02:00
parent 54ebb2e593
commit b5ec9cb128
2 changed files with 23 additions and 14 deletions

View File

@ -50,9 +50,18 @@ git clone https://github.com/ultralytics/yolov3 # master
cp -r weights yolov3 cp -r weights yolov3
cp -r cocoapi/PythonAPI/pycocotools yolov3 cp -r cocoapi/PythonAPI/pycocotools yolov3
cd yolov3 cd yolov3
python3 test.py --save-json
git pull https://github.com/ultralytics/yolov3 mv ../utils.py utils
python3 train.py --data-cfg data/coco_1img.data
rm results*.txt # WARNING: removes existing results
python3 train.py --nosave --data data/coco_1img.data && mv results.txt resultsn_1img.txt
python3 train.py --nosave --data data/coco_10img.data && mv results.txt resultsn_10img.txt
python3 train.py --nosave --data data/coco_100img.data && mv results.txt resultsn_100img.txt
python3 train.py --nosave --data data/coco_100img.data --transfer && mv results.txt resultsn_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()"
gsutil cp results*.txt gs://ultralytics
gsutil cp results.png gs://ultralytics
sudo shutdown

View File

@ -243,9 +243,10 @@ def wh_iou(box1, box2):
def compute_loss(p, targets): # predictions, targets def compute_loss(p, targets): # predictions, targets
FT = torch.cuda.FloatTensor if p[0].is_cuda else torch.Tensor ft = torch.cuda.FloatTensor if p[0].is_cuda else torch.Tensor
lxy, lwh, lcls, lconf = FT([0]), FT([0]), FT([0]), FT([0]) lxy, lwh, lcls, lconf = ft([0]), ft([0]), ft([0]), ft([0])
txy, twh, tcls, indices = targets txy, twh, tcls, indices = targets
bs = p[0].shape[0] # batch size
MSE = nn.MSELoss() MSE = nn.MSELoss()
CE = nn.CrossEntropyLoss() CE = nn.CrossEntropyLoss()
BCE = nn.BCEWithLogitsLoss() BCE = nn.BCEWithLogitsLoss()
@ -255,22 +256,21 @@ def compute_loss(p, targets): # predictions, targets
for i, pi0 in enumerate(p): # layer i predictions, i for i, pi0 in enumerate(p): # layer i predictions, i
b, a, gj, gi = indices[i] # image, anchor, gridx, gridy b, a, gj, gi = indices[i] # image, anchor, gridx, gridy
tconf = torch.zeros_like(pi0[..., 0]) # conf tconf = torch.zeros_like(pi0[..., 0]) # conf
nt = len(b) # number of targets
# Compute losses # Compute losses
k = 1 # nt / bs k = 8.4875 * bs
if nt: if len(b): # number of targets
pi = pi0[b, a, gj, gi] # predictions closest to anchors pi = pi0[b, a, gj, gi] # predictions closest to anchors
tconf[b, a, gj, gi] = 1 # conf tconf[b, a, gj, gi] = 1 # conf
lxy += (k * 8) * MSE(torch.sigmoid(pi[..., 0:2]), txy[i]) # xy loss lxy += (k * 0.07934) * MSE(torch.sigmoid(pi[..., 0:2]), txy[i]) # xy loss
lwh += (k * 1) * MSE(pi[..., 2:4], twh[i]) # wh yolo loss lwh += (k * 0.01561) * MSE(pi[..., 2:4], twh[i]) # wh yolo loss
# lwh += (k * 1) * MSE(torch.sigmoid(pi[..., 2:4]), twh[i]) # wh power loss # lwh += (k * 0.01561) * MSE(torch.sigmoid(pi[..., 2:4]), twh[i]) # wh power loss
lcls += (k * 1) * CE(pi[..., 5:], tcls[i]) # class_conf loss lcls += (k * 0.02094) * CE(pi[..., 5:], tcls[i]) # class_conf loss
# pos_weight = FT([gp[i] / min(gp) * 4.]) # pos_weight = ft([gp[i] / min(gp) * 4.])
# BCE = nn.BCEWithLogitsLoss(pos_weight=pos_weight) # BCE = nn.BCEWithLogitsLoss(pos_weight=pos_weight)
lconf += (k * 64) * BCE(pi0[..., 4], tconf) # obj_conf loss lconf += (k * 0.8841) * BCE(pi0[..., 4], tconf) # obj_conf loss
loss = lxy + lwh + lconf + lcls loss = lxy + lwh + lconf + lcls
return loss, torch.cat((lxy, lwh, lconf, lcls, loss)).detach() return loss, torch.cat((lxy, lwh, lconf, lcls, loss)).detach()