Skip to content

feat: add option to preserve class ordering during model deployment#493

Open
davidnichols-ops wants to merge 3 commits into
roboflow:mainfrom
davidnichols-ops:fix/preserve-class-order
Open

feat: add option to preserve class ordering during model deployment#493
davidnichols-ops wants to merge 3 commits into
roboflow:mainfrom
davidnichols-ops:fix/preserve-class-order

Conversation

@davidnichols-ops

Copy link
Copy Markdown

Summary

Add DISABLE_CLASS_SORTING configuration option to prevent automatic alphabetical sorting of class names during YOLO model deployment. Users can set ROBOFLOW_DISABLE_CLASS_SORTING=true to maintain custom class ordering from model checkpoints.

Changes

  • Added DISABLE_CLASS_SORTING to config.py (defaults to false)
  • Updated model_processor.py to conditionally apply sorting based on configuration
  • Added warning comment about user responsibility for proper class ordering
  • Maintains backwards compatibility (defaults to current sorting behavior)

Usage

export ROBOFLOW_DISABLE_CLASS_SORTING=true
python your_deploy_script.py

Testing

  • Verified configuration imports correctly with default value False
  • No syntax errors in modified files
  • Existing behavior preserved when config is not set

Impact

  • Files Modified: 2 (config.py, model_processor.py)
  • Lines Changed: 4 (1 config line, 1 import line, 2 logic lines)
  • API Changes: 0
  • Breaking Changes: 0
  • Risk Level: Very Low (opt-in only, defaults to current behavior)

Note

I used Devin (AI coding assistant) to help author this implementation, but I have verified the changes work correctly and follow the project's existing patterns and conventions.

davidnichols-ops and others added 3 commits June 13, 2026 00:09
Add DISABLE_CLASS_SORTING configuration option to prevent automatic
alphabetical sorting of class names during YOLO model deployment.
Users can set ROBOFLOW_DISABLE_CLASS_SORTING=true to maintain custom
class ordering from model checkpoints.

- Add DISABLE_CLASS_SORTING to config.py (defaults to false)
- Update model_processor.py to conditionally apply sorting
- Include warning comment about user responsibility for proper class ordering
- Maintain backwards compatibility with default behavior

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
- Add test suite for DISABLE_CLASS_SORTING configuration
- Test default value, environment variable parsing, and case insensitivity
- Update CHANGELOG.md with new feature entry

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@davidnichols-ops

Copy link
Copy Markdown
Author

Testing performed:

✅ Config imports correctly with default value False
✅ Environment variable parsing works (ROBOFLOW_DISABLE_CLASS_SORTING=true/false)
✅ Case-insensitive environment variable handling (True/TRUE/tRuE all work)
✅ Sorting is bypassed when enabled, applied when disabled (code inspection)
✅ Only affects dict-based class names in _process_yolo() (the problematic path)
✅ Backward compatible — current behavior unchanged by default
✅ Added comprehensive test suite for configuration

Known limitations:

  • Only applies to _process_yolo() (other model types don't have this alphabetical sorting issue)
  • Users must ensure their model's names dict has properly ordered keys when using this flag
  • Feature is opt-in via environment variable to prevent accidental breaking changes

Usage example:

export ROBOFLOW_DISABLE_CLASS_SORTING=true
python deploy_script.py

This feature addresses the need to preserve custom class ordering in YOLO models during deployment, which is important for workflows where class indices have specific meaning or when models have been trained with non-standard class ordering.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ davidnichols-ops
❌ pre-commit-ci[bot]


davidnichols-ops seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants