Skip to content

Commit

Permalink
eval changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rogeriobonatti committed Jun 7, 2022
1 parent f94d1b9 commit 5655d1b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
8 changes: 6 additions & 2 deletions mushr_rhc_ros/launch/sim/sim_server_eval.launch
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@
<arg name="n_layers" default="12" />

<!-- action model -->
<arg name="model_path_act" default="/home/rb/hackathon_data_premium/aml_outputs/log_output/hvd_test_16/GPTcorl_scratch_trainm_e2e_statet_pointnet_traini_1_nla_12_nhe_8_statel_0.01_2022-06-02_1654131996.2524076_2022-06-02_1654131996.2524228/model/epoch30.pth.tar" />
<arg name="model_path_act" type="str" default="" />
<!-- <arg name="model_path_act" default="/home/rb/hackathon_data_premium/aml_outputs/log_output/hvd_test_16/GPTcorl_scratch_trainm_e2e_statet_pointnet_traini_1_nla_12_nhe_8_statel_0.01_2022-06-02_1654131996.2524076_2022-06-02_1654131996.2524228/model/epoch30.pth.tar" /> -->
<!-- <arg name="model_path_act" default="/home/rb/hackathon_data_premium/aml_outputs/log_output/model_sizes_0/GPTcorl_scratch_trainm_e2e_statet_pointnet_traini_0_nla_6_nhe_8_statel_0.01_2022-06-03_1654253046.3212142_2022-06-03_1654253046.3212266/model/epoch30.pth.tar" /> -->
<!-- <arg name="model_path_act" default="/home/rb/hackathon_data_premium/aml_outputs/log_output/model_sizes_0/GPTcorl_scratch_trainm_e2e_statet_pointnet_traini_1_nla_24_nhe_8_statel_0.01_2022-06-03_1654235683.085602_2022-06-03_1654235683.0856125/model/epoch30.pth.tar" /> -->
<!-- <arg name="model_path_act" default="/home/rb/hackathon_data_premium/aml_outputs/log_output/model_sizes_1/GPTcorl_scratch_trainm_e2e_statet_pointnet_traini_1_nla_12_nhe_8_statel_0.1_2022-06-06_1654492441.2570548_2022-06-06_1654492441.2570653/model/epoch74.pth.tar" /> -->
<!-- <arg name="model_path_act" default="/home/rb/hackathon_data_premium/aml_outputs/log_output/model_sizes_1/GPTcorl_scratch_trainm_e2e_statet_pointnet_traini_1_nla_6_nhe_8_statel_0.1_2022-06-06_1654513698.5957458_2022-06-06_1654513698.5957568/model/epoch64.pth.tar" /> -->
<!-- <arg name="model_path_act" default="/home/rb/hackathon_data_premium/aml_outputs/log_output/model_sizes_1/GPTcorl_scratch_trainm_e2e_statet_pointnet_traini_1_nla_24_nhe_8_statel_0.1_2022-06-06_1654493649.8333972_2022-06-06_1654493649.8334105/model/epoch51.pth.tar" /> -->

<!-- map model -->
<arg name="use_map" default="false" />
Expand All @@ -26,7 +30,7 @@
<arg name="use_loc" default="false" />
<arg name="model_path_loc" default="/home/rb/hackathon_data_premium/aml_outputs/log_output/locscratch_new_0/GPTcorl_loc_trainm_loc_sta_pointnet_lr_6e-5_traini_1_nla_12_nhe_8_locx_0.01_locy_1_loca_10_locd_joint_2022-05-31_1653978601.5423563_2022-05-31_1653978601.5423756/model/epoch30.pth.tar" />

<arg name="deployment_map" default="test" />
<arg name="deployment_map" default="train" />
<!-- <arg name="deployment_map" default="test" /> -->

<group if="$(eval arg('deployment_map') == 'train')">
Expand Down
40 changes: 24 additions & 16 deletions mushr_rhc_ros/src/rhcnode_network_pcl_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ def __init__(self, dtype, params, logger, name):
self.time_started_goal = None
self.num_trials = 0

self.act_inference_time_sum = 0.0
self.act_inference_time_count = 0

self.cur_rollout = self.cur_rollout_ip = None
self.traj_pub_lock = threading.Lock()

Expand Down Expand Up @@ -107,7 +110,7 @@ def __init__(self, dtype, params, logger, name):
self.use_map = rospy.get_param("~use_map", False)
self.use_loc = rospy.get_param("~use_loc", False)

saved_model_path_action = rospy.get_param("~model_path_act", 'default_value')
saved_model_path_action = rospy.get_param("~model_path_act", '')
self.out_path = rospy.get_param("~out_path", 'default_value')

self.n_layers = rospy.get_param("~n_layers", 12)
Expand All @@ -127,19 +130,20 @@ def __init__(self, dtype, params, logger, name):
model = GPT(mconf, device)
# model=torch.nn.DataParallel(model)

checkpoint = torch.load(saved_model_path_action, map_location=device)
# old code for loading model
model.load_state_dict(checkpoint['state_dict'])
# new code for loading mode
# new_checkpoint = OrderedDict()
# for key in checkpoint['state_dict'].keys():
# new_checkpoint[key.split("module.",1)[1]] = checkpoint['state_dict'][key]
# model.load_state_dict(new_checkpoint)
if len(saved_model_path_action)>0:
checkpoint = torch.load(saved_model_path_action, map_location=device)
# old code for loading model
model.load_state_dict(checkpoint['state_dict'])
# new code for loading mode
# new_checkpoint = OrderedDict()
# for key in checkpoint['state_dict'].keys():
# new_checkpoint[key.split("module.",1)[1]] = checkpoint['state_dict'][key]
# model.load_state_dict(new_checkpoint)

# ckpt = torch.load('/home/rb/downloaded_models/epoch30.pth.tar')['state_dict']
# for key in ckpt:
# print('********',key)
# model.load_state_dict(torch.load('/home/rb/downloaded_models/epoch30.pth.tar')['state_dict'], strict=True)
# ckpt = torch.load('/home/rb/downloaded_models/epoch30.pth.tar')['state_dict']
# for key in ckpt:
# print('********',key)
# model.load_state_dict(torch.load('/home/rb/downloaded_models/epoch30.pth.tar')['state_dict'], strict=True)

model.eval()
# model.half()
Expand Down Expand Up @@ -532,22 +536,26 @@ def publish_vel_marker(self):


def apply_network(self):
start_zero = time.time()
x_imgs, x_act, t = self.prepare_model_inputs(queue_type='small')
start = time.time()
# with torch.set_grad_enabled(False):
with torch.inference_mode():
# action_pred = 0.0
action_pred, _, _, _ = self.model(states=x_imgs, actions=x_act, targets=x_act, gt_map=None, timesteps=t, poses=None, compute_loss=False)
finished_action_network = time.time()
rospy.loginfo("action network delay: "+str(finished_action_network-start))
# rospy.loginfo_throttle(10, "action network delay: "+str(finished_action_network-start))
# rospy.loginfo("action network delay: "+str(finished_action_network-start))
# self.act_inference_time_sum += finished_action_network-start
# self.act_inference_time_count += 1
rospy.loginfo_throttle(10, "action network delay: "+str(finished_action_network-start))
# rospy.loginfo_throttle(10, "AVG action network delay: "+str(self.act_inference_time_sum/self.act_inference_time_count))
action_pred = action_pred[0,-1,0].cpu().flatten().item()
# if self.use_map:
# map_pred, loss = self.map_model(states=x_imgs, actions=x_act, targets=x_act, gt_map=None, timesteps=t, poses=None)
# finished_map_network = time.time()
# rospy.loginfo("map network delay: "+str(finished_map_network-finished_action_network))
finished_network = time.time()
# rospy.loginfo("network delay: "+str(finished_network-finish_processing))
# rospy.loginfo("network delay total: "+str(finished_network-start_zero))
# de-normalize
action_pred = pre.denorm_angle(action_pred)
return action_pred
Expand Down

0 comments on commit 5655d1b

Please sign in to comment.