The `test_detection_model_trainable_backbone_layers` test shouldn't download the pretrained_backbone weights
See original GitHub issueFeature Improvement
The test_detection_model_trainable_backbone_layers
test currently downloads the weights of the backbone:
https://github.com/pytorch/vision/blob/6530546080148cd5d9533b50a8258f12cb050c82/test/test_models.py#L786
Setting the value pretrained_backbone=True
is necessary because the number of trainable layers depends on this value. Unfortunately downloading pre-trained weights can lead to flakiness and slow tests and should be avoided. Until we setup a cache to store the weights locally on the CI, we should find a way to skip the actual downloading of weights during the test execution.
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
Initialized DETR backbone weights do not match with ... - GitHub
Hello everybody! My task is to initialize DETR Object Detection model with my own pretrained backbone (for example, ResNet-50).
Read more >06. PyTorch Transfer Learning - Zero to Mastery Learn ...
We can setup the EfficientNet_B0 pretrained ImageNet weights using the same code as we used to create the transforms. weights = torchvision.models.
Read more >Training with Custom Pretrained Models Using the NVIDIA ...
This post walks you through the workflow, from downloading the TLT Docker container and AI models from NVIDIA NGC, to training and ...
Read more >Transfer learning and fine-tuning | TensorFlow Core
Load in the pretrained base model (and pretrained weights) ... As the original dataset doesn't contain a test set, you will create one....
Read more >Transfer Learning in PyTorch, Part 2: How to Create a Transfer ...
In the last case, we may want to do only predictions and keep all weights including the backbone and the head frozen. This...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think it should be possible to patch
load_state_dict
at thenn.Module
level as you suggested, something like:I haven’t checked, but this shouldn’t do any network call – this can be verified with pytest-sockets https://github.com/miketheman/pytest-socket
@NicolasHug thanks for checking. Yes the weights are always added in the manifold so this won’t be a problem.
The speed is not as bad on CircleCI. We checked during merge (see here) and only 1 test appeared on the top slowest with execution time 14-15 secs. All others executed in less than 8 sec:
The problem can be solved quite easily using the new weights API, because you can easily patch the model loading method of the weights during tests and avoid their actual downloading. That’s a bit harder using the old
pretrained
approach. Any thoughts/ideas about this? I’m open to reverting if a good solution doesn’t exist now and we could add the test back once we’ve moved the multi-pretrained model mechanism in main.EDIT:
I checked the new proposed API and patching it won’t be as easy as I remembered. I think we need to make some additional minor adjustments. Here is how the weights are typically loaded based on the current proposal:
One could easily patch the
state_dict
method of the weights in the tests, so that they don’t actually download anything. Unfortunately, passingNone
onload_state_dict()
wont work. We could have an extra step that checks that the weights are not None before loading them but this might require some extra thought.