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
Excuse me, I trained a 5-class detection model with RT-DETR, but reported exceeding the category during inference. How can this error be resolved #12563
Comments
👋 Hello @Shybert-AI, thank you for your interest in Ultralytics YOLOv8 🚀! We recommend a visit to the Docs for new users where you can find many Python and CLI usage examples and where many of the most common questions may already be answered. If this is a 🐛 Bug Report, please provide a minimum reproducible example to help us debug it. If this is a custom training ❓ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results. Join the vibrant Ultralytics Discord 🎧 community for real-time conversations and collaborations. This platform offers a perfect space to inquire, showcase your work, and connect with fellow Ultralytics users. InstallPip install the pip install ultralytics EnvironmentsYOLOv8 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):
StatusIf this badge is green, all Ultralytics CI tests are currently passing. CI tests verify correct operation of all YOLOv8 Modes and Tasks on macOS, Windows, and Ubuntu every 24 hours and on every commit. |
Hello! It seems like the model is encountering a "KeyError" which typically suggests that there's a mismatch in the number of classes between the trained model and the class names provided during inference. Ensure that your class names file (often labeled Here’s a basic checklist:
If everything appears correct and the error persists, consider re-exporting or re-saving your model configuration. Let me know how it goes, or if there's anything else you need help with! 🚀 |
yolo detect predict model=./runs/detect/train/weights/best.pt source="00001.jpg" replacefrom ultralytics import YOLO,RTDETR |
Hello! I'm glad to hear that the issue has been resolved 🌟! The method you used to perform inference through the Python script is indeed a great alternative if you encounter issues with the command line. It also provides more flexibility for post-processing and handling the results. Thanks for sharing your solution; it could be helpful to others facing similar problems. If there's anything more we can assist you with, don't hesitate to ask. Happy detecting! 🚀 |
Search before asking
YOLOv8 Component
No response
Bug
D:\mywork\pythonProject\yolov8>yolo task=detect mode=predict model="./runs/detect/train12/weights/last.pt" conf=0.25 source="00001.jpg"
Ultralytics YOLOv8.0.131 Python-3.11.5 torch-2.2.2+cu121 CUDA:0 (NVIDIA GeForce RTX 4080 SUPER, 16376MiB)
rtdetr-l summary: 498 layers, 31994015 parameters, 0 gradients
Traceback (most recent call last):
File "", line 198, in run_module_as_main
File "", line 88, in run_code
File "D:\software\anaconda\Scripts\yolo.exe_main.py", line 7, in
File "D:\software\anaconda\Lib\site-packages\ultralytics\yolo\cfg_init.py", line 411, in entrypoint
getattr(model, mode)(**overrides) # default args from model
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\software\anaconda\Lib\site-packages\torch\utils_contextlib.py", line 115, in decorate_context
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "D:\software\anaconda\Lib\site-packages\ultralytics\yolo\engine\model.py", line 255, in predict
return self.predictor.predict_cli(source=source) if is_cli else self.predictor(source=source, stream=stream)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\software\anaconda\Lib\site-packages\ultralytics\yolo\engine\predictor.py", line 195, in predict_cli
for _ in gen: # running CLI inference without accumulating any outputs (do not modify)
File "D:\software\anaconda\Lib\site-packages\torch\utils_contextlib.py", line 35, in generator_context
response = gen.send(None)
^^^^^^^^^^^^^^
File "D:\software\anaconda\Lib\site-packages\ultralytics\yolo\engine\predictor.py", line 267, in stream_inference
s += self.write_results(i, self.results, (p, im, im0))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\software\anaconda\Lib\site-packages\ultralytics\yolo\engine\predictor.py", line 161, in write_results
log_string += result.verbose()
^^^^^^^^^^^^^^^^
File "D:\software\anaconda\Lib\site-packages\ultralytics\yolo\engine\results.py", line 265, in verbose
log_string += f"{n} {self.names[int(c)]}{'s' * (n > 1)}, "
~~~~~~~~~~^^^^^^^^
KeyError: 196
Environment
No response
Minimal Reproducible Example
No response
Additional
No response
Are you willing to submit a PR?
The text was updated successfully, but these errors were encountered: