natanielruiz
2017-10-30 4b67b5c8ed5566ec3030d537536282e830d87e40
code/test_preangles.py
@@ -36,13 +36,6 @@
    return args
def load_filtered_state_dict(model, snapshot):
    # By user apaszke from discuss.pytorch.org
    model_dict = model.state_dict()
    snapshot = {k: v for k, v in snapshot.items() if k in model_dict}
    model_dict.update(snapshot)
    model.load_state_dict(model_dict)
if __name__ == '__main__':
    args = parse_args()
@@ -57,7 +50,6 @@
    # Load snapshot
    saved_state_dict = torch.load(snapshot_path)
    model.load_state_dict(saved_state_dict)
    # load_filtered_state_dict(model, saved_state_dict)
    print 'Loading data.'
@@ -96,6 +88,9 @@
    model.eval()  # Change model to 'eval' mode (BN uses moving mean/var).
    total = 0
    idx_tensor = [idx for idx in xrange(66)]
    idx_tensor = torch.FloatTensor(idx_tensor).cuda(gpu)
    yaw_error = .0
    pitch_error = .0
    roll_error = .0
@@ -110,7 +105,7 @@
        label_pitch = cont_labels[:,1].float()
        label_roll = cont_labels[:,2].float()
        yaw, pitch, roll, angles = model(images)
        yaw, pitch, roll = model(images)
        # Binned predictions
        _, yaw_bpred = torch.max(yaw.data, 1)
@@ -118,9 +113,13 @@
        _, roll_bpred = torch.max(roll.data, 1)
        # Continuous predictions
        yaw_predicted = angles[:,0].data.cpu()
        pitch_predicted = angles[:,1].data.cpu()
        roll_predicted = angles[:,2].data.cpu()
        yaw_predicted = utils.softmax_temperature(yaw.data, 1)
        pitch_predicted = utils.softmax_temperature(pitch.data, 1)
        roll_predicted = utils.softmax_temperature(roll.data, 1)
        yaw_predicted = torch.sum(yaw_predicted * idx_tensor, 1).cpu() * 3 - 99
        pitch_predicted = torch.sum(pitch_predicted * idx_tensor, 1).cpu() * 3 - 99
        roll_predicted = torch.sum(roll_predicted * idx_tensor, 1).cpu() * 3 - 99
        # Mean absolute error
        yaw_error += torch.sum(torch.abs(yaw_predicted - label_yaw))