Open cs-heibao opened 3 years ago
I believe the code is correct. Did you encounter an error during training?
@duanzhiihao sorry, it's my misunderstanding, by the way, is the code support images with no objects(I want to add some negative samples)?
Yes, it supports empty images. I would recommend not to add too many negative samples since it will slow down the training.
@duanzhiihao should I do some changes if I add some empty images, or directly?
@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)
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.
@duanzhiihao thanks, I will try it later.
the code as following:
for the
self.pred_L = PredLayer(self.anchors_all, self.index_L, **kwargs)
, theself.index_L
should be[6, 7, 8]
, so the same as to hereself.anchor_indices
:while the
best_n_all belongs to[0, 8]
, andself.num_anchors=3
, sobest_n = best_n_all % self.num_anchors
,best_n
can only equals to 0, 1, 2, cannot be 3, 4, 5, 6, 7, 8