This commit is contained in:
Glenn Jocher 2018-11-22 14:14:19 +01:00
parent 809667404f
commit db515a4535
3 changed files with 19 additions and 16 deletions

View File

@ -172,7 +172,7 @@ class YOLOLayer(nn.Module):
lh = k * MSELoss(h[mask], th[mask])
# lconf = k * BCEWithLogitsLoss(pred_conf[mask], mask[mask].float())
lconf = (k * 1) * BCEWithLogitsLoss(pred_conf, mask.float())
lconf = (k * 5) * BCEWithLogitsLoss(pred_conf, mask.float())
lcls = (k / 10) * CrossEntropyLoss(pred_cls[mask], torch.argmax(tcls, 1))
# lcls = (k * 10) * BCEWithLogitsLoss(pred_cls[mask], tcls.float())

View File

@ -125,7 +125,8 @@ def main(opt):
g['lr'] = lr
# Compute loss, compute gradient, update parameters
loss = model(imgs.to(device), targets, requestPrecision=False)
precision_per_batch = False
loss = model(imgs.to(device), targets, requestPrecision=precision_per_batch)
loss.backward()
# accumulated_batches = 1 # accumulate gradient for 4 batches before stepping optimizer
@ -133,24 +134,26 @@ def main(opt):
optimizer.step()
optimizer.zero_grad()
# Compute running epoch-means of tracked metrics
# Running epoch-means of tracked metrics
ui += 1
metrics += model.losses['metrics']
TP, FP, FN = metrics
for key, val in model.losses.items():
rloss[key] = (rloss[key] * ui + val) / (ui + 1)
# Precision
precision = TP / (TP + FP)
k = (TP + FP) > 0
if k.sum() > 0:
mean_precision = precision[k].mean()
if precision_per_batch:
TP, FP, FN = metrics
metrics += model.losses['metrics']
# Recall
recall = TP / (TP + FN)
k = (TP + FN) > 0
if k.sum() > 0:
mean_recall = recall[k].mean()
# Precision
precision = TP / (TP + FP)
k = (TP + FP) > 0
if k.sum() > 0:
mean_precision = precision[k].mean()
# Recall
recall = TP / (TP + FN)
k = (TP + FN) > 0
if k.sum() > 0:
mean_recall = recall[k].mean()
s = ('%11s%11s' + '%11.3g' * 14) % (
'%g/%g' % (epoch, opt.epochs - 1), '%g/%g' % (i, len(dataloader) - 1), rloss['x'],

View File

@ -438,7 +438,7 @@ def plot_results():
import matplotlib.pyplot as plt
plt.figure(figsize=(16, 8))
s = ['X', 'Y', 'Width', 'Height', 'Objectness', 'Classification', 'Total Loss', 'Precision', 'Recall', 'mAP']
for f in ('results5.txt', 'results_new.txt', 'results3.txt',
for f in ('results_d5.txt', 'results_d10.txt', 'results_new.txt',
):
results = np.loadtxt(f, usecols=[2, 3, 4, 5, 6, 7, 8, 9, 10]).T # column 16 is mAP
for i in range(9):