YOLOv8 Final Detection Head Still Outputs (1, 7, 8400) Instead of (1, 8, 8400) for 3 Classes #19107
Replies: 4 comments 3 replies
-
👋 Hello @Saleh-1987, thank you for bringing this to our attention and for your detailed explanation 🚀! It seems like you’re encountering an issue with the detection head output not aligning with the number of classes defined during training. We recommend double-checking a few key areas to help diagnose the problem, and here’s how you can proceed:
If the issue persists, you might also want to reset and reinitialize your train scripts or checkpoints to ensure no residual configurations are affecting the outputs. Community Support 🌟You can also engage with the Ultralytics community for insights and ideas:
Verified EnvironmentsEnsure you’re working within a verified environment for YOLO. Options include:
This is an automated response 🤖, but rest assured that an Ultralytics engineer will review your issue and provide additional assistance soon! Thank you for your patience and for contributing to the Ultralytics community ❤️. |
Beta Was this translation helpful? Give feedback.
-
It appears that the updated class count wasn’t properly applied during model construction, so please ensure the training configuration (including nc) is correctly used when building and saving the model. |
Beta Was this translation helpful? Give feedback.
-
4 coordinates + 3 class scores = 7 It's correct. |
Beta Was this translation helpful? Give feedback.
-
YOLOv8 does not include an explicit objectness score. Instead, class probabilities already incorporate object confidence. Hence, the (1, 7, 8400) is correct. |
Beta Was this translation helpful? Give feedback.
-
I trained a YOLOv8 detection model with 3 classes, but the raw forward pass still shows a final detect output of (1, 7, 8400) instead of (1, 8, 8400).
What I’ve Done:
Checked my data.yaml:
Confirmed nc: 3 is correct.
Trained from scratch with the command:
The training runs without error and completes successfully.
Installed the latest Ultralytics version (v8.3.72) to ensure no version issues:
Loaded the new best.pt directly:
The console shows (1, 7, 8400) for the detection output.
Verified model metadata says nc=3 and model.names has 3 classes. However, the raw detect layer output is still 7 channels.
Observations:
If a YOLO detect layer is genuinely for 3 classes, it should output (5 + 3)=8 channels per anchor, not 7.
The mismatch (1, 7, 8400) typically indicates it’s still set for 2 classes despite nc=3.
Question / Request for Help:
Why is the raw detect head still (1, 7, 8400) even though I trained from scratch for 3 classes?
How can I ensure the detect layer is fully re-initialized to (5 + 3)=8 for 3-class detection?
I’ve tried deleting old .pt files, re-checking my data.yaml, reinstalling ultralytics, and confirming model.model.nc == 3. But the final detect layer continues to yield 7 channels instead of 8.
Any ideas on what might cause this persistent mismatch?
Thanks in advance for any help or insights!
Beta Was this translation helpful? Give feedback.
All reactions