-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Adding Weights classes for Resnet classification models #4655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
e48df51
adding Weights classes for Resnet classification models
jdsgomes 7354381
Replacing BasicBlock by Bottleneck in all but 3 model contructors
jdsgomes 9264a52
adding tests for prototype models
jdsgomes 17fa569
fixing typo in environment variable
jdsgomes 72ba4e3
Update test/test_prototype_models.py
jdsgomes ae412e1
changing default value for PYTORCH_TEST_WITH_PROTOTYPE
jdsgomes df6cd1f
adding checks to compare outputs of the prototype vs old models
jdsgomes 9e4200d
refactoring prototype tests
jdsgomes 0b49b70
removing unused imports
jdsgomes b877d6b
applying ufmt
jdsgomes 069c832
Update test/test_prototype_models.py
jdsgomes 20fa4da
Update test/test_prototype_models.py
jdsgomes d594973
Update test/test_prototype_models.py
jdsgomes da969ce
Update test/test_prototype_models.py
jdsgomes b737bf6
Update test/test_prototype_models.py
jdsgomes 814aeb8
Update test/test_prototype_models.py
jdsgomes c4048b0
Merge branch 'main' into multiweight/resnet
jdsgomes 344b84c
Update test/test_prototype_models.py
jdsgomes c93a653
Merge branch 'main' into multiweight/resnet
datumbox File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,56 @@ | ||
import os | ||
|
||
import pytest | ||
import torch | ||
from common_utils import set_rng_seed, cpu_and_gpu | ||
from test_models import _assert_expected, _model_params | ||
from torchvision import models as original_models | ||
from torchvision.prototype import models | ||
|
||
|
||
def get_available_classification_models(): | ||
return [k for k, v in models.__dict__.items() if callable(v) and k[0].lower() == k[0] and k[0] != "_"] | ||
|
||
|
||
@pytest.mark.parametrize("model_name", get_available_classification_models()) | ||
@pytest.mark.parametrize("dev", cpu_and_gpu()) | ||
@pytest.mark.skipif(os.getenv("PYTORCH_TEST_WITH_PROTOTYPE", "0") == "0", reason="Prototype code tests are disabled") | ||
def test_classification_model(model_name, dev): | ||
set_rng_seed(0) | ||
defaults = { | ||
"num_classes": 50, | ||
"input_shape": (1, 3, 224, 224), | ||
} | ||
kwargs = {**defaults, **_model_params.get(model_name, {})} | ||
input_shape = kwargs.pop("input_shape") | ||
model = models.__dict__[model_name](**kwargs) | ||
model.eval().to(device=dev) | ||
x = torch.rand(input_shape).to(device=dev) | ||
out = model(x) | ||
_assert_expected(out.cpu(), model_name, prec=0.1) | ||
assert out.shape[-1] == 50 | ||
|
||
|
||
@pytest.mark.parametrize("model_name", get_available_classification_models()) | ||
@pytest.mark.parametrize("dev", cpu_and_gpu()) | ||
@pytest.mark.skipif(os.getenv("PYTORCH_TEST_WITH_PROTOTYPE", "0") == "0", reason="Prototype code tests are disabled") | ||
def test_old_vs_new_classification_factory(model_name, dev): | ||
defaults = { | ||
"pretrained": True, | ||
"input_shape": (1, 3, 224, 224), | ||
} | ||
kwargs = {**defaults, **_model_params.get(model_name, {})} | ||
input_shape = kwargs.pop("input_shape") | ||
model_old = original_models.__dict__[model_name](**kwargs) | ||
model_old.eval().to(device=dev) | ||
x = torch.rand(input_shape).to(device=dev) | ||
out_old = model_old(x) | ||
# compare with new model builder parameterized in the old fashion way | ||
model_new = models.__dict__[model_name](**kwargs) | ||
model_new.eval().to(device=dev) | ||
out_new = model_new(x) | ||
torch.testing.assert_close(out_new, out_old, rtol=0.0, atol=0.0, check_dtype=False) | ||
|
||
|
||
def test_smoke(): | ||
import torchvision.prototype.models # noqa: F401 |
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
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.
Uh oh!
There was an error while loading. Please reload this page.