open-mmlab / mmdetection

OpenMMLab Detection Toolbox and Benchmark
https://mmdetection.readthedocs.io
Apache License 2.0
29.14k stars 9.39k forks source link

class error when visualizing output #5017

Closed FirasKedidi closed 3 years ago

FirasKedidi commented 3 years ago

Hello, I've trained a mask rcnn model on mmdetection on costum data.The model finished training but when I tried to do inference and visualize the output I got this error that mask rcnn have no attribute classes image

jshilong commented 3 years ago

Please give more detail about the problem.

FirasKedidi commented 3 years ago

I am using mask_rcnn_r101_fpn_2x_coco model to detect three classes.I am using my own custom dataset in coco format mounted via drive.I am using colab.I followed the get_started colab notebook except that I didn't transform the data because it's already in a coco format. Also when training the detector I didn't get the accuracy of training.

FirasKedidi commented 3 years ago

`cfg = Config.fromfile('/content/mmdetection/configs/mask_rcnn/mask_rcnn_r101_fpn_2x_coco.py') cfg.dataset_type = 'CocoDataset' cfg.classes = ("article","flag","footer") cfg.data.train.img_prefix = '/content/drive/MyDrive/training_dataset_1/' cfg.data.train.classes = cfg.classes cfg.data.train.ann_file = '/content/drive/MyDrive/training_dataset_1/training_data.json' cfg.data.train.type = 'CocoDataset' cfg.data.val.img_prefix = '/content/vgg/' cfg.data.val.classes = cfg.classes cfg.data.val.ann_file = '/content/vgg/arabic_newspaper_coco.json' cfg.data.val.type = 'CocoDataset' cfg.data.test.img_prefix = '/content/drive/MyDrive/validation (1)' cfg.data.test.classes = cfg.classes cfg.data.test.ann_file = '/content/drive/MyDrive/validation (1)/validation_data.json' cfg.data.test.type = 'CocoDataset' cfg.optimizer.lr = 0.02 / 8 cfg.lr_config.warmup = None cfg.log_config.interval = 500

Change the evaluation metric since we use customized dataset.

cfg.evaluation.metric = 'mAP'

We can set the evaluation interval to reduce the evaluation times

cfg.evaluation.interval = 3

We can set the checkpoint saving interval to reduce the storage cost

cfg.checkpoint_config.interval = 3

Set seed thus the results are more reproducible

cfg.seed = 0 set_random_seed(0, deterministic=False) cfg.gpu_ids = range(1)

cfg.load_from = 'checkpoints/mask_rcnn_r101_fpn_2x_coco_bbox_mAP-0.408__segm_mAP-0.366_20200505_071027-14b391c7.pth' cfg.work_dir = "/content/output" cfg.runner.max_epochs = 1 cfg.total_epochs = 1 model = build_detector(cfg.model) mmcv.mkdir_or_exist(osp.abspath(cfg.work_dir)) datasets = [build_dataset(cfg.data.train)] train_detector(model, datasets[0], cfg, distributed=False, validate=True) from mmdet.apis import inference_detector, show_result_pyplot img = mmcv.imread('/content/0001.jpg')

model.cfg = cfg result = inference_detector(model, img) show_result_pyplot(model, img, result,score_thr=0.5)`

FirasKedidi commented 3 years ago

I forgot to put : model.CLASSES = datasets[0].CLASSES also i tried a different model : cascade mask rcnn. the error is gone.