-
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 mobilenet_v2_0_5_224 * Add mobilenet_v2_0_5_224.json to region_layer_map for model mobilenet_v2_0_5_224 --------- Co-authored-by: KartikP <[email protected]>
- Loading branch information
1 parent
24ad980
commit c41c4fb
Showing
5 changed files
with
97 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['mobilenet_v2_0_5_224'] = \ | ||
lambda: ModelCommitment(identifier='mobilenet_v2_0_5_224', activations_model=get_model('mobilenet_v2_0_5_224'), layers=get_layers('mobilenet_v2_0_5_224')) |
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,73 @@ | ||
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 | ||
from brainscore_vision.model_helpers.s3 import load_weight_file | ||
import torch | ||
import imp | ||
|
||
model_path = load_weight_file(bucket="brainscore-storage", folder_name="brainscore-vision/models", | ||
relative_path="mobilenet_v2_0.5_224/mobilenet_v2_0.py", | ||
version_id="null", | ||
sha1="51ead4ba3605cdc9b5adc117e14def601288dd94") | ||
model_weight_path = load_weight_file(bucket="brainscore-storage", folder_name="brainscore-vision/models", | ||
relative_path="mobilenet_v2_0.5_224/mobilenet_v2_0.5_224_frozen.pth", | ||
version_id="null", | ||
sha1="649501eadcf01f871bdb2265aa7dcac80594160a") | ||
MainModel = imp.load_source('MainModel',model_path.as_posix()) | ||
model = torch.load(model_weight_path.as_posix()) | ||
|
||
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 == 'mobilenet_v2_0_5_224' | ||
preprocessing = functools.partial(load_preprocess_images, image_size=224, preprocess_type='inception') | ||
wrapper = PytorchWrapper(identifier=name, model=model, preprocessing=preprocessing) | ||
wrapper.image_size = 224 | ||
return wrapper | ||
|
||
|
||
def get_layers(name): | ||
assert name == 'mobilenet_v2_0_5_224' | ||
layer_names = (['MobilenetV2_Conv_Conv2D'] + | ||
[f'MobilenetV2_expanded_conv_{i}_expand_Conv2D' for i in range(1, 17)] + | ||
['MobilenetV2_Conv_1_Conv2D']) | ||
return layer_names | ||
|
||
|
||
def get_bibtex(name): | ||
""" | ||
A method returning the bibtex reference of the requested model as a string. | ||
""" | ||
return ''' | ||
@article{DBLP:journals/corr/abs-1801-04381, | ||
author = {Mark Sandler and | ||
Andrew G. Howard and | ||
Menglong Zhu and | ||
Andrey Zhmoginov and | ||
Liang{-}Chieh Chen}, | ||
title = {Inverted Residuals and Linear Bottlenecks: Mobile Networks for Classification, | ||
Detection and Segmentation}, | ||
journal = {CoRR}, | ||
volume = {abs/1801.04381}, | ||
year = {2018}, | ||
url = {http://arxiv.org/abs/1801.04381}, | ||
eprinttype = {arXiv}, | ||
eprint = {1801.04381}, | ||
timestamp = {Tue, 12 Jan 2021 15:30:06 +0100}, | ||
biburl = {https://dblp.org/rec/journals/corr/abs-1801-04381.bib}, | ||
bibsource = {dblp computer science bibliography, https://dblp.org} | ||
} | ||
''' | ||
|
||
|
||
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__) |
6 changes: 6 additions & 0 deletions
6
brainscore_vision/models/mobilenet_v2_0_5_224/region_layer_map/mobilenet_v2_0_5_224.json
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": "MobilenetV2_expanded_conv_9_expand_Conv2D", | ||
"V2": "MobilenetV2_expanded_conv_8_expand_Conv2D", | ||
"V4": "MobilenetV2_expanded_conv_7_expand_Conv2D", | ||
"IT": "MobilenetV2_Conv_1_Conv2D" | ||
} |
2 changes: 2 additions & 0 deletions
2
brainscore_vision/models/mobilenet_v2_0_5_224/requirements.txt
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,2 @@ | ||
imp | ||
torch |
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,9 @@ | ||
import brainscore_vision | ||
import pytest | ||
|
||
|
||
|
||
@pytest.mark.travis_slow | ||
def test_has_identifier(): | ||
model = brainscore_vision.load_model('mobilenet_v2_0_5_224') | ||
assert model.identifier == 'mobilenet_v2_0_5_224' |