Tung-I/Dual-awareness-Attention-for-Few-shot-Object-Detection

inference error or problems

Opened this issue · 2 comments

hello,dear author @Tung-I
During the training, it went well.However, the following problems occurred in the inference process.I execute python inference.py. How can I change it?

Namespace(ascale=4, batch_size=1, cfg_file='cfgs/res50.yml', checkepoch=1, checkpoint=34467, dataset='val2014_novel', disp_interval=100, dlog=False, eval=True, eval_dir='dana', fewshot=False, imdbval_name='coco_20_set1', imlog=False, large_scale=False, load_dir='models/DAnA-cocoBase', lr=0.001, lr_decay_gamma=0.1, lr_decay_step=1000, mGPUs=False, max_epochs=12, net='DAnA', num_workers=0, old_n_classes=81, optimizer='sgd', resume=True, save_dir='models', set_cfgs=['ANCHOR_SCALES', '[4, 8, 16, 32]', 'ANCHOR_RATIOS', '[0.5,1,2]', 'MAX_NUM_GT_BOXES', '50'], shot=3, start_epoch=1, sup_dir='all', use_flip=False, way=1)
coco_20_set1
loading annotations into memory...
Done (t=0.11s)
creating index...
index created!
Loaded dataset coco_set1_20 for training
Set proposal method: gt
Preparing training data...
done
loading annotations into memory...
Done (t=0.11s)
creating index...
index created!
load checkpoint models/DAnA-cocoBase/train/checkpoints/model_1_34467.pth
Traceback (most recent call last):
File "inference.py", line 50, in
model.load_state_dict(checkpoint['model'],strict=False)
File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 1407, in load_state_dict
self.class.name, "\n\t".join(error_msgs)))
RuntimeError: Error(s) in loading state_dict for DAnARCNN:
size mismatch for RCNN_rpn.RPN_cls_score.weight: copying a param with shape torch.Size([18, 512, 1, 1]) from checkpoint, the shape in current model is torch.Size([24, 512, 1, 1]).
size mismatch for RCNN_rpn.RPN_cls_score.bias: copying a param with shape torch.Size([18]) from checkpoint, the shape in current model is torch.Size([24]).
size mismatch for RCNN_rpn.RPN_bbox_pred.weight: copying a param with shape torch.Size([36, 512, 1, 1]) from checkpoint, the shape in current model is torch.Size([48, 512, 1, 1]).
size mismatch for RCNN_rpn.RPN_bbox_pred.bias: copying a param with shape torch.Size([36]) from checkpoint, the shape in current model is torch.Size([48]).

I hope I will get you recieve soon

It seems the number of anchors of RPN at inference.py is misaligned with that at the loaded model. According to the error message, the RPN cls layer you loaded has 3x3(anchors of 9 different sizes)x2(positive or negative) = 18 channels, yet the container you created has 4x3x2 = 24 channels. Please set args.set_cfgs = ['ANCHOR_SCALES', '[8, 16, 32]', 'ANCHOR_RATIOS', '[0.5,1,2]', 'MAX_NUM_GT_BOXES', '30'] in inference.py parameters and see if it works. This could be a bug I overlooked, sorry for that.

Yes, your`re right. It works now. Thank you.