-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add vgg-16 and vgg-19 * remove hyphens * Add vgg_19.json to region_layer_map for model vgg_19 * Add vgg_16.json to region_layer_map for model vgg_16 --------- Co-authored-by: KartikP <[email protected]>
- Loading branch information
1 parent
ad0dd5d
commit 898155f
Showing
10 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from brainscore_vision.model_helpers.brain_transformation import ModelCommitment | ||
from brainscore_vision import model_registry | ||
from .model import get_layers,get_model | ||
|
||
|
||
model_registry['vgg_16'] = \ | ||
lambda: ModelCommitment(identifier='vgg_16', activations_model=get_model('vgg_16'), layers=get_layers('vgg_16')) |
This file contains 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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import functools | ||
from brainscore_vision.model_helpers.activations.pytorch import load_preprocess_images | ||
from brainscore_vision.model_helpers.activations.pytorch import PytorchWrapper | ||
from brainscore_vision.model_helpers.check_submission import check_models | ||
import torchvision | ||
|
||
|
||
|
||
def get_model(name): | ||
""" | ||
This method fetches an instance of a base model. The instance has to be callable and return a xarray object, | ||
containing activations. There exist standard wrapper implementations for common libraries, like pytorch and | ||
keras. Checkout the examples folder, to see more. For custom implementations check out the implementation of the | ||
wrappers. | ||
:param name: the name of the model to fetch | ||
:return: the model instance | ||
""" | ||
assert name == 'vgg_16' | ||
model = torchvision.models.vgg16(weights='DEFAULT') | ||
preprocessing = functools.partial(load_preprocess_images, image_size=224) | ||
wrapper = PytorchWrapper(identifier=name, model=model, preprocessing=preprocessing) | ||
wrapper.image_size = 224 | ||
return wrapper | ||
|
||
|
||
def get_layers(name): | ||
assert name == 'vgg_16' | ||
layer_names = [f'features.{i}' for i in [4, 9, 16, 23, 30]] + [f'classifier.{i}' for i in [0, 3]] | ||
return layer_names | ||
|
||
|
||
def get_bibtex(name): | ||
""" | ||
A method returning the bibtex reference of the requested model as a string. | ||
""" | ||
return ''' | ||
@misc{simonyan2015deepconvolutionalnetworkslargescale, | ||
title={Very Deep Convolutional Networks for Large-Scale Image Recognition}, | ||
author={Karen Simonyan and Andrew Zisserman}, | ||
year={2015}, | ||
eprint={1409.1556}, | ||
archivePrefix={arXiv}, | ||
primaryClass={cs.CV}, | ||
url={https://arxiv.org/abs/1409.1556}, | ||
} | ||
''' | ||
|
||
|
||
if __name__ == '__main__': | ||
# Use this method to ensure the correctness of the BaseModel implementations. | ||
# It executes a mock run of brain-score benchmarks. | ||
check_models.check_base_models(__name__) |
This file contains 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"V1": "features.16", | ||
"V2": "features.16", | ||
"V4": "features.16", | ||
"IT": "features.23" | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
torchvision |
This file contains 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import brainscore_vision | ||
import pytest | ||
|
||
|
||
@pytest.mark.travis_slow | ||
def test_has_identifier(): | ||
model = brainscore_vision.load_model('vgg_16') | ||
assert model.identifier == 'vgg_16' |
This file contains 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from brainscore_vision.model_helpers.brain_transformation import ModelCommitment | ||
from brainscore_vision import model_registry | ||
from .model import get_layers,get_model | ||
|
||
|
||
model_registry['vgg_19'] = \ | ||
lambda: ModelCommitment(identifier='vgg_19', activations_model=get_model('vgg_19'), layers=get_layers('vgg_19')) |
This file contains 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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import functools | ||
from brainscore_vision.model_helpers.activations.pytorch import load_preprocess_images | ||
from brainscore_vision.model_helpers.activations.pytorch import PytorchWrapper | ||
from brainscore_vision.model_helpers.check_submission import check_models | ||
import torchvision | ||
|
||
|
||
|
||
def get_model(name): | ||
""" | ||
This method fetches an instance of a base model. The instance has to be callable and return a xarray object, | ||
containing activations. There exist standard wrapper implementations for common libraries, like pytorch and | ||
keras. Checkout the examples folder, to see more. For custom implementations check out the implementation of the | ||
wrappers. | ||
:param name: the name of the model to fetch | ||
:return: the model instance | ||
""" | ||
assert name == 'vgg_19' | ||
model = torchvision.models.vgg19(weights='DEFAULT') | ||
preprocessing = functools.partial(load_preprocess_images, image_size=224) | ||
wrapper = PytorchWrapper(identifier=name, model=model, preprocessing=preprocessing) | ||
wrapper.image_size = 224 | ||
return wrapper | ||
|
||
|
||
def get_layers(name): | ||
assert name == 'vgg_19' | ||
layer_names = [f'features.{i}' for i in [4, 8, 18, 27, 36]] + [f'classifier.{i}' for i in [0, 3]] | ||
return layer_names | ||
|
||
|
||
def get_bibtex(name): | ||
""" | ||
A method returning the bibtex reference of the requested model as a string. | ||
""" | ||
return ''' | ||
@misc{simonyan2015deepconvolutionalnetworkslargescale, | ||
title={Very Deep Convolutional Networks for Large-Scale Image Recognition}, | ||
author={Karen Simonyan and Andrew Zisserman}, | ||
year={2015}, | ||
eprint={1409.1556}, | ||
archivePrefix={arXiv}, | ||
primaryClass={cs.CV}, | ||
url={https://arxiv.org/abs/1409.1556}, | ||
} | ||
''' | ||
|
||
|
||
if __name__ == '__main__': | ||
# Use this method to ensure the correctness of the BaseModel implementations. | ||
# It executes a mock run of brain-score benchmarks. | ||
check_models.check_base_models(__name__) |
This file contains 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
{"IT": "conv_relu_3_3_fake_relu", "V4": "conv_relu_2_3_fake_relu", "V1": "conv_relu_1_1_fake_relu", "V2": "conv_relu_2_3_fake_relu"} |
This file contains 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
torchvision |
This file contains 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import brainscore_vision | ||
import pytest | ||
|
||
|
||
@pytest.mark.travis_slow | ||
def test_has_identifier(): | ||
model = brainscore_vision.load_model('vgg_19') | ||
assert model.identifier == 'vgg_19' |