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

AssertionError: A prediction has class=10, but the dataset only has 10 classes and predicted class id should be in [0, 9]. #5103

Open
mahilaMoghadami opened this issue Oct 4, 2023 · 5 comments
Labels
documentation Problems about existing documentation or comments

Comments

@mahilaMoghadami
Copy link

File "train_fcos.py", line 89, in
launch(
File "/home/mahilamoghadami.mut/miniconda3/envs/CZDET/lib/python3.8/site-packages/detectron2/engine/launch.py", line 82, in launch
main_func(*args)
File "train_fcos.py", line 80, in main
return trainer.train()
File "/home/mahilamoghadami.mut/miniconda3/envs/CZDET/lib/python3.8/site-packages/detectron2/engine/defaults.py", line 484, in train
super().train(self.start_iter, self.max_iter)
File "/home/mahilamoghadami.mut/miniconda3/envs/CZDET/lib/python3.8/site-packages/detectron2/engine/train_loop.py", line 150, in train
self.after_step()
File "/home/mahilamoghadami.mut/miniconda3/envs/CZDET/lib/python3.8/site-packages/detectron2/engine/train_loop.py", line 180, in after_step
h.after_step()
File "/home/mahilamoghadami.mut/miniconda3/envs/CZDET/lib/python3.8/site-packages/detectron2/engine/hooks.py", line 552, in after_step
self._do_eval()
File "/home/mahilamoghadami.mut/miniconda3/envs/CZDET/lib/python3.8/site-packages/detectron2/engine/hooks.py", line 525, in _do_eval
results = self._func()
File "/home/mahilamoghadami.mut/CZDet/DroneDetectron2/croptrain/engine/trainer_fcos.py", line 234, in test_and_save_results
self._last_eval_results = self.test_crop(self.cfg, self.model, self.iter)
File "/home/mahilamoghadami.mut/CZDet/DroneDetectron2/croptrain/engine/trainer_fcos.py", line 278, in test_crop
results_i = inference_fcos.inference_with_crops(model, data_loader, evaluator, cfg, iter)
File "/home/mahilamoghadami.mut/CZDet/DroneDetectron2/croptrain/engine/inference_fcos.py", line 124, in inference_with_crops
results = evaluator.evaluate()
File "/home/mahilamoghadami.mut/miniconda3/envs/CZDET/lib/python3.8/site-packages/detectron2/evaluation/coco_evaluation.py", line 194, in evaluate
self._eval_predictions(predictions, img_ids=img_ids)
File "/home/mahilamoghadami.mut/miniconda3/envs/CZDET/lib/python3.8/site-packages/detectron2/evaluation/coco_evaluation.py", line 228, in _eval_predictions
assert category_id < num_classes, (
**AssertionError: A prediction has class=10, but the dataset only has 10 classes and predicted class id should be in [0, 9].

AssertionError: A prediction has class=10, but the dataset only has 10 classes and predicted class id should be in [0, 9].**

@mahilaMoghadami mahilaMoghadami added the documentation Problems about existing documentation or comments label Oct 4, 2023
@olivia632
Copy link

how can i contribute to this

@pevers
Copy link

pevers commented Dec 30, 2023

@mahilaMoghadami make sure you have set cfg.MODEL.ROI_HEADS.NUM_CLASSES correctly. If your model predicts too many classes then there are categories available in your COCO dataset, it will fail with this error.

@weirgmat
Copy link

File "train_fcos.py", line 89, in launch( File "/home/mahilamoghadami.mut/miniconda3/envs/CZDET/lib/python3.8/site-packages/detectron2/engine/launch.py", line 82, in launch main_func(*args) File "train_fcos.py", line 80, in main return trainer.train() File "/home/mahilamoghadami.mut/miniconda3/envs/CZDET/lib/python3.8/site-packages/detectron2/engine/defaults.py", line 484, in train super().train(self.start_iter, self.max_iter) File "/home/mahilamoghadami.mut/miniconda3/envs/CZDET/lib/python3.8/site-packages/detectron2/engine/train_loop.py", line 150, in train self.after_step() File "/home/mahilamoghadami.mut/miniconda3/envs/CZDET/lib/python3.8/site-packages/detectron2/engine/train_loop.py", line 180, in after_step h.after_step() File "/home/mahilamoghadami.mut/miniconda3/envs/CZDET/lib/python3.8/site-packages/detectron2/engine/hooks.py", line 552, in after_step self._do_eval() File "/home/mahilamoghadami.mut/miniconda3/envs/CZDET/lib/python3.8/site-packages/detectron2/engine/hooks.py", line 525, in _do_eval results = self._func() File "/home/mahilamoghadami.mut/CZDet/DroneDetectron2/croptrain/engine/trainer_fcos.py", line 234, in test_and_save_results self._last_eval_results = self.test_crop(self.cfg, self.model, self.iter) File "/home/mahilamoghadami.mut/CZDet/DroneDetectron2/croptrain/engine/trainer_fcos.py", line 278, in test_crop results_i = inference_fcos.inference_with_crops(model, data_loader, evaluator, cfg, iter) File "/home/mahilamoghadami.mut/CZDet/DroneDetectron2/croptrain/engine/inference_fcos.py", line 124, in inference_with_crops results = evaluator.evaluate() File "/home/mahilamoghadami.mut/miniconda3/envs/CZDET/lib/python3.8/site-packages/detectron2/evaluation/coco_evaluation.py", line 194, in evaluate self._eval_predictions(predictions, img_ids=img_ids) File "/home/mahilamoghadami.mut/miniconda3/envs/CZDET/lib/python3.8/site-packages/detectron2/evaluation/coco_evaluation.py", line 228, in _eval_predictions assert category_id < num_classes, ( **AssertionError: A prediction has class=10, but the dataset only has 10 classes and predicted class id should be in [0, 9].

AssertionError: A prediction has class=10, but the dataset only has 10 classes and predicted class id should be in [0, 9].**

Hello, have you resolved this issue? How to solve it? thanks

@clairelin23
Copy link

I also get the same problem despite setting ROI_HEADS.

@Godk02
Copy link

Godk02 commented May 14, 2024

Had anyone solved this problem?

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

No branches or pull requests

7 participants
@pevers @clairelin23 @mahilaMoghadami @weirgmat @olivia632 @Godk02 and others