Skip to content

Commit

Permalink
Add resnet50_tutorial to model registry (#1014)
Browse files Browse the repository at this point in the history
* Add resnet50_tutorial to model registry

* resnet50_tutorial now inline with 2.0 model packaging

* remove setup.py and add requirements.txt

* add standard test and make sure model identifiers line up

* Update brainscore_vision/models/resnet50_tutorial/model.py

Co-authored-by: Martin Schrimpf <[email protected]>

---------

Co-authored-by: Martin Schrimpf <[email protected]>
  • Loading branch information
mike-ferguson and mschrimpf authored Jul 11, 2024
1 parent def245c commit 446a514
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
5 changes: 5 additions & 0 deletions brainscore_vision/models/resnet50_tutorial/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from brainscore_vision import model_registry
from brainscore_vision.model_helpers.brain_transformation import ModelCommitment
from .model import get_model, get_layers

model_registry['resnet50_tutorial'] = lambda: ModelCommitment(identifier='resnet50_tutorial', activations_model=get_model('resnet50_tutorial'), layers=get_layers('resnet50_tutorial'))
34 changes: 34 additions & 0 deletions brainscore_vision/models/resnet50_tutorial/model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from brainscore_vision.model_helpers.check_submission import check_models
import functools
import torchvision.models
from brainscore_vision.model_helpers.activations.pytorch import PytorchWrapper
from brainscore_vision.model_helpers.activations.pytorch import load_preprocess_images

# This is an example implementation for submitting resnet-50 as a pytorch model

# Attention: It is important, that the wrapper identifier is unique per model!
# The results will otherwise be the same due to brain-scores internal result caching mechanism.
# Please load your pytorch model for usage in CPU. There won't be GPUs available for scoring your model.
# If the model requires a GPU, contact the brain-score team directly.


def get_model(name):
assert name == 'resnet50_tutorial'
model = torchvision.models.resnet50(pretrained=True)
preprocessing = functools.partial(load_preprocess_images, image_size=224)
wrapper = PytorchWrapper(identifier='resnet50_tutorial', model=model, preprocessing=preprocessing)
wrapper.image_size = 224
return wrapper


def get_layers(name):
assert name == 'resnet50_tutorial'
return ['conv1','layer1', 'layer2', 'layer3', 'layer4', 'fc']


def get_bibtex(model_identifier):
return """"""


if __name__ == '__main__':
check_models.check_base_models(__name__)
2 changes: 2 additions & 0 deletions brainscore_vision/models/resnet50_tutorial/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
torchvision
torch
8 changes: 8 additions & 0 deletions brainscore_vision/models/resnet50_tutorial/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import pytest
import brainscore_vision


@pytest.mark.travis_slow
def test_has_identifier():
model = brainscore_vision.load_model('resnet50_tutorial')
assert model.identifier == 'resnet50_tutorial'

0 comments on commit 446a514

Please sign in to comment.