Skip to content

Fix modelconverter analyze command - #271

Merged
klemen1999 merged 12 commits into
mainfrom
fix/analyze2
Aug 11, 2026
Merged

Fix modelconverter analyze command#271
klemen1999 merged 12 commits into
mainfrom
fix/analyze2

Conversation

@dtronmans

@dtronmans dtronmans commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Purpose

Order of fixes performed:

  1. The pre-created debug output directory that snpe-net-run --debug would use was "predicted" incorrectly. Solution: parse SNPE's missing-utput error, create the parent directory on-device then retry.
  2. --output-dir should have been passed to snpe-net-run (in the other RVC4 paths it is)
  3. Changed the analyze cycle to be sample-by-sample instead of one large debug pass because dumping every intermediate tensor for 256 all at once was too heavy
  • Added --image subset <num-images> parser argument to optionally limit the number of images used in the analyze loop.

Working usage now:

modelconverter analyze --dlc-model-path <dlc-model-path>.dlc --onnx-model-path <onnx-intermediate-path>.onnx --image-dirs <flat-dir-of-images> --device-ip <device-ip> --image-subset N

Specification

None / not applicable

Dependencies & Potential Impact

None / not applicable

Deployment Plan

None / not applicable

Testing & Validation

None / not applicable

AI Usage

Assisted-by: AGENT_NAME:MODEL_VERSION [TOOL1] [TOOL2]

Submitted code was reviewed by a human: YES/NO

The author is taking the responsibility for the contribution: YES/NO

Summary by CodeRabbit

  • New Features

    • Added an optional image limit for analysis runs.
    • Added support for PNG, JPG, JPEG, and NPY input files.
    • Added per-sample progress reporting and comparison statistics.
    • Analysis results can now be exported as CSV files.
    • Added configurable raw-input preparation and inference logging.
  • Bug Fixes

    • Improved handling of empty, invalid, or mismatched input sets.
    • Improved inference reliability by recovering from missing output directories.
    • Added clearer validation when an invalid image limit is provided.
  • Documentation

    • Clarified which DLC files to select for analysis.

@dtronmans
dtronmans requested a review from a team as a code owner August 7, 2026 09:56
@dtronmans
dtronmans requested review from klemen1999 and kozlov721 and removed request for a team August 7, 2026 09:56
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: fc178558-02ad-431c-97bd-297b74ebbff7

📥 Commits

Reviewing files that changed from the base of the PR and between 3cc5774 and 172b694.

📒 Files selected for processing (2)
  • README.md
  • modelconverter/packages/rvc4/analyze.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • modelconverter/packages/rvc4/analyze.py

📝 Walkthrough

Walkthrough

The analysis command now limits supported input files per directory. RVC4Analyzer processes samples individually, aggregates comparison statistics, writes CSV results, and retries DLC execution when output directories are missing. The README documents DLC selection.

Changes

RVC4 analysis workflow

Layer / File(s) Summary
Analysis input contract
modelconverter/__main__.py, modelconverter/packages/rvc4/analyze.py
analyze validates and forwards a positive image_subset. RVC4Analyzer filters supported inputs, applies the subset, and validates input sets.
Per-sample comparison workflow
modelconverter/packages/rvc4/analyze.py
Analysis prepares and processes each sample, collects comparison statistics, cleans temporary outputs, and writes aggregated CSV results.
DLC workspace execution and recovery
modelconverter/packages/rvc4/analyze.py, README.md
DLC execution uses centralized workspace paths, configurable logging, bounded output-directory retries, and an explicit cycle-analysis output directory. The README describes final and intermediate DLC selection.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant RVC4Analyzer
  participant SNPE_DLC
  participant ONNX_Session
  participant Comparison_CSV
  RVC4Analyzer->>RVC4Analyzer: Prepare one supported sample
  RVC4Analyzer->>SNPE_DLC: Execute DLC with output directory
  SNPE_DLC-->>RVC4Analyzer: Return inference outputs
  RVC4Analyzer->>ONNX_Session: Collect comparison statistics
  ONNX_Session-->>RVC4Analyzer: Return statistics
  RVC4Analyzer->>Comparison_CSV: Write aggregated results
Loading

Suggested reviewers: kozlov721

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: fixing the modelconverter analyze command.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/analyze2

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov-commenter

codecov-commenter commented Aug 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.98%. Comparing base (a050dd0) to head (172b694).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff            @@
##           main     #271       +/-   ##
=========================================
+ Coverage      0   99.98%   +99.98%     
=========================================
  Files         0       73       +73     
  Lines         0     5101     +5101     
=========================================
+ Hits          0     5100     +5100     
- Misses        0        1        +1     
Flag Coverage Δ
conversion 57.10% <ø> (?)
unit 71.08% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🧹 Nitpick comments (1)
modelconverter/packages/rvc4/analyze.py (1)

143-180: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Rename the type parameter.

type shadows the Python builtin and raises an A002 error. Rename it to dtype, update the annotation, and update the astype(...) call.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@modelconverter/packages/rvc4/analyze.py` around lines 143 - 180, Rename the
prepare-raw-inputs method parameter type to dtype, update its type annotation,
and replace both astype(type) usages with astype(dtype). Preserve the existing
input conversion behavior.

Source: Linters/SAST tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@modelconverter/packages/rvc4/analyze.py`:
- Around line 35-38: Update the analyzer initialization around self.image_subset
and Analyzer.__init__ so image_subset is assigned before base initialization.
Move or override the base size validation to count only paths accepted by
_prepare_input_matcher and restricted by image_subset, while preserving the
existing device setup and handler creation flow.
- Around line 114-118: Update the input-path comprehension in the analyzer to
require path.is_file() in addition to the supported suffix check, ensuring
directories with input-like extensions are excluded while valid files remain
included.

---

Nitpick comments:
In `@modelconverter/packages/rvc4/analyze.py`:
- Around line 143-180: Rename the prepare-raw-inputs method parameter type to
dtype, update its type annotation, and replace both astype(type) usages with
astype(dtype). Preserve the existing input conversion behavior.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c3940ca7-d214-4d0a-9c17-bd9d61e3932c

📥 Commits

Reviewing files that changed from the base of the PR and between a1778c8 and 89728a0.

📒 Files selected for processing (2)
  • modelconverter/__main__.py
  • modelconverter/packages/rvc4/analyze.py

Comment thread modelconverter/packages/rvc4/analyze.py Outdated
Comment thread modelconverter/packages/rvc4/analyze.py

@klemen1999 klemen1999 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'd propose a better flow overall. If I understand the code as is now correctly we are doing:

For each sample:
   try to guess the output structure
   if it fails parse through SNPE errors and create missing folders
   run snpe-net-run to create outputs
   copy outputs to host
   delete everything

But since we are dealing with the same model and we are just changin the inputs between samples I think a better flow would be:

one-time setup:
    push DLC
    create the dir structure on the device including output directories (use SNPE with a dummy/first input directly, don't need to even try to guess it with ONNX)

for each sample:
    replace staged input files and input_list.txt
    delete old output .raw files, but keep their parent directories
    run SNPE
    pull outputs to the host
    compare them locally
    delete local temporary output files

This way we are technically doing one more inference (the first dummy one) but we don't need to keep trying and guessing the structure for every sample.
Does this make sense?

Comment thread modelconverter/packages/rvc4/analyze.py Outdated
@klemen1999

Copy link
Copy Markdown
Collaborator

For CI fixes we need to merge in main branch

@klemen1999 klemen1999 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Generally LGTM, just two smaller mistakes

Comment thread modelconverter/packages/rvc4/analyze.py Outdated
Comment thread modelconverter/packages/rvc4/analyze.py Outdated
@klemen1999
klemen1999 merged commit d348886 into main Aug 11, 2026
13 checks passed
@klemen1999
klemen1999 deleted the fix/analyze2 branch August 11, 2026 13:20
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.

3 participants