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

brain-score.org submission (user:542) | (public:False) #1538

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 5 additions & 0 deletions brainscore_vision/models/barlow_twins_custom/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from brainscore_vision import model_registry
from .model import get_model

# Register the Barlow Twins model with custom weights
model_registry['barlow_twins_custom'] = lambda: get_model('barlow_twins_custom')
44 changes: 44 additions & 0 deletions brainscore_vision/models/barlow_twins_custom/model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import torch
from pathlib import Path
from torchvision.models import resnet18
from brainscore_vision.model_helpers.activations.pytorch import PytorchWrapper
from brainscore_vision.model_helpers.brain_transformation import ModelCommitment
from brainscore_vision.model_helpers.activations.pytorch import load_preprocess_images
from brainscore_vision.model_helpers.check_submission import check_models
from collections import OrderedDict
from urllib.request import urlretrieve
import functools

# Custom model loader
def get_model(name):
assert name == 'barlow_twins_custom'

url = " https://www.dropbox.com/scl/fi/db5yp3hols5sucujanimx/barlow_twins_weights.pth?rlkey=nalge9jixfeqorazwu4xqdbd8&st=yqf3qkaj&dl=1"
fh = urlretrieve(url)
state_dict = torch.load(fh[0], map_location=torch.device("cpu"))
model = resnet18(pretrained=False)
model.load_state_dict(state_dict, strict=False)
print(model)
preprocessing = functools.partial(load_preprocess_images, image_size=224)

activations_model = PytorchWrapper(identifier='barlow_twins_custom', model=model, preprocessing=preprocessing)


return ModelCommitment(
identifier='barlow_twins_custom',
activations_model=activations_model,
layers=['layer1', 'layer2', 'layer3', 'layer4', 'avgpool']
)

def get_model_list():
return ['barlow_twins_custom']

# Specify layers to test
def get_layers(name):
assert name == 'barlow_twins_custom'
return ['layer1', 'layer2', 'layer3', 'layer4', 'avgpool']


if __name__ == '__main__':

check_models.check_base_models(__name__)
5 changes: 5 additions & 0 deletions brainscore_vision/models/barlow_twins_custom/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
torch
torchvision
requests
pathlib
urlretrieve
12 changes: 12 additions & 0 deletions brainscore_vision/models/barlow_twins_custom/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pytest
import brainscore_vision

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



# AssertionError: No registrations found for resnet18_random
# ⚡ master ~/vision python -m brainscore_vision score --model_identifier='resnet50_tutorial' --benchmark_identifier='MajajHong2015public.IT-pls'