Skip to content

Conversation

@lixiaolei1982
Copy link

  • 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.


if "class_names" in train_config and train_config["class_names"] is None:
train_config["class_names"] = class_names
#if "class_names" in train_config and train_config["class_names"] is None:
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

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

Instead of commenting out the old code, consider removing it entirely. Commented-out code can lead to confusion and should generally be avoided in production code. The version control system preserves the history if the old implementation needs to be referenced.

Suggested change
#if "class_names" in train_config and train_config["class_names"] is None:

Copilot uses AI. Check for mistakes.
@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
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