fix: model_convnext_small_22k1k defaults to 1000 classes - #376
Merged
cregouby merged 2 commits intoAug 1, 2026
Conversation
`convnext_small_22k1k` is pretrained on Imagenet 22k and *fine-tuned* on
Imagenet 1k, so the published weights have a 1000-class head. The formal
default was `num_classes = 21841`, taken from the other `_22k` models, so
`model_convnext_small_22k1k(pretrained = TRUE)` built a 21841-class head
and then failed to load the state dict with
The size of tensor a (21841) must match the size of tensor b (1000)
at non-singleton dimension 0
Verified against the published checkpoint: its `head.weight` is 1000x768,
whereas `convnext_tiny_22k` really is 21841x768.
The caller could not work around this by passing `num_classes = 1000`
either, because `.convnext()` loads the state dict with `strict = FALSE`,
which is silently swallowed by `...`: `load_state_dict()` of torch for R
has no `strict` argument.
The roxygen description had the two datasets the wrong way round
("pretrained on Imagenet 1k and fine-tuned on Imagenet 22k") and the
variants table listed 21841 classes and a 252 MB file size; both are
corrected (the file is 192 MB).
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
cregouby
approved these changes
Aug 1, 2026
cregouby
left a comment
Collaborator
There was a problem hiding this comment.
Thanks a lot @sebffischer !
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.
convnext_small_22k1kis pretrained on Imagenet 22k and fine-tuned on Imagenet 1k, so the published weights have a 1000-class head. The formal default wasnum_classes = 21841, taken from the other_22kmodels, somodel_convnext_small_22k1k(pretrained = TRUE)built a 21841-class head and then failed to load the state dict withThe size of tensor a (21841) must match the size of tensor b (1000)
at non-singleton dimension 0
Verified against the published checkpoint: its
head.weightis 1000x768, whereasconvnext_tiny_22kreally is 21841x768.The caller could not work around this by passing
num_classes = 1000either, because.convnext()loads the state dict withstrict = FALSE, which is silently swallowed by...:load_state_dict()of torch for R has nostrictargument.The roxygen description had the two datasets the wrong way round ("pretrained on Imagenet 1k and fine-tuned on Imagenet 22k") and the variants table listed 21841 classes and a 252 MB file size; both are corrected (the file is 192 MB).