def evaluate(args, loader, generator, num_samples): ade_outer, fde_outer = [], [] total_traj = 0 with torch.no_grad(): for batch in loader: batch = [tensor.cuda() for tensor in batch] (obs_traj, pred_traj_gt, obs_traj_rel, pred_traj_gt_rel, non_linear_ped, loss_mask, seq_start_end) = batch ade, fde = [], [] total_traj += pred_traj_gt.size(1) for _ in range(num_samples): pred_traj_fake_rel = generator( obs_traj, obs_traj_rel, seq_start_end ) pred_traj_fake = relative_to_abs( pred_traj_fake_rel, obs_traj[-1] ) ade.append(displacement_error( pred_traj_fake, pred_traj_gt, mode='raw' )) fde.append(final_displacement_error( pred_traj_fake[-1], pred_traj_gt[-1], mode='raw' )) ade_sum = evaluate_helper(ade, seq_start_end) fde_sum = evaluate_helper(fde, seq_start_end) ade_outer.append(ade_sum) fde_outer.append(fde_sum) ade = sum(ade_outer) / (total_traj * args.pred_len) fde = sum(fde_outer) / (total_traj) return ade, fde
def evaluate(args, loader, generator, num_samples): ade_outer, fde_outer = [], [] total_traj = 0 trajs = [] with torch.no_grad(): for batch in loader: # batch = [tensor.cuda() for tensor in batch] (obs_traj, pred_traj_gt, obs_traj_rel, pred_traj_gt_rel, non_linear_ped, loss_mask, seq_start_end) = batch obs_traj = obs_traj.float() obs_traj_rel = obs_traj_rel.float() pred_traj_gt = pred_traj_gt.double() ade, fde = [], [] total_traj += pred_traj_gt.size(1) for _ in range(num_samples): pred_traj_fake_rel = generator(obs_traj, obs_traj_rel, seq_start_end) pred_traj_fake = relative_to_abs(pred_traj_fake_rel, obs_traj[-1]) pred_traj_fake = pred_traj_fake.double() trajs.append([ obs_traj.cpu().numpy(), pred_traj_fake.cpu().numpy(), pred_traj_gt.cpu().numpy(), seq_start_end.cpu().numpy() ]) ade_traj = displacement_error(pred_traj_fake, pred_traj_gt, mode='sum') fde_traj = final_displacement_error(pred_traj_fake[-1], pred_traj_gt[-1], mode='sum') # ade.append(displacement_error( # pred_traj_fake, pred_traj_gt, mode='sum' # )) # fde.append(final_displacement_error( # pred_traj_fake[-1], pred_traj_gt[-1], mode='sum' # )) # ade_sum = evaluate_helper(ade, seq_start_end) # fde_sum = evaluate_helper(fde, seq_start_end) # ade_outer.append(ade_sum) # fde_outer.append(fde_sum) ade_outer.append(ade_traj) fde_outer.append(fde_traj) ade = sum(ade_outer) / (total_traj * args.pred_len) fde = sum(fde_outer) / (total_traj) return ade, fde, trajs
def cal_ade(pred_traj_gt, pred_traj_fake, linear_ped, non_linear_ped): ade = displacement_error(pred_traj_fake, pred_traj_gt) ade_l = displacement_error(pred_traj_fake, pred_traj_gt, linear_ped) ade_nl = displacement_error(pred_traj_fake, pred_traj_gt, non_linear_ped) return ade, ade_l, ade_nl
def cal_ade(pred_traj_gt, pred_traj_fake): ade = displacement_error(pred_traj_fake, pred_traj_gt) return ade