use nerf render imgs instead of use real imgs
(args, model, sample_size, device, targets, rgbs, poses, batch_size=1)
| 131 | # vis_pose(vis_info) |
| 132 | |
| 133 | def get_render_error_in_q(args, model, sample_size, device, targets, rgbs, poses, batch_size=1): |
| 134 | ''' use nerf render imgs instead of use real imgs ''' |
| 135 | model.eval() |
| 136 | |
| 137 | results = np.zeros((sample_size, 2)) |
| 138 | print("to be implement...") |
| 139 | |
| 140 | predict_pose_list = [] |
| 141 | gt_pose_list = [] |
| 142 | ang_error_list = [] |
| 143 | |
| 144 | for i in range(sample_size): |
| 145 | data = rgbs[i:i+1].permute(0,3,1,2) |
| 146 | pose = poses[i:i+1].reshape(batch_size, 12) |
| 147 | |
| 148 | data = data.to(device) # input |
| 149 | pose = pose.reshape((batch_size,3,4)).numpy() # label |
| 150 | |
| 151 | # using SVD to make sure predict rotation is normalized rotation matrix |
| 152 | with torch.no_grad(): |
| 153 | _, predict_pose = model(data) |
| 154 | R_torch = predict_pose.reshape((batch_size, 3, 4))[:,:3,:3] # debug |
| 155 | predict_pose = predict_pose.reshape((batch_size, 3, 4)).cpu().numpy() |
| 156 | |
| 157 | R = predict_pose[:,:3,:3] |
| 158 | res = R@np.linalg.inv(R) |
| 159 | # print('R@np.linalg.inv(R):', res) |
| 160 | |
| 161 | u,s,v=torch.svd(R_torch) |
| 162 | Rs = torch.matmul(u, v.transpose(-2,-1)) |
| 163 | predict_pose[:,:3,:3] = Rs[:,:3,:3].cpu().numpy() |
| 164 | |
| 165 | pose_q = transforms.matrix_to_quaternion(torch.Tensor(pose[:,:3,:3]))#.cpu().numpy() # gnd truth in quaternion |
| 166 | pose_x = pose[:, :3, 3] # gnd truth position |
| 167 | predicted_q = transforms.matrix_to_quaternion(torch.Tensor(predict_pose[:,:3,:3]))#.cpu().numpy() # predict in quaternion |
| 168 | predicted_x = predict_pose[:, :3, 3] # predict position |
| 169 | pose_q = pose_q.squeeze() |
| 170 | pose_x = pose_x.squeeze() |
| 171 | predicted_q = predicted_q.squeeze() |
| 172 | predicted_x = predicted_x.squeeze() |
| 173 | |
| 174 | #Compute Individual Sample Error |
| 175 | q1 = pose_q / torch.linalg.norm(pose_q) |
| 176 | q2 = predicted_q / torch.linalg.norm(predicted_q) |
| 177 | d = torch.abs(torch.sum(torch.matmul(q1,q2))) |
| 178 | d = torch.clamp(d, -1., 1.) # acos can only input [-1~1] |
| 179 | theta = (2 * torch.acos(d) * 180/math.pi).numpy() |
| 180 | error_x = torch.linalg.norm(torch.Tensor(pose_x-predicted_x)).numpy() |
| 181 | results[i,:] = [error_x, theta] |
| 182 | #print ('Iteration: {} Error XYZ (m): {} Error Q (degrees): {}'.format(i, error_x, theta)) |
| 183 | |
| 184 | # save results for visualization |
| 185 | predict_pose_list.append(predicted_x) |
| 186 | gt_pose_list.append(pose_x) |
| 187 | ang_error_list.append(theta) |
| 188 | |
| 189 | predict_pose_list = np.array(predict_pose_list) |
| 190 | gt_pose_list = np.array(gt_pose_list) |
nothing calls this directly
no outgoing calls
no test coverage detected