data_time.update(time.time() - end)
input_var = torch.autograd.Variable(inputs.cuda())
target_var = torch.autograd.Variable(target.cuda(async=True))
// compute output
output = model(input_var)
score_map = output[-1].data.cpu()
loss = criterion(output[0], target_var)
for j in range(1, len(output)):
loss += criterion(output[j], target_var)
acc = accuracy(score_map, target, idx)
if debug: // visualize groundtruth and predictions
gt_batch_img = batch_with_heatmap(inputs, target)
pred_batch_img = batch_with_heatmap(inputs, score_map)
if not gt_win or not pred_win:
ax1 = plt.subplot(121)
ax1.title.set_text("Groundtruth")
gt_win = plt.imshow(gt_batch_img)
ax2 = plt.subplot(122)
ax2.title.set_text("Prediction")
pred_win = plt.imshow(pred_batch_img)
else:
gt_win.set_data(gt_batch_img)
pred_win.set_data(pred_batch_img)
plt.pause(.05)
plt.draw()
// measure accuracy and record loss
losses.update(loss.data[0], inputs.size(0))
acces.update(acc[0], inputs.size(0))
// compute gradient and do SGD step
After Change
if debug: // visualize groundtruth and predictions
gt_batch_img = batch_with_heatmap(input, target)
pred_batch_img = batch_with_heatmap(input, output[0])
if not gt_win or not pred_win:
ax1 = plt.subplot(121)
ax1.title.set_text("Groundtruth")