-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jenkins
committed
Nov 30, 2024
1 parent
100e698
commit d3612e5
Showing
5 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
torch | ||
torchvision |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |