Skip to content
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

add mobilenet_v2_0_5_192 #1740

Merged
merged 2 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions brainscore_vision/models/mobilenet_v2_0_5_192/__init__.py
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_192'] = \
lambda: ModelCommitment(identifier='mobilenet_v2_0_5_192', activations_model=get_model('mobilenet_v2_0_5_192'), layers=get_layers('mobilenet_v2_0_5_192'))
73 changes: 73 additions & 0 deletions brainscore_vision/models/mobilenet_v2_0_5_192/model.py
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_192/mobilenet_v2_0.py",
version_id="null",
sha1="d5c7af8768f9f2475367ac1e48e204cc5cf004a0")
model_weight_path = load_weight_file(bucket="brainscore-storage", folder_name="brainscore-vision/models",
relative_path="mobilenet_v2_0.5_192/mobilenet_v2_0.5_192_frozen.pth",
version_id="null",
sha1="e5aa083caa4833fccd48af0c578a45064824dd7f")
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_192'
preprocessing = functools.partial(load_preprocess_images, image_size=192, preprocess_type='inception')
wrapper = PytorchWrapper(identifier=name, model=model, preprocessing=preprocessing)
wrapper.image_size = 192
return wrapper


def get_layers(name):
assert name == 'mobilenet_v2_0_5_192'
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__)
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_expanded_conv_14_expand_Conv2D"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
imp
torch
8 changes: 8 additions & 0 deletions brainscore_vision/models/mobilenet_v2_0_5_192/test.py
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('mobilenet_v2_0_5_192')
assert model.identifier == 'mobilenet_v2_0_5_192'
Loading