open-mmlab / mmdetection

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

MMdetection using coco dataset #5514

Closed shabbbb closed 3 years ago

shabbbb commented 3 years ago

I tried mmdetection using coco dataset, and I am getting the following error, during training.


ValueError Traceback (most recent call last) /usr/local/lib/python3.7/dist-packages/mmcv/utils/registry.py in build_from_cfg(cfg, registry, default_args) 50 try: ---> 51 return obj_cls(**args) 52 except Exception as e:

4 frames /content/mmdetection/mmdet/datasets/custom.py in init(self, ann_file, pipeline, classes, data_root, img_prefix, seg_prefix, proposal_file, test_mode, filter_empty_gt) 87 # load annotations (and proposals) ---> 88 self.data_infos = self.load_annotations(self.ann_file) 89

in load_annotations(self, ann_file) 67 bboxes_ignore=np.array(gt_bboxes_ignore, ---> 68 dtype=np.float32).reshape(-1, 4), 69 labels_ignore=np.array(gt_labels_ignore, dtype=np.long)) ValueError: cannot reshape array of size 31 into shape (4) During handling of the above exception, another exception occurred: ValueError Traceback (most recent call last) in () 5 6 # Build dataset ----> 7 datasets = [build_dataset(cfg.data.train)] 8 9 # Build the detector /content/mmdetection/mmdet/datasets/builder.py in build_dataset(cfg, default_args) 69 dataset = _concat_dataset(cfg, default_args) 70 else: ---> 71 dataset = build_from_cfg(cfg, DATASETS, default_args) 72 73 return dataset /usr/local/lib/python3.7/dist-packages/mmcv/utils/registry.py in build_from_cfg(cfg, registry, default_args) 52 except Exception as e: 53 # Normal TypeError does not print class name. ---> 54 raise type(e)(f'{obj_cls.__name__}: {e}') 55 56 ValueError: ccocoDataset: cannot reshape array of size 31 into shape (4) --------------------------------------------------------------------------- And also, I mounted cocodataset into my notebook using : ---------------------------------------------------- !curl -L "https://public.roboflow.com/ds/TS1Gv1DctE?key=mqqgGIv57m" > roboflow.zip; unzip roboflow.zip; rm roboflow.zip ----------------------------------------------------- which provide annotations in .txt format. I will be grateful, if you can help me in this. Thank You...
AronLin commented 3 years ago

The dataset you downloaded is processed, not the original dataset. Our CocoDataset does not support this format. You can download the original dataset from coco.

shabbbb commented 3 years ago

Yes Sir, the coco dataset that I downloaded is processed. But instead of running coco.py; the cell I ran is as follows (which is for custom dataset) :

import copy import os.path as osp

import mmcv import numpy as np

from mmdet.datasets.builder import DATASETS from mmdet.datasets.custom import CustomDataset

@DATASETS.register_module() class cccocoDataset(CustomDataset):

CLASSES = ('person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus',
           'train', 'truck', 'boat', 'traffic light', 'fire hydrant',
           'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog',
           'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe',
           'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee',
           'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat',
           'baseball glove', 'skateboard', 'surfboard', 'tennis racket',
           'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl',
           'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot',
           'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch',
           'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop',
           'mouse', 'remote', 'keyboard', 'cell phone', 'microwave',
           'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock',
           'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush')

def load_annotations(self, ann_file):
    cat2label = {k: i for i, k in enumerate(self.CLASSES)}
    # load image list from file
    image_list = mmcv.list_from_file(self.ann_file)

    data_infos = []
    # convert annotations to middle format
    for image_id in image_list:
        filename = f'{self.img_prefix}/{image_id}.jpg'
        image = mmcv.imread(filename)
        height, width = image.shape[:2]

        data_info = dict(filename=f'{image_id}.jpg', width=width, height=height)

        # load annotations
        label_prefix = self.img_prefix.replace('images', 'labels')
        lines = mmcv.list_from_file(osp.join(label_prefix, f'{image_id}.txt'))

        content = [line.strip().split(' ') for line in lines]
        bbox_names = [x[0] for x in content]
        bboxes = [[float(info) for info in x[4:8]] for x in content]

        gt_bboxes = []
        gt_labels = []
        gt_bboxes_ignore = []
        gt_labels_ignore = []

        # filter 'DontCare'
        for bbox_name, bbox in zip(bbox_names, bboxes):
            if bbox_name in cat2label:
                gt_labels.append(cat2label[bbox_name])
                gt_bboxes.append(bbox)
            else:
                gt_labels_ignore.append(-1)
                gt_bboxes_ignore.append(bbox)

        data_anno = dict(
            bboxes=np.array(gt_bboxes, dtype=np.float32).reshape(-1, 4),
            labels=np.array(gt_labels, dtype=np.long),
            bboxes_ignore=np.array(gt_bboxes_ignore,
                                   dtype=np.float32).reshape(-1, 4),
            labels_ignore=np.array(gt_labels_ignore, dtype=np.long))

        data_info.update(ann=data_anno)
        data_infos.append(data_info)

    return data_infos

AronLin commented 3 years ago

ValueError: cannot reshape array of size 31 into shape (4)

According to the error message, the size of bboxes_ignore is not a multiple of 4. You can check the shape of it. It looks like just a bug and has nothing to do with our dataset.