adityaarun1 / Detectron.pytorch

A PyTorch implementation of Detectron. Both training from scratch and inferring directly from pretrained Detectron weights are available. Supports PyTorch 1.1+ and TorchVision 0.3.0+. No compilation necessary.
MIT License
65 stars 18 forks source link

Infer test images on a custom dataset #3

Closed Asif6511 closed 5 years ago

Asif6511 commented 5 years ago

Hi! I am trying to use voc dataset to infer test images. It works fine with the coco dataset! I am exploring the code and its abilities as I ultimately want to use a custom dataset and classes! So, I was trying to visualize the training performance of VOC2007 on the infer_simple.py. But its not possible as the infer_simple.py only accepts coco or keypoints coco as the acceptable dataset. Am I doing something wrong here?

adityaarun1 commented 5 years ago

You need to prepare the VOC data as mentioned here. You would then need to call the inference step with --dataset voc2007/12 option (as mentioned in the Readme).

Asif6511 commented 5 years ago

Hi! Thanks for the reply. I did prepare the VOC dataset in the way mentioned. However in Infer_simple.py,

if args.dataset.startswith("coco"): dataset = datasets.get_coco_dataset() cfg.MODEL.NUM_CLASSES = len(dataset.classes) elif args.dataset.startswith("keypoints_coco"): dataset = datasets.get_coco_dataset() cfg.MODEL.NUM_CLASSES = 2 else: raise ValueError('Unexpected dataset name: {}'.format(args.dataset))

So we cannot use datasets other than COCO and KEYPOINT COCO?

Also, I would like to know if it is possible to evaluate training results on VOC2007 using "python tools/test_net.py --dataset coco2017 --cfg config/baselines/e2e_mask_rcnn_R-50-FPN_1x.yaml --load_ckpt {path/to/your/checkpoint} " The modelZOO in detectron checkpoints are trained by COCO dataset and cannot be used on VOC2007?

adityaarun1 commented 5 years ago

The test script does accept VOC data (refer these lines). Please make sure that you are running the script as : python tools/test_net.py --dataset voc2007 --cfg config/baselines/e2e_mask_rcnn_R-50-FPN_1x.yaml --load_ckpt {path/to/your/checkpoint}, note --dataset voc2007 option in the command above.

By the way, pre-trained models are trained for COCO dataset only and not for VOC dataset. This may lead to sub-optimal performance (ideally you would either want to train only on VOC trainval or VOC trainval + COCO). So it is recommended that you train your own model first.

Asif6511 commented 5 years ago

When I tried to use pre-trained models of COCO dataset on the test script with VOC, I received this error: RuntimeError: The expanded size of the tensor (21) must match the existing size (81) at non-singleton dimension 0. Target sizes: [21, 1024]. Tensor sizes: [81, 1024]

I am guessing this is a mismatch between number of classes in VOC dataset and the pretrained weight?? Am I right about this ? and is there a way around this or should I train the network?

adityaarun1 commented 5 years ago

Yes. The pretrained models will have 81 output classes (corresponding to the COCO classes) whereas the VOC based model would expect 21 classes. You would need to train the model from scratch (using ImageNet pretrained backbone).

For training from scratch, please follow the instructions given in the Readme.

Asif6511 commented 5 years ago

Ok! Thanks @adityaarun1!