From fe3e5ec092d991f7e3431eab5f55756613be5564 Mon Sep 17 00:00:00 2001 From: godspeed5 <36200106+godspeed5@users.noreply.github.com> Date: Sun, 31 Oct 2021 14:06:07 +0530 Subject: [PATCH 1/7] Update image_utils.py Added function to visualize results. Tested on inD, but should work in general --- ynet/utils/image_utils.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ynet/utils/image_utils.py b/ynet/utils/image_utils.py index 6b28efd..f764d37 100644 --- a/ynet/utils/image_utils.py +++ b/ynet/utils/image_utils.py @@ -126,3 +126,13 @@ def image2world(image_coords, scene, homo_mat, resize): traj_image2world = traj_image2world[:, :2] traj_image2world = traj_image2world.view_as(image_coords) return traj_image2world + +def plot_results(gt_future, future_samples, observed, scene_image, im, resize): + plt.scatter(gt_future.cpu()[1,:,0]/resize, gt_future.cpu()[1,:,1]/resize) + plt.scatter(future_samples.cpu()[:,1,:,0]/resize, future_samples.cpu()[:,1,:,1]/resize, alpha=0.1) + plt.scatter(observed[5:10,0]/resize, observed[5:10,1]/resize) + scene_image_rescaled = rescale(scene_image.cpu().squeeze()[1].squeeze(), 1/resize) + plt.imshow(scene_image_rescaled) + plt.imshow(im, alpha=0.5) + plt.show() + From ac8de1899a3e5c44e9bc45559715e522dd0c644b Mon Sep 17 00:00:00 2001 From: godspeed5 <36200106+godspeed5@users.noreply.github.com> Date: Sun, 31 Oct 2021 14:06:30 +0530 Subject: [PATCH 2/7] Update image_utils.py --- ynet/utils/image_utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ynet/utils/image_utils.py b/ynet/utils/image_utils.py index f764d37..d408359 100644 --- a/ynet/utils/image_utils.py +++ b/ynet/utils/image_utils.py @@ -2,6 +2,8 @@ import torch import cv2 import torch.nn.functional as F +import skimage.io +from skimage.transform import rescale, resize, downscale_local_mean def gkern(kernlen=31, nsig=4): """ creates gaussian kernel with side length l and a sigma of sig """ From c5d0e5f986ef0f60eeeba9b8ed85e3a11f21b6cb Mon Sep 17 00:00:00 2001 From: godspeed5 <36200106+godspeed5@users.noreply.github.com> Date: Sun, 31 Oct 2021 14:09:30 +0530 Subject: [PATCH 3/7] Update test.py --- ynet/test.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ynet/test.py b/ynet/test.py index 17c0c57..5b465fe 100644 --- a/ynet/test.py +++ b/ynet/test.py @@ -1,8 +1,8 @@ import torch import torch.nn as nn -from utils.image_utils import get_patch, sampling, image2world +from utils.image_utils import get_patch, sampling, image2world, plot_results from utils.kmeans import kmeans - +import skimage.io def torch_multivariate_gaussian_heatmap(coordinates, H, W, dist, sigma_factor, ratio, device, rot=False): """ @@ -215,5 +215,7 @@ def evaluate(model, val_loader, val_images, num_goals, num_traj, obs_len, batch_ val_ADE = torch.cat(val_ADE).mean() val_FDE = torch.cat(val_FDE).mean() + + plot_results(gt_future, future_samples, observed, scene_image, im, resize) return val_ADE.item(), val_FDE.item() From 8c33a2467047c987959a3cad3d756dfafff2451a Mon Sep 17 00:00:00 2001 From: godspeed5 <36200106+godspeed5@users.noreply.github.com> Date: Sun, 31 Oct 2021 14:49:32 +0530 Subject: [PATCH 4/7] Update image_utils.py added legend --- ynet/utils/image_utils.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ynet/utils/image_utils.py b/ynet/utils/image_utils.py index d408359..07b98a8 100644 --- a/ynet/utils/image_utils.py +++ b/ynet/utils/image_utils.py @@ -130,11 +130,12 @@ def image2world(image_coords, scene, homo_mat, resize): return traj_image2world def plot_results(gt_future, future_samples, observed, scene_image, im, resize): - plt.scatter(gt_future.cpu()[1,:,0]/resize, gt_future.cpu()[1,:,1]/resize) - plt.scatter(future_samples.cpu()[:,1,:,0]/resize, future_samples.cpu()[:,1,:,1]/resize, alpha=0.1) - plt.scatter(observed[5:10,0]/resize, observed[5:10,1]/resize) + plt.scatter(gt_future.cpu()[1,:,0]/resize, gt_future.cpu()[1,:,1]/resize, label='ground truth') + plt.scatter(future_samples.cpu()[:,1,:,0]/resize, future_samples.cpu()[:,1,:,1]/resize, label='predictions', alpha=0.1) + plt.scatter(observed[5:10,0]/resize, observed[5:10,1]/resize, label='observed_past') scene_image_rescaled = rescale(scene_image.cpu().squeeze()[1].squeeze(), 1/resize) plt.imshow(scene_image_rescaled) - plt.imshow(im, alpha=0.5) + plt.imshow(im, alpha=0.5) + plt.legend() plt.show() From 715590f8b2d6e411e6d2eee1f756fef13a68c3d5 Mon Sep 17 00:00:00 2001 From: godspeed5 <36200106+godspeed5@users.noreply.github.com> Date: Sun, 21 Nov 2021 20:07:32 +0100 Subject: [PATCH 5/7] Update image_utils.py Added feature to optionally save path and display background --- ynet/utils/image_utils.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/ynet/utils/image_utils.py b/ynet/utils/image_utils.py index 07b98a8..6660b3f 100644 --- a/ynet/utils/image_utils.py +++ b/ynet/utils/image_utils.py @@ -2,6 +2,7 @@ import torch import cv2 import torch.nn.functional as F +import matplotlib.pyplot as plt import skimage.io from skimage.transform import rescale, resize, downscale_local_mean @@ -129,13 +130,19 @@ def image2world(image_coords, scene, homo_mat, resize): traj_image2world = traj_image2world.view_as(image_coords) return traj_image2world -def plot_results(gt_future, future_samples, observed, scene_image, im, resize): - plt.scatter(gt_future.cpu()[1,:,0]/resize, gt_future.cpu()[1,:,1]/resize, label='ground truth') - plt.scatter(future_samples.cpu()[:,1,:,0]/resize, future_samples.cpu()[:,1,:,1]/resize, label='predictions', alpha=0.1) - plt.scatter(observed[5:10,0]/resize, observed[5:10,1]/resize, label='observed_past') +def plot_results(gt_future, future_samples, observed, scene_image, im, resize, with_bg=True, save_path=None): + plt.scatter(gt_future.cpu()[1,:,0]/resize, gt_future.cpu()[1,:,1]/resize, label='ground truth', zorder=3) + plt.scatter(future_samples.cpu()[:,1,:,0]/resize, future_samples.cpu()[:,1,:,1]/resize, label='predictions', alpha=0.1, zorder=2) + plt.scatter(observed[5:10,0]/resize, observed[5:10,1]/resize, label='observed_past', color='cyan', zorder=1) scene_image_rescaled = rescale(scene_image.cpu().squeeze()[1].squeeze(), 1/resize) - plt.imshow(scene_image_rescaled) - plt.imshow(im, alpha=0.5) + im_rescaled = rescale(im.cpu().squeeze()[1].squeeze(), 1/resize) + plt.imshow(scene_image_rescaled, alpha=0.001) + if with_bg: + plt.imshow(scene_image_rescaled) + plt.imshow(im_rescaled, alpha=0.7) plt.legend() + + if save_path is not None: + plt.savefig(save_path) plt.show() From 15400aaa86c7eda43cc91d93487592b11e52771c Mon Sep 17 00:00:00 2001 From: godspeed5 <36200106+godspeed5@users.noreply.github.com> Date: Sun, 21 Nov 2021 20:09:32 +0100 Subject: [PATCH 6/7] Update test.py --- ynet/test.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ynet/test.py b/ynet/test.py index 5b465fe..427c206 100644 --- a/ynet/test.py +++ b/ynet/test.py @@ -4,6 +4,7 @@ from utils.kmeans import kmeans import skimage.io + def torch_multivariate_gaussian_heatmap(coordinates, H, W, dist, sigma_factor, ratio, device, rot=False): """ Create Gaussian Kernel for CWS @@ -55,7 +56,7 @@ def evaluate(model, val_loader, val_images, num_goals, num_traj, obs_len, batch_ :param mode: ['val', 'test'] :return: val_ADE, val_FDE for one epoch """ - + im = skimage.io.imread('data/inD/test/scene1/reference.png') model.eval() val_ADE = [] val_FDE = [] @@ -212,10 +213,14 @@ def evaluate(model, val_loader, val_images, num_goals, num_traj, obs_len, batch_ val_FDE.append(((((gt_goal - waypoint_samples[:, :, -1:]) / resize) ** 2).sum(dim=3) ** 0.5).min(dim=0)[0]) val_ADE.append(((((gt_future - future_samples) / resize) ** 2).sum(dim=3) ** 0.5).mean(dim=2).min(dim=0)[0]) + + plot_results(gt_future, future_samples, observed, scene_image, val_images[scene], resize, with_bg=False) +# plot_results(gt_future, future_samples, observed, scene_image, val_images[scene], resize, with_bg=True, save_path='viz/'+str(scene)+'_'+str(counter)+'.png') + counter+=1 + + # plt.savefig() val_ADE = torch.cat(val_ADE).mean() val_FDE = torch.cat(val_FDE).mean() - - plot_results(gt_future, future_samples, observed, scene_image, im, resize) return val_ADE.item(), val_FDE.item() From e9abcc6ba608286ac72f97a9fdce46f7a9132fd3 Mon Sep 17 00:00:00 2001 From: ni701311 Date: Tue, 30 Nov 2021 00:09:48 +0100 Subject: [PATCH 7/7] added python file for evaluation of inD on YNet --- ynet/evaluate_inD_longterm.py | 111 ++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 ynet/evaluate_inD_longterm.py diff --git a/ynet/evaluate_inD_longterm.py b/ynet/evaluate_inD_longterm.py new file mode 100644 index 0000000..510d784 --- /dev/null +++ b/ynet/evaluate_inD_longterm.py @@ -0,0 +1,111 @@ +#!/usr/bin/env python +# coding: utf-8 + +# In[2]: + + +import pandas as pd +import yaml +import argparse +import torch +from model import YNet + + +# In[3]: + + +get_ipython().run_line_magic('load_ext', 'autoreload') +get_ipython().run_line_magic('autoreload', '2') + + +# #### Some hyperparameters and settings + +# In[4]: + + +CONFIG_FILE_PATH = 'config/inD_longterm.yaml' # yaml config file containing all the hyperparameters +DATASET_NAME = 'ind' + +TEST_DATA_PATH = 'data/inD/test.pkl' +TEST_IMAGE_PATH = 'data/inD/test' +OBS_LEN = 5 # in timesteps +PRED_LEN = 30 # in timesteps +NUM_GOALS = 20 # K_e +NUM_TRAJ = 1 # K_a + +ROUNDS = 3 # Y-net is stochastic. How often to evaluate the whole dataset +BATCH_SIZE = 8 + + +# #### Load config file and print hyperparameters + +# In[5]: + + +with open(CONFIG_FILE_PATH) as file: + params = yaml.load(file, Loader=yaml.FullLoader) +experiment_name = CONFIG_FILE_PATH.split('.yaml')[0].split('config/')[1] +params + + +# #### Load preprocessed Data + +# In[6]: + + +df_test = pd.read_pickle(TEST_DATA_PATH) + + +# In[7]: + + +df_test.head() + + +# #### Initiate model and load pretrained weights + +# In[8]: + + +model = YNet(obs_len=OBS_LEN, pred_len=PRED_LEN, params=params) + + +# In[9]: + + +model.load(f'pretrained_models/{experiment_name}_weights.pt') + + +# #### Evaluate model + +# In[10]: + + +model.evaluate(df_test, params, image_path=TEST_IMAGE_PATH, + batch_size=BATCH_SIZE, rounds=ROUNDS, + num_goals=NUM_GOALS, num_traj=NUM_TRAJ, device=None, dataset_name=DATASET_NAME) + + +# In[1]: + + +get_ipython().system('nvidia-smi') + + +# In[ ]: + + + + + +# In[ ]: + + + + + +# In[ ]: + + + +