duanzhiihao / RAPiD

RAPiD: Rotation-Aware People Detection in Overhead Fisheye Images (CVPR 2020 Workshops)
http://vip.bu.edu/rapid/
Other
213 stars 63 forks source link

is there something wrong in the "PredLayer module" #16

Open cs-heibao opened 3 years ago

cs-heibao commented 3 years ago

the code as following:

# calculate iou between truth and reference anchors
anchor_ious = iou_mask(gt_boxes, norm_anch_00wha, xywha=True,mask_size=64, is_degree=True)
# anchor_ious = iou_rle(gt_boxes, norm_anch_00wha, xywha=True, is_degree=True, img_size=img_size, normalized=True)
best_n_all = torch.argmax(anchor_ious, dim=1)
best_n = best_n_all % self.num_anchors

valid_mask = torch.zeros(n, dtype=torch.bool, device=device)
 for ind in self.anchor_indices.to(device=device):
      valid_mask = ( valid_mask | (best_n_all == ind) )
if sum(valid_mask) == 0:
       # no anchor is responsible for any ground truth
       continue
else:
       valid_gt_num += sum(valid_mask)

for the self.pred_L = PredLayer(self.anchors_all, self.index_L, **kwargs), the self.index_L should be [6, 7, 8], so the same as to here self.anchor_indices:

 for ind in self.anchor_indices.to(device=device):
      valid_mask = ( valid_mask | (best_n_all == ind) )

while the best_n_all belongs to[0, 8], and self.num_anchors=3 , so best_n = best_n_all % self.num_anchors, best_n can only equals to 0, 1, 2, cannot be 3, 4, 5, 6, 7, 8

duanzhiihao commented 3 years ago

I believe the code is correct. Did you encounter an error during training?

cs-heibao commented 3 years ago

@duanzhiihao sorry, it's my misunderstanding, by the way, is the code support images with no objects(I want to add some negative samples)?

duanzhiihao commented 3 years ago

Yes, it supports empty images. I would recommend not to add too many negative samples since it will slow down the training.

cs-heibao commented 3 years ago

@duanzhiihao should I do some changes if I add some empty images, or directly?

cs-heibao commented 3 years ago

@duanzhiihao I found the load_annos function in datasets.py script, seems did not consider the empty images input, or should just comment the assert len(ann['bbox']) == 5 ?

    def load_anns(self, img_dir, json_path):
        '''
        laod json file to self.img_ids, self.imgid2anns
        '''
        self.coco = False
        print(f'Loading annotations {json_path} into memory...')
        with open(json_path, 'r') as f:
            json_data = json.load(f)
        for ann in json_data['annotations']:
            img_id = ann['image_id']
            # get width and height
            if len(ann['bbox']) == 4:
                # using COCO dataset. 4 = [x1,y1,w,h]
                self.coco = True
                # convert COCO format: x1,y1,w,h to x,y,w,h
                ann['bbox'][0] = ann['bbox'][0] + ann['bbox'][2] / 2
                ann['bbox'][1] = ann['bbox'][1] + ann['bbox'][3] / 2
                ann['bbox'].append(0)
                if ann['bbox'][2] > ann['bbox'][3]:
                    ann['bbox'][2],ann['bbox'][3] = ann['bbox'][3],ann['bbox'][2]
                    ann['bbox'][4] -= 90
            else:
                # using rotated bounding box datasets. 5 = [cx,cy,w,h,angle]
                assert len(ann['bbox']) == 5, 'Unknown bbox format' # x,y,w,h,a
            if ann['bbox'][2] == ann['bbox'][3]:
                ann['bbox'][3] += 1 # force that w < h
            ann['bbox'] = torch.Tensor(ann['bbox'])
            try:
                assert ann['bbox'][2] < ann['bbox'][3]
            except Exception as e:
                print(img_id)
            assert ann['bbox'][4] >= -90 and ann['bbox'][4] < 90
            self.imgid2anns[img_id].append(ann)
duanzhiihao commented 3 years ago

No code changes are needed. If you want to add empty images, you should 1) copy them into the images directory, and 2) add the image information into the .json annotation file. You can look at the annotation file from COCO or HABBOF to see the annotation format.

cs-heibao commented 3 years ago

@duanzhiihao thanks, I will try it later.