updates
This commit is contained in:
parent
809667404f
commit
db515a4535
|
@ -172,7 +172,7 @@ class YOLOLayer(nn.Module):
|
||||||
lh = k * MSELoss(h[mask], th[mask])
|
lh = k * MSELoss(h[mask], th[mask])
|
||||||
|
|
||||||
# lconf = k * BCEWithLogitsLoss(pred_conf[mask], mask[mask].float())
|
# 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) * CrossEntropyLoss(pred_cls[mask], torch.argmax(tcls, 1))
|
||||||
# lcls = (k * 10) * BCEWithLogitsLoss(pred_cls[mask], tcls.float())
|
# lcls = (k * 10) * BCEWithLogitsLoss(pred_cls[mask], tcls.float())
|
||||||
|
|
31
train.py
31
train.py
|
@ -125,7 +125,8 @@ def main(opt):
|
||||||
g['lr'] = lr
|
g['lr'] = lr
|
||||||
|
|
||||||
# Compute loss, compute gradient, update parameters
|
# 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()
|
loss.backward()
|
||||||
|
|
||||||
# accumulated_batches = 1 # accumulate gradient for 4 batches before stepping optimizer
|
# accumulated_batches = 1 # accumulate gradient for 4 batches before stepping optimizer
|
||||||
|
@ -133,24 +134,26 @@ def main(opt):
|
||||||
optimizer.step()
|
optimizer.step()
|
||||||
optimizer.zero_grad()
|
optimizer.zero_grad()
|
||||||
|
|
||||||
# Compute running epoch-means of tracked metrics
|
# Running epoch-means of tracked metrics
|
||||||
ui += 1
|
ui += 1
|
||||||
metrics += model.losses['metrics']
|
|
||||||
TP, FP, FN = metrics
|
|
||||||
for key, val in model.losses.items():
|
for key, val in model.losses.items():
|
||||||
rloss[key] = (rloss[key] * ui + val) / (ui + 1)
|
rloss[key] = (rloss[key] * ui + val) / (ui + 1)
|
||||||
|
|
||||||
# Precision
|
if precision_per_batch:
|
||||||
precision = TP / (TP + FP)
|
TP, FP, FN = metrics
|
||||||
k = (TP + FP) > 0
|
metrics += model.losses['metrics']
|
||||||
if k.sum() > 0:
|
|
||||||
mean_precision = precision[k].mean()
|
|
||||||
|
|
||||||
# Recall
|
# Precision
|
||||||
recall = TP / (TP + FN)
|
precision = TP / (TP + FP)
|
||||||
k = (TP + FN) > 0
|
k = (TP + FP) > 0
|
||||||
if k.sum() > 0:
|
if k.sum() > 0:
|
||||||
mean_recall = recall[k].mean()
|
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) % (
|
s = ('%11s%11s' + '%11.3g' * 14) % (
|
||||||
'%g/%g' % (epoch, opt.epochs - 1), '%g/%g' % (i, len(dataloader) - 1), rloss['x'],
|
'%g/%g' % (epoch, opt.epochs - 1), '%g/%g' % (i, len(dataloader) - 1), rloss['x'],
|
||||||
|
|
|
@ -438,7 +438,7 @@ def plot_results():
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
plt.figure(figsize=(16, 8))
|
plt.figure(figsize=(16, 8))
|
||||||
s = ['X', 'Y', 'Width', 'Height', 'Objectness', 'Classification', 'Total Loss', 'Precision', 'Recall', 'mAP']
|
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
|
results = np.loadtxt(f, usecols=[2, 3, 4, 5, 6, 7, 8, 9, 10]).T # column 16 is mAP
|
||||||
for i in range(9):
|
for i in range(9):
|
||||||
|
|
Loading…
Reference in New Issue