Skip to content

fix(examples): QuantVGG classifier in_features after TruncAvgPool2d (#1500) - #1630

Open
tonycoder-hub wants to merge 1 commit into
Xilinx:masterfrom
tonycoder-hub:fix/quant-vgg-classifier-in-features-1500
Open

tonycoder-hub wants to merge 1 commit into
Xilinx:masterfrom
tonycoder-hub:fix/quant-vgg-classifier-in-features-1500

Conversation

@tonycoder-hub

Copy link
Copy Markdown

Summary

Fixes #1500.

QuantVGG uses TruncAvgPool2d(kernel_size=(7, 7), stride=1) after VGG's five MaxPool2d layers (224→7 spatial). That pool collapses 7×7 to 1×1, so torch.flatten(x, 1) has size 512, not 512 * 7 * 7.

The previous QuantLinear(512 * 7 * 7, 4096, …) matched torchvision VGG, which keeps 7×7 via AdaptiveAvgPool2d((7, 7)). With TruncAvgPool2d it raises a shape mismatch on any standard 224×224 input.

Changes

  • Set the first classifier QuantLinear in_features to 512.
  • Add tests/brevitas_examples/test_quant_vgg_shape.py — forward quant_vgg11 on (2, 3, 224, 224) and assert (2, 1000).

Test plan

  • pytest tests/brevitas_examples/test_quant_vgg_shape.py -q
  • Manual: quant_vgg11()(torch.randn(1,3,224,224)).shape == (1,1000)

Signed-off-by: Tony Coder 407243179@qq.com

…ilinx#1500)

TruncAvgPool2d(kernel_size=7, stride=1) on the 7x7 feature map from VGG's
five MaxPools yields a 1x1 spatial map, so flatten size is 512 channels,
not 512*7*7 (that value matches torchvision's AdaptiveAvgPool2d((7,7))).

Signed-off-by: Tony Coder <407243179@qq.com>

This branch has not been deployed

No deployments
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.

QuantVGG classifier: incorrect in_features (512*7*7) after TruncAvgPool2d

1 participant