Skip to content

Fix the PPLCNetV3 detection backbone channel count - #446

Merged
kozlov721 merged 2 commits into
mainfrom
fix/pplcnet-detection-backbone
Sep 7, 2026
Merged

Fix the PPLCNetV3 detection backbone channel count#446
kozlov721 merged 2 commits into
mainfrom
fix/pplcnet-detection-backbone

Conversation

@kozlov721

@kozlov721 kozlov721 commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator

Purpose

PPLCNetV3 crashes when a configuration sets use_detection_backbone
to true. The detection branch has never worked. This PR corrects the
channel count and adds the tests that the branch never had.

The PR also unblocks the codecov check on #443. That PR renames
detecion_blocks to detection_blocks and corrects an "initalized"
typo in EMACallback. Both renamed lines sit in untested code, so
codecov counts them as missed and fails codecov/patch. The new tests
cover them.

Specification

  • Use the block widths directly in the PPLCNetV3 detection backbone.
    LCNetV3Layer scales its out_channels in the constructor. The
    backbone scaled the same value a second time:

    blocks_out_channels = [
        scale_up(blocks[i].out_channels, self.scale) for i in range(1, 5)
    ]

    The rec-light variant uses the scale 0.95. The second scale turns
    the true block widths [64, 128, 240, 480] into
    [64, 128, 224, 464]. The detection convolutions then expect 224
    channels, but the blocks give 240:

    RuntimeError: Given groups=1, weight of size [53, 224, 1, 1],
    expected input[2, 240, 6, 40] to have 224 channels,
    but got 240 channels instead
    
  • Add tests/unittests/test_pplcnet_v3.py. It covers the two backbone
    modes:

    • The recognition mode gives 5 outputs. The last output is pooled to
      (1, max_text_len).
    • The detection mode gives 4 outputs with the widths
      [15, 22, 53, 456].
  • Add test_ema_before_fit_start. It covers the EMACallback.ema
    guard. The guard raises before on_fit_start builds the model.

No variant sets use_detection_backbone to true. No test covered
the branch. The defect stayed hidden for these two reasons.

Dependencies & Potential Impact

  • Not breaking. The detection branch raised a RuntimeError before
    this change. No configuration can depend on the old widths.
  • The change does not touch the recognition path. The
    ocr_recognition predefined model uses that path.
  • The tests read only the forward outputs. They do not name the
    detecion_blocks attribute. Pre-docs cleanup: fix the typo'd names and tighten the lint gate #443 can thus rename the attribute
    without a test change.
  • No dependency changes.

Deployment Plan

None / not applicable — the changes ship with the next release.

Testing & Validation

  • test_detection_backbone fails on main with the RuntimeError
    above. It passes with this change.
  • pytest tests/unittests: 508 passed. The run excludes
    tests/unittests/test_losses, which holds the known expired
    gcloud-ADC failures.
  • The pre-commit hooks ran on both commits. All hooks pass.
  • pyright --warnings: at parity with main. The one error is the
    pre-existing aimet_torch import from the optional extra.

AI Usage

Assisted-by: Claude:claude-opus-5

Submitted code was reviewed by a human: NO

The author is taking the responsibility for the contribution: YES

🤖 Generated with Claude Code

https://claude.ai/code/session_01QA7RcK3rsE5mHX7J6X1Vxh

Summary by CodeRabbit

  • Bug Fixes

    • Corrected channel sizing in the PPLCNetV3 detection backbone to ensure detection features have the expected dimensions.
    • Improved EMA callback behavior when accessed before training initialization by providing a clear error.
  • Tests

    • Added coverage for PPLCNetV3 recognition and detection outputs, including feature dimensions.
    • Added validation for EMA access before training begins.

@kozlov721
kozlov721 requested a review from a team as a code owner September 6, 2026 21:34
@kozlov721
kozlov721 requested review from klemen1999 and removed request for a team September 6, 2026 21:34
@github-actions github-actions Bot added the fix Fixing a bug label Sep 6, 2026
@coderabbitai

coderabbitai Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

Next included review available in 15 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: de908298-15b9-4c94-8662-6f98f57a1503

📥 Commits

Reviewing files that changed from the base of the PR and between 0fb0481 and 8033ee5.

📒 Files selected for processing (1)
  • tests/unittests/test_pplcnet_v3.py

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: 0499220b-afe3-4973-a688-31ef34aa303f

📥 Commits

Reviewing files that changed from the base of the PR and between 407c6a1 and 0fb0481.

📒 Files selected for processing (1)
  • luxonis_train/nodes/backbones/pplcnet_v3/pplcnet_v3.py

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The change removes redundant PPLCNetV3 channel scaling and adds tests for recognition, detection, and EMA initialization behavior.

Changes

PPLCNetV3 backbone validation

Layer / File(s) Summary
Detection channel construction
luxonis_train/nodes/backbones/pplcnet_v3/pplcnet_v3.py
blocks_out_channels now uses block output channels without applying a second scale.
Backbone output tests
tests/unittests/test_pplcnet_v3.py
Tests validate recognition output dimensions and detection feature channel widths for the rec-light backbone.

EMA callback initialization

Layer / File(s) Summary
EMA initialization test
tests/unittests/test_callbacks/test_ema.py
The test verifies that accessing ema before on_fit_start raises ValueError with the expected message.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 0fb04

The detection backbone now uses the actual layer output widths, preventing channel mismatches during detection model construction. Recognition behavior remains covered, and the change is ready to merge.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: fixing the PPLCNetV3 detection backbone channel count.
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 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/pplcnet-detection-backbone

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

codecov Bot commented Sep 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.61%. Comparing base (3c668bd) to head (8033ee5).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff            @@
##           main     #446       +/-   ##
=========================================
+ Coverage      0   94.61%   +94.61%     
=========================================
  Files         0      290      +290     
  Lines         0    15868    +15868     
=========================================
+ Hits          0    15013    +15013     
- Misses        0      855      +855     
Flag Coverage Δ
pytest 94.61% <100.00%> (?)

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.

@kozlov721
kozlov721 force-pushed the fix/pplcnet-detection-backbone branch 2 times, most recently from 0fb0481 to 2e18780 Compare September 6, 2026 23:00
kozlov721 and others added 2 commits September 7, 2026 01:35
`LCNetV3Layer` scales its `out_channels` in the constructor. The backbone scaled that value a second time. The detection convolutions then expected 224 channels, but the blocks gave 240. A config with `use_detection_backbone: true` crashed for this reason.

Use the block widths directly. Add a unit test for both backbone modes.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QA7RcK3rsE5mHX7J6X1Vxh
`EMACallback.ema` raises before `on_fit_start` builds the model. No test covered that path.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QA7RcK3rsE5mHX7J6X1Vxh
@kozlov721
kozlov721 force-pushed the fix/pplcnet-detection-backbone branch from 2e18780 to 8033ee5 Compare September 6, 2026 23:35
@kozlov721
kozlov721 merged commit 795f485 into main Sep 7, 2026
16 checks passed
@kozlov721
kozlov721 deleted the fix/pplcnet-detection-backbone branch September 7, 2026 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Fixing a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants