Skip to content

Fix BatchNormLayer::Reshape crash on 1-axis blobs#7101

Open
Chessing234 wants to merge 1 commit intoBVLC:masterfrom
Chessing234:fix/batch-norm-reshape-axis-guard
Open

Fix BatchNormLayer::Reshape crash on 1-axis blobs#7101
Chessing234 wants to merge 1 commit intoBVLC:masterfrom
Chessing234:fix/batch-norm-reshape-axis-guard

Conversation

@Chessing234
Copy link
Copy Markdown

Bug

In BatchNormLayer::Reshape, line 54:

if (bottom[0]->num_axes() >= 1)
    CHECK_EQ(bottom[0]->shape(1), channels_);

When a blob has exactly 1 axis, shape(1) calls CanonicalAxisIndex(1) which triggers CHECK_LT(1, 1) and aborts.

Root cause

The guard should be >= 2, not >= 1. LayerSetUp (lines 17-20) correctly handles 1-axis blobs by checking num_axes() == 1 and setting channels_ = 1 without accessing shape(1).

Fix

Changed >= 1 to >= 2 to match the minimum axes needed for shape(1).

🤖 Generated with Claude Code

The guard condition uses num_axes() >= 1, but shape(1) requires at
least 2 axes. With exactly 1 axis, shape(1) calls CanonicalAxisIndex(1)
which triggers CHECK_LT(1, 1) and aborts. LayerSetUp correctly handles
this case with num_axes() == 1 at line 17.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

1 participant