Repository navigation
Conversation
Block i read its input width from layer_sizes[i] and the output layer always used layer_sizes[-1], so ResNet raised IndexError for more blocks than widths and a shape mismatch for fewer blocks than transitions. Track the running width: block i maps layer_sizes[i] to layer_sizes[i + 1], later blocks keep the last width (as documented), and the output layer reads the width of the last block. Document the schedule in ResNetConfig and the ResNet model page. Fixes #537
Four blocks is the case from the issue (one more block than layer_sizes entries) that raised IndexError. Refs #537
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #537
Problem
ResNet.__init__took blocki's input width fromlayer_sizes[i]and always built the output layer asnn.Linear(layer_sizes[-1], num_classes). Onlynum_blocksequal tolen(layer_sizes) - 1orlen(layer_sizes)worked:layer_sizes[i]raisedIndexError, contrary to the model page's "later blocks stay at the final width";num_blocks=0), the output layer didn't match the last block's width and the first forward pass failed.Fix
deeptab/architectures/resnet.pytracks the running width:imaps the current width tolayer_sizes[min(i + 1, len(layer_sizes) - 1)];layer_sizes[0]without blocks.Configurations that worked before build the identical network.
Tests
tests/architectures/test_architecture_contracts.py::test_resnet_blocks_follow_layer_sizes_for_any_num_blocks[0-blocks|1-block|2-blocks|3-blocks|4-blocks|5-blocks]checks each block's widths, the output layer width, a forward pass and a backward pass withlayer_sizes=[16, 8, 4]. The cases with 0, 1, 4 and 5 blocks fail onmain; four blocks is the issue'sIndexErrorcase. The 2- and 3-block cases worked before and build the samestate_dictas onmain. All pass with this change.This also makes the documented example in
docs/api/configs/index.rstwork. It usesResNetConfig(layer_sizes=[256, 128, 32], num_blocks=4)and raisesIndexErroronmain.Docs
ResNetConfignumpydoc:layer_sizesis described as the width schedule, andnum_blocksexplains blocks beyond it and the output width.docs/model_zoo/stable/resnet.md: the building-blocks table and the implementation notes describe the schedule and the output layer.Checks
just test: 3242 passed, 46 skipped, 28 xfailed; coverage 91.29%just docs: build succeeded (warnings treated as errors)just check: all hooks passed (ruff, prettier, pyright)