Skip to content

Commit

Permalink
add AlexNet_SIN to models (#798)
Browse files Browse the repository at this point in the history
Co-authored-by: AutoJenkins <[email protected]>
  • Loading branch information
kvfairchild and AutoJenkins authored Apr 25, 2024
1 parent fcb9af0 commit 84a71b3
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
8 changes: 8 additions & 0 deletions brainscore_vision/models/AlexNet_SIN/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from brainscore_vision import model_registry
from brainscore_vision.model_helpers.brain_transformation import ModelCommitment
from .model import get_model, LAYERS

model_registry['AlexNet_SIN'] = lambda: ModelCommitment(
identifier='AlexNet_SIN',
activations_model=get_model(),
layers=LAYERS)
29 changes: 29 additions & 0 deletions brainscore_vision/models/AlexNet_SIN/model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import functools

import torchvision.models
import torch

from brainscore_vision.model_helpers.activations.pytorch import PytorchWrapper
from brainscore_vision.model_helpers.activations.pytorch import load_preprocess_images

BIBTEX = """@article{geirhos2018imagenet,
title={ImageNet-trained CNNs are biased towards texture; increasing shape bias improves accuracy and robustness},
author={Geirhos, Robert and Rubisch, Patricia and Michaelis, Claudio and Bethge, Matthias and Wichmann, Felix A and Brendel, Wieland},
journal={arXiv preprint arXiv:1811.12231},
year={2018}
}"""

LAYERS = ['features.module.2', 'features.module.5', 'features.module.7', 'features.module.9', 'features.module.12',
'classifier.2', 'classifier.5']

model_url = 'https://bitbucket.org/robert_geirhos/texture-vs-shape-pretrained-models/raw/0008049cd10f74a944c6d5e90d4639927f8620ae/alexnet_train_60_epochs_lr0.001-b4aa5238.pth.tar'

def get_model():
model = torchvision.models.alexnet(pretrained=False)
model.features = torch.nn.DataParallel(model.features)
checkpoint = torch.utils.model_zoo.load_url(model_url, map_location="cpu")
model.load_state_dict(checkpoint["state_dict"])
preprocessing = functools.partial(load_preprocess_images, image_size=224)
wrapper = PytorchWrapper(identifier='AlexNet_SIN', model=model, preprocessing=preprocessing)
wrapper.image_size = 224
return wrapper
2 changes: 2 additions & 0 deletions brainscore_vision/models/AlexNet_SIN/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
torch
torchvision
1 change: 1 addition & 0 deletions brainscore_vision/models/AlexNet_SIN/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Left empty as part of 2023 models migration

0 comments on commit 84a71b3

Please sign in to comment.