aosokin / os2d

OS2D: One-Stage One-Shot Object Detection by Matching Anchor Features

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

making the code faster

roitmaster opened this issue · comments

Hi once again awsome work you did

in your head.py lines 371-376 :
default_boxes_xyxy_wrt_fm = self.box_grid_generator_feature_map_level.create_strided_boxes_columnfirst(fm_size=image_fm_size)

default_boxes_xyxy_wrt_fm = default_boxes_xyxy_wrt_fm.view(1, 1, image_fm_size.h, image_fm_size.w, 4)
# 1 (to broadcast to batch_size) x 1 (to broadcast to class batch_size) x  box_grid_height x box_grid_width x 4
default_boxes_xyxy_wrt_fm = default_boxes_xyxy_wrt_fm.to(resampling_grids_local_coord.device)
resampling_grids_fm_coord = convert_box_coordinates_local_to_global(resampling_grids_local_coord, default_boxes_xyxy_wrt_fm)

and lines 405-410:

default_boxes_xyxy_wrt_image = self.box_grid_generator_image_level.create_strided_boxes_columnfirst(fm_size=image_fm_size)
default_boxes_xyxy_wrt_image = default_boxes_xyxy_wrt_image.view(1, 1, image_fm_size.h, image_fm_size.w, 4)
# 1 (to broadcast to batch_size) x 1 (to broadcast to class batch_size) x  box_grid_height x box_grid_width x 4
default_boxes_xyxy_wrt_image = default_boxes_xyxy_wrt_image.to(resampling_grids_local_coord.device)
resampling_grids_image_coord = convert_box_coordinates_local_to_global(resampling_grids_local_coord, default_boxes_xyxy_wrt_image)

thus line do the same calculation, and they don't have trainable parameters, why we can't reuse the first calculation for the second one?

Note that line 371

default_boxes_xyxy_wrt_fm = self.box_grid_generator_feature_map_level.create_strided_boxes_columnfirst(fm_size=image_fm_size)

and line 405
default_boxes_xyxy_wrt_image = self.box_grid_generator_image_level.create_strided_boxes_columnfirst(fm_size=image_fm_size)

depend on self.box_grid_generator_feature_map_level and self.box_grid_generator_image_level, respectively.
These two are different objects:

os2d/os2d/modeling/head.py

Lines 218 to 220 in 96c488b

self.box_grid_generator_image_level = BoxGridGenerator(box_size=rec_field, box_stride=stride)
self.box_grid_generator_feature_map_level = BoxGridGenerator(box_size=self.aligner.network_receptive_field,
box_stride=self.aligner.network_stride)

If I remember correctly, the first one produces boxes in the coordinates w.r.t. the feature map, the second one - w.r.t. the input image.