Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I use a custom dataset for training? #186

Closed
ma3252788 opened this issue Jan 10, 2023 · 11 comments
Closed

How can I use a custom dataset for training? #186

ma3252788 opened this issue Jan 10, 2023 · 11 comments
Labels
documentation Improvements or additions to documentation

Comments

@ma3252788
Copy link

How can I use a custom dataset for training?

I have made the data in COCO2017 format, but the number of classes and class names are different from COCO, which file should I change?

@rentainhe
Copy link
Collaborator

How can I use a custom dataset for training?

I have made the data in COCO2017 format, but the number of classes and class names are different from COCO, which file should I change?

You can use this functions: register_coco_instances to register your dataset in config file, and then update the dataset name

@rentainhe
Copy link
Collaborator

rentainhe commented Jan 11, 2023

Here is an example:

# dataset config
from detectron2.data.datasets import register_coco_instances

register_coco_instances("my_dataset", {}, "path/to/json", "path/to/image_root") 

dataloader.train = L(build_detection_train_loader)(
    dataset=L(get_detection_dataset_dicts)(names="my_dataset"),
    ...

@rentainhe rentainhe added enhancement New feature or request documentation Improvements or additions to documentation and removed enhancement New feature or request labels Jan 11, 2023
@rentainhe
Copy link
Collaborator

rentainhe commented Jan 11, 2023

Please refer to custom.py to see how to register and use coco-like datasets in detrex and d2~

@ma3252788
Copy link
Author

Here is an example:

# dataset config
from detectron2.data.datasets import register_coco_instances

register_coco_instances("my_dataset", {}, "path/to/json", "path/to/image_root") 

dataloader.train = L(build_detection_train_loader)(
    dataset=L(get_detection_dataset_dicts)(names="my_dataset"),
    ...

I see. Thank you very much for your reply.

@rentainhe
Copy link
Collaborator

Here is an example:

# dataset config
from detectron2.data.datasets import register_coco_instances

register_coco_instances("my_dataset", {}, "path/to/json", "path/to/image_root") 

dataloader.train = L(build_detection_train_loader)(
    dataset=L(get_detection_dataset_dicts)(names="my_dataset"),
    ...

I see. Thank you very much for your reply.

You're welcome~

@sjtu-cz
Copy link

sjtu-cz commented Feb 28, 2023

File "/workspace/detrex/detectron2/detectron2/evaluation/coco_evaluation.py", line 240, in _eval_predictions
assert category_id < num_classes, (
AssertionError: A prediction has class=14, but the dataset only has 11 classes and predicted class id should be in [0, 10].

I use a custom dataset for training, but meet the error.

@FrostbiteLee
Copy link

File "/workspace/detrex/detectron2/detectron2/evaluation/coco_evaluation.py", line 240, in _eval_predictions assert category_id < num_classes, ( AssertionError: A prediction has class=14, but the dataset only has 11 classes and predicted class id should be in [0, 10].

I use a custom dataset for training, but meet the error.

I had the same problem. I need help.

@xiaolizai
Copy link

File "/workspace/detrex/detectron2/detectron2/evaluation/coco_evaluation.py", line 240, in _eval_predictions assert category_id < num_classes, ( AssertionError: A prediction has class=14, but the dataset only has 11 classes and predicted class id should be in [0, 10].

I use a custom dataset for training, but meet the error.

Maybe can help you. #267 (comment)

@sjtu-cz
Copy link

sjtu-cz commented Jul 21, 2023 via email

@wwzstudy
Copy link

After modifying the custom.py file, run python tools/train_net.py --config-file projects/dab_detr/configs/models/dab_detr_r50.py, A Missing key train error occurred
full_key: train
object_type=dict

@wwzstudy
Copy link

ERROR [09/30 16:04:15 d2.config.instantiate]: Error when instantiating detectron2.data.build.build_detection_train_loader!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

6 participants