Skip to content

Commit

Permalink
add resnet18_random to models
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins committed Nov 30, 2024
1 parent 100e698 commit d3612e5
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 0 deletions.
5 changes: 5 additions & 0 deletions brainscore_vision/models/resnet18_random/__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 model with the identifier 'resnet18_random'
model_registry['resnet18_random'] = lambda: get_model('resnet18_random')
Binary file not shown.
42 changes: 42 additions & 0 deletions brainscore_vision/models/resnet18_random/model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import torch
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
import functools

# Define preprocessing (resize to 224x224 as required by ResNet)
preprocessing = functools.partial(load_preprocess_images, image_size=224)

# Define ResNet18 with random weights
def get_model(name):
assert name == 'resnet18_random'
# Load ResNet18 without pre-trained weights
model = resnet18(pretrained=False)
# Wrap the model with Brain-Score's PytorchWrapper
activations_model = PytorchWrapper(identifier='resnet18_random', model=model, preprocessing=preprocessing)
return ModelCommitment(
identifier='resnet18_random',
activations_model=activations_model,
# Specify layers for evaluation
layers=['layer1', 'layer2', 'layer3', 'layer4', 'avgpool']
)

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

# Optional: Provide a BibTeX reference for the model
def get_bibtex(model_identifier):
return """
@misc{resnet18_test_consistency,
title={ResNet18 with Random Weights},
author={Clear Glue},
year={2024},
}
"""

if __name__ == '__main__':
from brainscore_vision.model_helpers.check_submission import check_models
check_models.check_base_models(__name__)
2 changes: 2 additions & 0 deletions brainscore_vision/models/resnet18_random/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
torch
torchvision
12 changes: 12 additions & 0 deletions brainscore_vision/models/resnet18_random/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_resnet18_random():
model = brainscore_vision.load_model('resnet18_random')
assert model.identifier == 'resnet18_random'



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

0 comments on commit d3612e5

Please sign in to comment.