detectron2: AssertionError: You must register a function with `DatasetCatalog.register`!
here i have used custom dataset and i wrote a script to get the values from and return the ‘list[dict]’ Then i have used the following code to register the dataset,
from detectron2.data import DatasetCatalog, MetadataCatalog DatasetCatalog.register(‘train’, get_kitti_data_dict(dataset_root_dir, ‘train’)) MetadataCatalog.get(“train”).thing_classes = [“person”]
But i got following error
Traceback (most recent call last): File “tools/get_dataset_from_kitti.py”, line 94, in <module> DatasetCatalog.register(‘train’, get_kitti_data_dict(dataset_root_dir, ‘train’)) File “/opt/anaconda3/envs/Detectron2/lib/python3.8/site-packages/detectron2/data/catalog.py”, line 37, in register assert callable(func), “You must register a function with
DatasetCatalog.register!” AssertionError: You must register a function withDatasetCatalog.register!
The ‘list[dict]’ is the following
[{'file_name': '/home/samjith/0000180.jpg', 'height': 788, 'width': 1400, 'image_id': 1, 'annotations': [{'bbox': [250.0, 675.0, 23.0, 17.0], 'bbox_mode': <BoxMode.XYWH_ABS: 1>, 'area': 391.0, 'segmentation': [], 'category_id': 0}, {'bbox': [295.0, 550.0, 21.0, 20.0], 'bbox_mode': <BoxMode.XYWH_ABS: 1>, 'area': 420.0, 'segmentation': [], 'category_id': 0},..
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 16 (4 by maintainers)
Hi, I was able to reproduce your error locally as I’m trying to work with the detectron2 also. You must provide a ’ lambda function’ to the 2nd argument like in the custom dataset use custom dataset tutorial:
for d in ['train']:DatasetCatalog.register(d, lambda d: d = get_kitti_data_dict(dataset_root_dir, d))MetadataCatalog.get(d).thing_classes = ["person"]Normally it should work. But really I haven’t gone about how to do it without the loop. Hope it fixes your issueBased on the python language, the loop posted above is equivalent to
An advice: don’t hesitate to go over an error yourself to figure it out ! As you’ll encounter so many in your journey and you’ll not always find people to answer you.
Let’s analyze the error:
dataset_dictsis not defined, is the problem. So the question is where do you define it in the first place in your code. Go there and check if it has been really defined, re-run the cell. In your case here, I can see in the colab notebook that you got an error in the previous cell:In most cases, the error ‘Traceback’ is very clear. You see that the error occurred before
dataset_dicts = get_street_dicts("/content/potholes/train"). Thusdataset_dicts = get_street_dicts("/content/potholes/train")was not executed and sodataset_dictsis not defined ! You can re-start your notebook and re-run it should be fine. I could have said “restart your notebook and it’ll be fine”. But my point here is: take a little time to understand what’s going on. Don’t hesitate to dispatch each line in a cell and look at variables before and after running each cell to deeply understand each step. And I’m sure if you do that, you’ll not ask these questions again as you’ll find the answer. Best of luck.