Skip to content

Add MD5 validation for file downloads and pretrained weights handling - #679

Merged
Borda merged 20 commits into
developfrom
assets/md5
Feb 13, 2026
Merged

Borda merged 20 commits into
developfrom
assets/md5

Conversation

@Borda

@Borda Borda commented Feb 13, 2026

Copy link
Copy Markdown
Member

This pull request introduces a new, robust mechanism for handling model weight assets in the RF-DETR codebase. The main improvements are the introduction of a centralized ModelWeights registry with MD5 validation, enhanced and refactored download logic, and comprehensive unit tests to ensure reliability. These changes improve security, maintainability, and test coverage for model asset management.

Model asset management and download improvements:

  • Added src/rfdetr/assets/__init__.py and a new ModelWeights registry for model weight assets, centralizing model filename, URL, and MD5 hash metadata. This enables consistent access and validation across the codebase.
  • Refactored the model download logic: moved download_pretrain_weights to rfdetr.assets.model_weights, added MD5 hash validation, and updated the download process to use the new registry. The legacy dictionary is now used only for backward compatibility. [1] [2] [3] [4]
  • Enhanced the file download utility in src/rfdetr/util/files.py to support MD5 hash computation and validation, downloading to a temporary file, and improved logging. [1] [2]

Testing and validation:

  • Added a comprehensive test suite in tests/assets/test_downloads.py to cover all aspects of the new download and validation logic, including integration with rf-detr-plus, fallback behavior, error handling, and MD5 correctness.
  • Added license headers to new and existing files in the assets test directory.

CI/CD improvements:

  • Updated the GitHub Actions workflow: replaced the previous "Plus Re-export Import Check" with a new job that validates model instantiation and download using the new registry and logic. [1] [2]

Minor improvements:

  • Improved log messaging and warning handling for model inference and download status. [1] [2]

These changes make model asset management more secure, reliable, and maintainable, while also providing strong test coverage and improved developer experience.

Borda and others added 5 commits February 13, 2026 17:31
…sets module

Move model weights handling from main.py to new rfdetr.assets.model_weights module
to improve code organization and separation of concerns. Update imports across
affected modules to reference the new location.
@codecov

codecov Bot commented Feb 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.75000% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 58%. Comparing base (7d56fae) to head (4e753a9).
⚠️ Report is 2 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff           @@
##           develop   #679    +/-   ##
=======================================
+ Coverage       58%    58%    +1%     
=======================================
  Files           50     52     +2     
  Lines         6595   6733   +138     
=======================================
+ Hits          3805   3935   +130     
- Misses        2790   2798     +8     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Borda
Borda marked this pull request as ready for review February 13, 2026 15:12
Copilot AI review requested due to automatic review settings February 13, 2026 15:13
@Borda Borda added the enhancement New feature or request label Feb 13, 2026
@Borda
Borda requested review from Copilot and removed request for Copilot February 13, 2026 15:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This pull request introduces a comprehensive model weight asset management system with MD5 validation for RF-DETR. The changes centralize model metadata (filename, URL, MD5 hash) into a ModelWeights enum registry, refactor download logic with integrity validation, and add extensive test coverage for the new functionality.

Changes:

  • Introduced a new ModelWeights enum-based registry with ModelWeightAsset dataclass for centralized model asset management
  • Added MD5 hash computation and validation utilities to src/rfdetr/util/files.py with enhanced download logic
  • Refactored model download and validation logic with backward compatibility for legacy platform models
  • Added comprehensive unit tests for MD5 validation, model weights registry, and download flows
  • Updated CI workflow to validate model instantiation and downloads instead of just import checks

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
src/rfdetr/assets/__init__.py New public API exposing ModelWeights, ModelWeightAsset, and ModelWeightsBase
src/rfdetr/assets/model_weights.py Core implementation of model registry with enum-based assets, download logic with MD5 validation, and rf-detr-plus integration
src/rfdetr/util/files.py Added MD5 computation/validation functions and enhanced download with temporary file handling
src/rfdetr/main.py Integrated new model_weights module, added MD5 validation before loading, updated OPEN_SOURCE_MODELS for backward compatibility
src/rfdetr/detr.py Updated import to use download_pretrain_weights from assets module, minor log message formatting
tests/assets/__init__.py Test package initialization with license header
tests/assets/test_model_weights.py Unit tests for ModelWeights enum methods and asset validation
tests/assets/test_downloads.py Comprehensive mocked tests for download logic including priority order, MD5 validation, and error handling
tests/util/test_file_validation.py Unit tests for MD5 computation and validation functions
tests/try_instantiate_all_models.py Integration script to validate all model downloads and instantiation
.github/workflows/ci-integrations.yml Updated CI job to run model instantiation validation instead of simple import check

Comment thread src/rfdetr/util/files.py Outdated
Comment thread src/rfdetr/util/files.py Outdated
Comment thread tests/try_instantiate_all_models.py Outdated
Comment thread src/rfdetr/util/files.py Outdated
Comment thread src/rfdetr/util/files.py
Comment thread tests/assets/test_downloads.py Outdated
Comment thread src/rfdetr/util/files.py Outdated
Comment thread .github/workflows/ci-integrations.yml
Comment thread src/rfdetr/util/files.py
Comment thread tests/util/test_file_validation.py
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@Borda
Borda merged commit 05bbdb5 into develop Feb 13, 2026
23 checks passed
@Borda
Borda deleted the assets/md5 branch February 13, 2026 16:48
Borda added a commit that referenced this pull request Feb 16, 2026
…#679)

* Add MD5 validation for file downloads and pretrained weights handling
* refactor(assets): extract model weights functionality to dedicated assets module
* Move model weights handling from main.py to new rfdetr.assets.model_weights module
to improve code organization and separation of concerns. Update imports across
affected modules to reference the new location.
* refactor(main, model_weights): move and reuse weight validation logic
* test(util, download): add comprehensive tests for MD5 validation and file download logic
* fix(pre-commit): 🎨 auto format pre-commit hooks
* Apply suggestions from code review

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Borda added a commit that referenced this pull request Feb 16, 2026
…#679)

* Add MD5 validation for file downloads and pretrained weights handling
* refactor(assets): extract model weights functionality to dedicated assets module
* Move model weights handling from main.py to new rfdetr.assets.model_weights module
to improve code organization and separation of concerns. Update imports across
affected modules to reference the new location.
* refactor(main, model_weights): move and reuse weight validation logic
* test(util, download): add comprehensive tests for MD5 validation and file download logic
* fix(pre-commit): 🎨 auto format pre-commit hooks
* Apply suggestions from code review

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Borda added a commit that referenced this pull request Mar 13, 2026
…#679)

* Add MD5 validation for file downloads and pretrained weights handling
* refactor(assets): extract model weights functionality to dedicated assets module
* Move model weights handling from main.py to new rfdetr.assets.model_weights module
to improve code organization and separation of concerns. Update imports across
affected modules to reference the new location.
* refactor(main, model_weights): move and reuse weight validation logic
* test(util, download): add comprehensive tests for MD5 validation and file download logic
* fix(pre-commit): 🎨 auto format pre-commit hooks
* Apply suggestions from code review

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants