Skip to content

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

Open
davidnichols-ops wants to merge 1 commit 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 1 commit 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

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

CLAassistant commented Jun 13, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@davidnichols-ops davidnichols-ops force-pushed the fix/preserve-class-order branch from 1ac9429 to 5d90f88 Compare June 14, 2026 20:38
@davidnichols-ops

Copy link
Copy Markdown
Author

Roboflow team,
Thank you for your consideration of my contribution. The CLA should be in order, and I really appreicate the level of use this tool gives to the broader global community. If there is anything I can do, I can share more about why I think this would be a good addition to this SDK. You can reach me via github or Gmail with any questions and I will get back to you as soon as I can.

Best,

David Nichols

@davidnichols-ops davidnichols-ops force-pushed the fix/preserve-class-order branch from d4fc251 to 5d90f88 Compare June 19, 2026 21:05
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.
@davidnichols-ops davidnichols-ops force-pushed the fix/preserve-class-order branch from c500b4b to 382445a Compare June 19, 2026 21:14
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