open-mmlab / mmdetection

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

Error while trying to train the model for a different data set #8197

Open ZahraAnam opened 2 years ago

ZahraAnam commented 2 years ago

I am trying to follow the tutorial and have written the following code:

import os.path as osp import mmcv

import numpy as np

import pdb

The new config inherits a base config to highlight the necessary modification

base = '/home/anam_zahra/QuantEx_Projects/mmdet/mmdetection/configs/mask_rcnn/mask_rcnn_r50_caffe_fpn_mstrain-poly_1x_coco.py'

pdb.set_trace()

dataset_type = 'CocoDataset' pdb.set_trace() classes = ("person","kitchenware","screen","animal","toy","book","object") pdb.set_trace()

explicitly over-write all the num_classes field from default 80 to 5.

data = dict( samples_per_gpu=2, workers_per_gpu=2, train=dict( type=dataset_type, classes=classes, img_prefix='/Processed_Data/Sample_DataSet/images/train', ann_file='/Processed_Data/Sample_DataSet/labels/train.json'), val=dict( type=dataset_type, classes=classes, img_prefix='/Processed_Data/Sample_DataSet/images/valid', ann_file='/Processed_Data/Sample_DataSet/labels/valid.json'), test=dict( type=dataset_type, classes=classes, img_prefix='/Processed_Data/Sample_DataSet/images/test', ann_file='/Processed_Data/Sample_DataSet/labels/test.json'))

pdb.set_trace() model = dict( roi_head=dict( bbox_head=[ dict( type='Shared2FCBBoxHead',

explicitly over-write all the num_classes field from default 80 to 7.

            num_classes=7),
        dict(
            type='Shared2FCBBoxHead',
            # explicitly over-write all the `num_classes` field from default 80 to 7.
            num_classes=7),
        dict(
            type='Shared2FCBBoxHead',
            # explicitly over-write all the `num_classes` field from default 80 to 7.
            num_classes=7)],
# explicitly over-write all the `num_classes` field from default 80 to 7.
mask_head=dict(num_classes=7)))

We can use the pre-trained Mask RCNN model to obtain higher performance

pdb.set_trace()

load_from = '/mmdet/mmdetection/checkpoints/mask_rcnn_r50_caffe_fpn_mstrain-poly_2x_coco_bbox.pth'

And I get the following error: mmdet/lib/python3.6/site-packages/mmdet/datasets/samplers/group_sampler.py", line 36, in iter indices = np.concatenate(indices) File "<__array_function__ internals>", line 6, in concatenate ValueError: need at least one array to concatenate

Further report is as follows:2022-06-15 14:27:55,554 - mmdet - INFO - workflow: [('train', 1)], max: 8 epochs 2022-06-15 14:27:55,554 - mmdet - INFO - Checkpoints will be saved to /home/anam_zahra/QuantEx_Projects/mmdet/mmdetection/work_dirs/retrain_demo by HardDiskBackend. Traceback (most recent call last): File "tools/train.py", line 242, in main() File "tools/train.py", line 238, in main meta=meta) File "/home/anam_zahra/QuantEx_Projects/mmdet/lib/python3.6/site-packages/mmdet/apis/train.py", line 244, in train_detector runner.run(data_loaders, cfg.workflow) File "/home/anam_zahra/QuantEx_Projects/mmdet/lib/python3.6/site-packages/mmcv/runner/epoch_based_runner.py", line 130, in run epoch_runner(data_loaders[i], **kwargs) File "/home/anam_zahra/QuantEx_Projects/mmdet/lib/python3.6/site-packages/mmcv/runner/epoch_based_runner.py", line 47, in train for i, data_batch in enumerate(self.data_loader): File "/home/anam_zahra/QuantEx_Projects/mmdet/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 359, in iter return self._get_iterator() File "/home/anam_zahra/QuantEx_Projects/mmdet/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 305, in _get_iterator return _MultiProcessingDataLoaderIter(self) File "/home/anam_zahra/QuantEx_Projects/mmdet/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 944, in init self._reset(loader, first_iter=True) File "/home/anam_zahra/QuantEx_Projects/mmdet/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 975, in _reset self._try_put_index() File "/home/anam_zahra/QuantEx_Projects/mmdet/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 1209, in _try_put_index index = self._next_index() File "/home/anam_zahra/QuantEx_Projects/mmdet/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 512, in _next_index return next(self._sampler_iter) # may raise StopIteration File "/home/anam_zahra/QuantEx_Projects/mmdet/lib/python3.6/site-packages/torch/utils/data/sampler.py", line 229, in iter for idx in self.sampler: File "/home/anam_zahra/QuantEx_Projects/mmdet/lib/python3.6/site-packages/mmdet/datasets/samplers/group_sampler.py", line 36, in iter indices = np.concatenate(indices) File "<__array_function__ internals>", line 6, in concatenate ValueError: need at least one array to concatenate

I was wondering if you can help please

jbwang1997 commented 2 years ago

Maybe this issue can help you. https://github.com/open-mmlab/mmdetection/issues/3628

ZahraAnam commented 2 years ago

Thank you, I can check

On Thu, Jun 16, 2022 at 4:45 AM jbwang1997 @.***> wrote:

Maybe this issue can help you. #3628 https://github.com/open-mmlab/mmdetection/issues/3628

— Reply to this email directly, view it on GitHub https://github.com/open-mmlab/mmdetection/issues/8197#issuecomment-1157171050, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIIJTCQ5RPQ7FBIFHRKO7TTVPKIMRANCNFSM5Y3EKTHA . You are receiving this because you authored the thread.Message ID: @.***>

-- Best Regards, Anam Zahra, PhD Fellow MPI, Email- @.***