facebookresearch / maskrcnn-benchmark

Fast, modular reference implementation of Instance Segmentation and Object Detection algorithms in PyTorch.
MIT License
9.29k stars 2.5k forks source link

How to use the project just for object detection ? #333

Open LaviLiu opened 5 years ago

LaviLiu commented 5 years ago

❓ Questions and Help

I want to just just the objection function. I transfomed my dataset to coco style. But the segmentation is [] in annotation files. The annotation is like below: "annotations": [{ "segmentation": [], "area": 5332000, "iscrowd": 0, "image_id": 200, "bbox": [311, 707, 161, 135], "category_id": 1, "id": 25064 }, { "segmentation": [], "area": 5332000, "iscrowd": 0, "image_id": 200, "bbox": [351, 631, 101, 90], "category_id": 1, "id": 25065 }, ... But when I train with one GPU. I got the following errors: 2019-01-11 22:36:47,272 maskrcnn_benchmark.trainer INFO: Start training Traceback (most recent call last): File "tools/train_net.py", line 171, in <module> main() File "tools/train_net.py", line 164, in main model = train(cfg, args.local_rank, args.distributed) File "tools/train_net.py", line 73, in train arguments, File "/home/weiliu/deepcode/maskrcnn-benchmark/maskrcnn_benchmark/engine/trainer.py", line 66, in do_train loss_dict = model(images, targets) File "/home/weiliu/anaconda3/envs/py36thmr/lib/python3.6/site-packages/torch/nn/modules/module.py", line 489, in __call__ result = self.forward(*input, **kwargs) File "/home/weiliu/deepcode/maskrcnn-benchmark/maskrcnn_benchmark/modeling/detector/generalized_rcnn.py", line 52, in forward x, result, detector_losses = self.roi_heads(features, proposals, targets) File "/home/weiliu/anaconda3/envs/py36thmr/lib/python3.6/site-packages/torch/nn/modules/module.py", line 489, in __call__ result = self.forward(*input, **kwargs) File "/home/weiliu/deepcode/maskrcnn-benchmark/maskrcnn_benchmark/modeling/roi_heads/roi_heads.py", line 36, in forward x, detections, loss_mask = self.mask(mask_features, detections, targets) File "/home/weiliu/anaconda3/envs/py36thmr/lib/python3.6/site-packages/torch/nn/modules/module.py", line 489, in __call__ result = self.forward(*input, **kwargs) File "/home/weiliu/deepcode/maskrcnn-benchmark/maskrcnn_benchmark/modeling/roi_heads/mask_head/mask_head.py", line 76, in forward loss_mask = self.loss_evaluator(proposals, mask_logits, targets) File "/home/weiliu/deepcode/maskrcnn-benchmark/maskrcnn_benchmark/modeling/roi_heads/mask_head/loss.py", line 114, in __call__ labels, mask_targets = self.prepare_targets(proposals, targets) File "/home/weiliu/deepcode/maskrcnn-benchmark/maskrcnn_benchmark/modeling/roi_heads/mask_head/loss.py", line 96, in prepare_targets segmentation_masks, positive_proposals, self.discretization_size File "/home/weiliu/deepcode/maskrcnn-benchmark/maskrcnn_benchmark/modeling/roi_heads/mask_head/loss.py", line 40, in project_masks_on_boxes mask = scaled_mask.convert(mode="mask") File "/home/weiliu/deepcode/maskrcnn-benchmark/maskrcnn_benchmark/structures/segmentation_mask.py", line 129, in convert [p.numpy() for p in self.polygons], height, width File "pycocotools/_mask.pyx", line 292, in pycocotools._mask.frPyObjects IndexError: list index out of range I want to know how to use the project just for object detection ?

fmassa commented 5 years ago

In theory, all you need to do is to set MASK_ON to False (the default value) https://github.com/facebookresearch/maskrcnn-benchmark/blob/f25c6cff92d32d92abe8965d68401004e90c8bee/configs/e2e_mask_rcnn_R_50_C4_1x.yaml#L10

What is the config file that you are using?

hockeybro12 commented 5 years ago

Hi,

I would like to do something like what is described in this image:

screen shot 2019-01-30 at 6 12 48 pm

In this picture, an image is passed to the Mask R-CNN model and some object detection segmentation is done on the shape. This allows a future model to more easily identify the relevant shapes, once the segmentation map is concatenated on top of the original image.

I am trying to do this on this picture:

screen shot 2019-01-30 at 6 13 56 pm

I run the MaskRCNN as given in the demo notebook. However, the image seems to be unchanged with both options. I don't see any segmentation maps being drawn.

Is it possible to use this library to do this task? Must I fine-tune the given model to get it to work?

Thanks in advance for your help

fmassa commented 5 years ago

@hockeybro12 you'll need to retrain/finetune for your particular use-case. The classes that maskrcnn-benchmark were trained for can be seen in https://github.com/facebookresearch/maskrcnn-benchmark/blob/c5ca36fc644dfc1d3dd4ad15739bf6bb4df72d72/demo/predictor.py#L16-L98

hockeybro12 commented 5 years ago

@fmassa Hmm ok. Are you by any chance aware of any other object detection models that work for shapes?

fmassa commented 5 years ago

@hockeybro12 not out of the box, no