Skip to content

Commit ccba664

Browse files
authored
Converted Mobilenet v2 0.75 192 (#1132)
* Add BiT-M-R50x3 * a * Add BiT-M-R50x3 * aaa * mobilenet_v2_0_75_192
1 parent e5630a2 commit ccba664

File tree

4 files changed

+86
-0
lines changed

4 files changed

+86
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from brainscore_vision.model_helpers.brain_transformation import ModelCommitment
2+
from brainscore_vision import model_registry
3+
from .model import get_layers,get_model
4+
5+
6+
model_registry['mobilenet_v2_0_75_192'] = \
7+
lambda: ModelCommitment(identifier='mobilenet_v2_0_75_192', activations_model=get_model('mobilenet_v2_0_75_192'), layers=get_layers('mobilenet_v2_0_75_192'))
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import functools
2+
from brainscore_vision.model_helpers.activations.pytorch import load_preprocess_images
3+
from brainscore_vision.model_helpers.activations.pytorch import PytorchWrapper
4+
from brainscore_vision.model_helpers.check_submission import check_models
5+
from brainscore_vision.model_helpers.s3 import load_weight_file
6+
import torch
7+
import imp
8+
9+
model_path = load_weight_file(bucket="brainscore-vision", folder_name="models",
10+
relative_path="mobilenet_v2_0.75_192/mobilenet_v2_0.py",
11+
version_id=".Cx.l320j.RVVHTABgJpQO.deOHI.ldd",
12+
sha1="8d253c2faad210834b4d39b9ccc644165ed8e3f6")
13+
model_weight_path = load_weight_file(bucket="brainscore-vision", folder_name="models",
14+
relative_path="mobilenet_v2_0.75_192/mobilenet_v2_0.75_192_frozen.pth",
15+
version_id="XNBog9emIZQ7ngr8v2X1Om6YQsV7okFU",
16+
sha1="af063236e83cb92fd78ed3eb7d9d2d4a65d794ab")
17+
MainModel = imp.load_source('MainModel',model_path.as_posix())
18+
model = torch.load(model_weight_path.as_posix())
19+
20+
def get_model(name):
21+
"""
22+
This method fetches an instance of a base model. The instance has to be callable and return a xarray object,
23+
containing activations. There exist standard wrapper implementations for common libraries, like pytorch and
24+
keras. Checkout the examples folder, to see more. For custom implementations check out the implementation of the
25+
wrappers.
26+
:param name: the name of the model to fetch
27+
:return: the model instance
28+
"""
29+
assert name == 'mobilenet_v2_0_75_192'
30+
preprocessing = functools.partial(load_preprocess_images, image_size=192)
31+
wrapper = PytorchWrapper(identifier=name, model=model, preprocessing=preprocessing)
32+
wrapper.image_size = 192
33+
return wrapper
34+
35+
36+
def get_layers(name):
37+
assert name == 'mobilenet_v2_0_75_192'
38+
return list(dict(model.named_modules()).keys())[1:]
39+
40+
41+
def get_bibtex(name):
42+
"""
43+
A method returning the bibtex reference of the requested model as a string.
44+
"""
45+
return '''
46+
@article{DBLP:journals/corr/ZophVSL17,
47+
author = {Barret Zoph and
48+
Vijay Vasudevan and
49+
Jonathon Shlens and
50+
Quoc V. Le},
51+
title = {Learning Transferable Architectures for Scalable Image Recognition},
52+
journal = {CoRR},
53+
volume = {abs/1707.07012},
54+
year = {2017},
55+
url = {http://arxiv.org/abs/1707.07012},
56+
eprinttype = {arXiv},
57+
eprint = {1707.07012},
58+
timestamp = {Mon, 13 Aug 2018 16:48:00 +0200},
59+
biburl = {https://dblp.org/rec/journals/corr/ZophVSL17.bib},
60+
bibsource = {dblp computer science bibliography, https://dblp.org}
61+
}
62+
'''
63+
64+
65+
if __name__ == '__main__':
66+
# Use this method to ensure the correctness of the BaseModel implementations.
67+
# It executes a mock run of brain-score benchmarks.
68+
check_models.check_base_models(__name__)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
imp
2+
torch
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import brainscore_vision
2+
import pytest
3+
4+
5+
6+
@pytest.mark.travis_slow
7+
def test_has_identifier():
8+
model = brainscore_vision.load_model('mobilenet_v2_0_75_192')
9+
assert model.identifier == 'mobilenet_v2_0_75_192'

0 commit comments

Comments
 (0)