From d8fed71e18a98cb17c8b15a243c5f5b3ba9c2fac Mon Sep 17 00:00:00 2001 From: Katherine Fairchild Date: Sat, 30 Nov 2024 10:45:23 -0500 Subject: [PATCH] add resnet18_random to models (#1512) Co-authored-by: Jenkins --- .../models/resnet18_random/__init__.py | 5 +++ .../models/resnet18_random/archive_name.zip | Bin 0 -> 4552 bytes .../models/resnet18_random/model.py | 42 ++++++++++++++++++ .../models/resnet18_random/requirements.txt | 2 + .../models/resnet18_random/test.py | 12 +++++ 5 files changed, 61 insertions(+) create mode 100644 brainscore_vision/models/resnet18_random/__init__.py create mode 100644 brainscore_vision/models/resnet18_random/archive_name.zip create mode 100644 brainscore_vision/models/resnet18_random/model.py create mode 100644 brainscore_vision/models/resnet18_random/requirements.txt create mode 100644 brainscore_vision/models/resnet18_random/test.py diff --git a/brainscore_vision/models/resnet18_random/__init__.py b/brainscore_vision/models/resnet18_random/__init__.py new file mode 100644 index 000000000..24487541c --- /dev/null +++ b/brainscore_vision/models/resnet18_random/__init__.py @@ -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') diff --git a/brainscore_vision/models/resnet18_random/archive_name.zip b/brainscore_vision/models/resnet18_random/archive_name.zip new file mode 100644 index 0000000000000000000000000000000000000000..bf25af6981ab3d26a11562f7cbab74e57212048a GIT binary patch literal 4552 zcmb7{cQ{<_*2afHl;}0V2+?IQAwr_}-n&tP(HXsW2@#?PA&4$o^cE2ry_eB~5WPi- z8VPcSyys0$^5&fHyXJcKwfFq-ThFuBUi)6Rssa#$3;+ON103pn_4F%5s{>F^1E_@u zpaB>gTRT|08XI#udTD9m0Dx}}Wi8upC|J6A;sMYwR)GM(#Rb+UhKmllj5+A1LhJ}> zAf68Yz%>0RAxg;-JzjE{dwz5D(Zk-GBHMcrY!dMB9HUY0eoZ;dhj1H$;w$-9{Hks~ z_jlW;DE!+3K?Xz!TxI;MpyOcnPHXd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3jl0>klf2l2^G7y(`jVdxEheV z-vv3HloZ|FDPklix_1=NKlIi^~O5G zoZPIPVfHWwR~JrKPuB~hu)O+@UW%iOOTPaDJ6bI4Y1`9dFDT##S_P#y5?|spk5JfW zC|`03g}%_3zj`6`5AH0cT)CC|a_EuZ1E$a!e0&dCmdtqew}BWy#gA%}IUWLWb(t zWha0HjP-_{7a~o|ln%9OUcIu)Umw9r9=~^*oE2Hi7G6UNwYQ8~yrOO&d!;NaI3A)h zN~o%Uh7JP$$=gz0I7Czu0gFNBw|{%O^IT$nce=kQ@^|2$jOKUXdA&EqS}%Y<+fEem z+;;vW@lU4n-$Vc)CkPj{Q)A;F#J{)uo3lYhI=7(zBhr6brk^9#puV&}NBV<-`rl!G zpN@WnSq!>~@@hYa`9I7`sF43KC;eRJ-__!K$nRx-f-2n)?Lg7awd23!>Gw|lnI?k| v_=mnmQP2DOzfgZ~;-9HmDC*xWje?!G^lvasln|avAvRzFRjf&Z^QV6S7~X2m literal 0 HcmV?d00001 diff --git a/brainscore_vision/models/resnet18_random/model.py b/brainscore_vision/models/resnet18_random/model.py new file mode 100644 index 000000000..47dc22906 --- /dev/null +++ b/brainscore_vision/models/resnet18_random/model.py @@ -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__) diff --git a/brainscore_vision/models/resnet18_random/requirements.txt b/brainscore_vision/models/resnet18_random/requirements.txt new file mode 100644 index 000000000..ac988bdf8 --- /dev/null +++ b/brainscore_vision/models/resnet18_random/requirements.txt @@ -0,0 +1,2 @@ +torch +torchvision diff --git a/brainscore_vision/models/resnet18_random/test.py b/brainscore_vision/models/resnet18_random/test.py new file mode 100644 index 000000000..56ec9a504 --- /dev/null +++ b/brainscore_vision/models/resnet18_random/test.py @@ -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' \ No newline at end of file