| | |
| | | # Test the Model |
| | | model.eval() # Change model to 'eval' mode (BN uses moving mean/var). |
| | | total = 0 |
| | | n_margins = 20 |
| | | yaw_correct = np.zeros(n_margins) |
| | | pitch_correct = np.zeros(n_margins) |
| | | roll_correct = np.zeros(n_margins) |
| | | |
| | | 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 |
| | | |
| | | l1loss = torch.nn.L1Loss(size_average=False) |
| | | |
| | | for i, (images, labels, name) in enumerate(test_loader): |
| | | for i, (images, labels, cont_labels, name) in enumerate(test_loader): |
| | | images = Variable(images).cuda(gpu) |
| | | total += labels.size(0) |
| | | label_yaw = labels[:,0].float() |
| | | label_pitch = labels[:,1].float() |
| | | label_roll = labels[:,2].float() |
| | | total += cont_labels.size(0) |
| | | label_yaw = cont_labels[:,0].float() |
| | | label_pitch = cont_labels[:,1].float() |
| | | label_roll = cont_labels[:,2].float() |
| | | |
| | | pre_yaw, pre_pitch, pre_roll, angles = model(images) |
| | | yaw = angles[-1][:,0].cpu().data |
| | | pitch = angles[-1][:,1].cpu().data |
| | | roll = angles[-1][:,2].cpu().data |
| | | yaw = angles[0][:,0].cpu().data * 3 - 99 |
| | | pitch = angles[0][:,1].cpu().data * 3 - 99 |
| | | roll = angles[0][:,2].cpu().data * 3 - 99 |
| | | |
| | | for idx in xrange(1,args.iter_ref+1): |
| | | yaw += angles[idx][:,0].cpu().data |
| | | pitch += angles[idx][:,1].cpu().data |
| | | roll += angles[idx][:,2].cpu().data |
| | | |
| | | # Mean absolute error |
| | | yaw_error += torch.sum(torch.abs(yaw - label_yaw) * 3) |
| | | pitch_error += torch.sum(torch.abs(pitch - label_pitch) * 3) |
| | | roll_error += torch.sum(torch.abs(roll - label_roll) * 3) |
| | | yaw_error += torch.sum(torch.abs(yaw - label_yaw)) |
| | | pitch_error += torch.sum(torch.abs(pitch - label_pitch)) |
| | | roll_error += torch.sum(torch.abs(roll - label_roll)) |
| | | |
| | | # Save images with pose cube. |
| | | # TODO: fix for larger batch size |
| | | if args.save_viz: |
| | | name = name[0] |
| | | cv2_img = cv2.imread(os.path.join(args.data_dir, name + '.jpg')) |
| | | if args.dataset == 'BIWI': |
| | | cv2_img = cv2.imread(os.path.join(args.data_dir, name + '_rgb.png')) |
| | | else: |
| | | cv2_img = cv2.imread(os.path.join(args.data_dir, name + '.jpg')) |
| | | |
| | | if args.batch_size == 1: |
| | | error_string = 'y %.4f, p %.4f, r %.4f' % (torch.sum(torch.abs(yaw - label_yaw) * 3), torch.sum(torch.abs(pitch - label_pitch) * 3), torch.sum(torch.abs(roll - label_roll) * 3)) |
| | | cv2_img = cv2.putText(cv2_img, error_string, (30, cv2_img.shape[0]- 30), fontFace=1, fontScale=2, color=(0,255,0), thickness=2) |
| | | utils.plot_pose_cube(cv2_img, yaw[0] * 3 - 99, pitch[0] * 3 - 99, roll[0] * 3 - 99) |
| | | cv2.imwrite(os.path.join('output/images', name + '.jpg'), cv2_img) |
| | | |