Skip to content

Commit

Permalink
Fixed bugs related to AL-v1 and obtained results of history based hea…
Browse files Browse the repository at this point in the history
…d selection on jetson agx.
  • Loading branch information
ahmedius2 committed Aug 17, 2023
1 parent a3a08f8 commit f58a911
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 21 deletions.
26 changes: 12 additions & 14 deletions pcdet/models/dense_heads/center_head_imprecise.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,7 @@ def generate_predicted_boxes(self, batch_size, pred_dicts, heads_to_run):
'pred_scores': [],
'pred_labels': [],
} for k in range(batch_size)]
for idx, pred_dict in enumerate(pred_dicts):
if idx not in heads_to_run:
continue
for head_idx, pred_dict in zip(heads_to_run, pred_dicts):
batch_hm = pred_dict['hm'].sigmoid()
batch_center = pred_dict['center']
batch_center_z = pred_dict['center_z']
Expand All @@ -315,18 +313,18 @@ def generate_predicted_boxes(self, batch_size, pred_dicts, heads_to_run):
)

for k, final_dict in enumerate(final_pred_dicts):
final_dict['pred_labels'] = self.class_id_mapping_each_head[idx][final_dict['pred_labels'].long()]
final_dict['pred_labels'] = self.class_id_mapping_each_head[head_idx \
][final_dict['pred_labels'].long()]
if post_process_cfg.NMS_CONFIG.NMS_TYPE != 'circle_nms':
if final_dict['pred_scores'].size(0) > 1:
selected, selected_scores = model_nms_utils.class_agnostic_nms(
box_scores=final_dict['pred_scores'], box_preds=final_dict['pred_boxes'],
nms_config=post_process_cfg.NMS_CONFIG,
score_thresh=None
)

final_dict['pred_boxes'] = final_dict['pred_boxes'][selected]
final_dict['pred_scores'] = selected_scores
final_dict['pred_labels'] = final_dict['pred_labels'][selected]
selected, selected_scores = model_nms_utils.class_agnostic_nms(
box_scores=final_dict['pred_scores'], box_preds=final_dict['pred_boxes'],
nms_config=post_process_cfg.NMS_CONFIG,
score_thresh=None
)

final_dict['pred_boxes'] = final_dict['pred_boxes'][selected]
final_dict['pred_scores'] = selected_scores
final_dict['pred_labels'] = final_dict['pred_labels'][selected]

ret_dict[k]['pred_boxes'].append(final_dict['pred_boxes'])
ret_dict[k]['pred_scores'].append(final_dict['pred_scores'])
Expand Down
21 changes: 18 additions & 3 deletions pcdet/models/detectors/anytime_template_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ def __init__(self, model_cfg, num_class, dataset):

#self.calibrating_now = False
self.add_dict = self._eval_dict['additional']
self.add_dict['bb3d_preds'] = []
self.add_dict['nonempty_tiles'] = []
self.add_dict['chosen_tiles_1'] = []
self.add_dict['chosen_tiles_2'] = []
#for k in ('voxel_counts', 'num_tiles', 'PostSched'):
# self.add_dict[k] = []

Expand Down Expand Up @@ -239,15 +243,16 @@ def schedule1(self, batch_dict):
num_tiles, vcounts_all, netc_flip= round_robin_sched_helper(
batch_dict['nonempty_tile_coords'], self.last_tile_coord, self.tcount,
netc_vcounts.cpu().numpy())
self.add_dict['nonempty_tiles'].append(batch_dict['nonempty_tile_coords'].tolist())
self.projection_stream.synchronize()

vcounts_all = torch.from_numpy(vcounts_all)
num_tiles = torch.from_numpy(num_tiles)
bb3d_times, post_bb3d_times = self.calibrator.pred_req_times_ms(vcounts_all, num_tiles)
batch_dict['post_bb3d_times'] = post_bb3d_times
tpreds = bb3d_times + post_bb3d_times
self.psched_start_time = time.time()
rem_time_ms = (batch_dict['abs_deadline_sec'] - self.psched_start_time) * 1000
psched_start_time = time.time()
rem_time_ms = (batch_dict['abs_deadline_sec'] - psched_start_time) * 1000

# Choose configuration that can meet the deadline, that's it
diffs = tpreds < rem_time_ms
Expand All @@ -262,11 +267,14 @@ def schedule1(self, batch_dict):
batch_dict['netc_flip'] = netc_flip
if diffs[-1]:
chosen_tile_coords = netc.numpy()
self.add_dict['bb3d_preds'].append(float(bb3d_times[-1]))
else:
tiles_idx=1
while tiles_idx < diffs.shape[0] and diffs[tiles_idx]:
tiles_idx += 1

self.add_dict['bb3d_preds'].append(float(bb3d_times[tiles_idx-1]))

# Voxel filtering is needed
chosen_tile_coords = netc_flip[:tiles_idx]
self.last_tile_coord = chosen_tile_coords[-1].item()
Expand All @@ -283,7 +291,7 @@ def schedule1(self, batch_dict):
self.measure_time_end('Sched')
return batch_dict
batch_dict['chosen_tile_coords'] = chosen_tile_coords

self.add_dict['chosen_tiles_1'].append(chosen_tile_coords.tolist())
self.measure_time_end('Sched')

return batch_dict
Expand All @@ -302,6 +310,7 @@ def schedule2(self, batch_dict):
chosen_tile_coords = batch_dict['netc_flip'][:tiles_idx]
self.last_tile_coord = chosen_tile_coords[-1].item()
batch_dict['chosen_tile_coords'] = chosen_tile_coords
self.add_dict['chosen_tiles_2'].append(batch_dict['chosen_tile_coords'].tolist())

return batch_dict

Expand Down Expand Up @@ -389,6 +398,12 @@ def calibrate(self):
return None

def post_eval(self):
# remove first ones due to calibration
self.add_dict['bb3d_preds'] = self.add_dict['bb3d_preds'][1:]
self.add_dict['nonempty_tiles'] = self.add_dict['nonempty_tiles'][1:]
self.add_dict['chosen_tiles_1'] = self.add_dict['chosen_tiles_1'][1:]
self.add_dict['chosen_tiles_2'] = self.add_dict['chosen_tiles_2'][1:]

self.add_dict['tcount'] = self.tcount
print(f"\nDeadlines missed: {self._eval_dict['deadlines_missed']}\n")

Expand Down
9 changes: 5 additions & 4 deletions pcdet/models/detectors/detector3d_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ def post_forward_hook(module, inp_args, outp_args):
if module._det_dict_copy is not None:
pred_dicts = [ module.get_dummy_det_dict() for p in pred_dicts ]

tm = module.finish_time - module.psched_start_time
module._eval_dict['additional']['PostSched'].append(tm)
#tm = module.finish_time - module.psched_start_time
#module._eval_dict['additional']['PostSched'].append(tm)

torch.cuda.synchronize()
module.calc_elapsed_times()
Expand Down Expand Up @@ -105,6 +105,7 @@ def __init__(self, model_cfg, num_class, dataset):
self.update_time_dict(dict())

self._eval_dict = {}
self._eval_dict['additional'] = {}
if self.model_cfg.get('DEADLINE_SEC', None) is not None:
self._default_deadline_sec = float(model_cfg.DEADLINE_SEC)
self._eval_dict['deadline_sec'] = self._default_deadline_sec
Expand All @@ -116,15 +117,15 @@ def __init__(self, model_cfg, num_class, dataset):
print('Default deadline is:', self._eval_dict['deadline_sec'])

# To be filled by the child class, in case needed
self._eval_dict['additional'] = {'PostSched':[]}
#self._eval_dict['additional'] = {'PostSched':[]}

self._det_dict_copy = None
self.pre_hook_handle = self.register_forward_pre_hook(pre_forward_hook)
self.post_hook_handle = self.register_forward_hook(post_forward_hook)
self.hooks_binded = True

self.latest_batch_dict = None
self.psched_start_time = 0
#self.psched_start_time = 0

self.client = None
#self.client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
Expand Down

0 comments on commit f58a911

Please sign in to comment.