Skip to content

fix: always set class_names from dataset annotations#518

Draft
lixiaolei1982 wants to merge 2 commits intoroboflow:developfrom
lixiaolei1982:fix-train-config-class-names-assignment
Draft

fix: always set class_names from dataset annotations#518
lixiaolei1982 wants to merge 2 commits intoroboflow:developfrom
lixiaolei1982:fix-train-config-class-names-assignment

Conversation

@lixiaolei1982
Copy link
Contributor

  • Remove conditional check that only set class_names when None
  • Unconditionally assign dataset-derived class_names to train_config
  • Ensure consistency between dataset annotations and training configuration

Description

The current code in train_from_config method contains an incorrect conditional check:
if "class_names" in train_config and train_config["class_names"] is None:
train_config["class_names"] = class_names

This logic is flawed because:
1.It only sets class_names when it already exists in train_config AND is None
2.It doesn't handle the case where class_names might not exist in train_config at all
3.It doesn't override potentially incorrect class_names values that are non-None

The correct behavior should be to always set train_config["class_names"] to the class_names variable derived from the dataset (Roboflow or COCO), ensuring consistency between the dataset annotations and the training configuration.

#Changes:

Remove the conditional check and unconditionally set train_config["class_names"] = class_names
This ensures the class names from the actual dataset annotations are always used for training

#Impact:

Fixes potential mismatches between dataset classes and training configuration
Ensures consistent behavior regardless of initial train_config["class_names"] value
Maintains backward compatibility while fixing the logic error

- Remove conditional check that only set class_names when None
- Unconditionally assign dataset-derived class_names to train_config
- Ensure consistency between dataset annotations and training configuration
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a logic flaw in the train_from_config method where class names from the dataset annotations were only conditionally assigned to the training configuration. The change ensures that class names derived from the dataset are always used, maintaining consistency between dataset annotations and training configuration.

Changes:

  • Remove conditional check that only set class_names when it existed and was None
  • Unconditionally assign dataset-derived class_names to train_config

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Borda Borda added the bug Something isn't working label Jan 22, 2026
@Borda Borda requested a review from isaacrob as a code owner February 11, 2026 15:57
@Borda Borda force-pushed the develop branch 4 times, most recently from 60b16c1 to 523f9df Compare February 14, 2026 06:46
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@Borda
Copy link
Member

Borda commented Feb 18, 2026

@lixiaolei1982, could you please elaborate on why the actual behaviour is wrong?

@Borda Borda marked this pull request as draft February 18, 2026 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working has conflicts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments