From a379e1d0b3de330bd73c22637e449d80eeb9360a Mon Sep 17 00:00:00 2001 From: Katherine Fairchild Date: Thu, 29 Feb 2024 10:21:11 -0500 Subject: [PATCH] add r50_tvpt to models (#584) Co-authored-by: AutoJenkins --- brainscore_vision/models/r50_tvpt/__init__.py | 9 ++++ brainscore_vision/models/r50_tvpt/model.py | 47 +++++++++++++++++++ brainscore_vision/models/r50_tvpt/setup.py | 25 ++++++++++ brainscore_vision/models/r50_tvpt/test.py | 1 + 4 files changed, 82 insertions(+) create mode 100644 brainscore_vision/models/r50_tvpt/__init__.py create mode 100644 brainscore_vision/models/r50_tvpt/model.py create mode 100644 brainscore_vision/models/r50_tvpt/setup.py create mode 100644 brainscore_vision/models/r50_tvpt/test.py diff --git a/brainscore_vision/models/r50_tvpt/__init__.py b/brainscore_vision/models/r50_tvpt/__init__.py new file mode 100644 index 000000000..47d009a2b --- /dev/null +++ b/brainscore_vision/models/r50_tvpt/__init__.py @@ -0,0 +1,9 @@ +from brainscore_vision import model_registry +from brainscore_vision.model_helpers.brain_transformation import ModelCommitment +from .model import get_model, get_layers + +model_registry["r50_tvpt"] = lambda: ModelCommitment( + identifier="r50_tvpt", + activations_model=get_model("r50_tvpt"), + layers=get_layers("r50_tvpt"), +) diff --git a/brainscore_vision/models/r50_tvpt/model.py b/brainscore_vision/models/r50_tvpt/model.py new file mode 100644 index 000000000..99ccb0bfb --- /dev/null +++ b/brainscore_vision/models/r50_tvpt/model.py @@ -0,0 +1,47 @@ +from brainscore_vision.model_helpers.check_submission import check_models +import functools +import os +from urllib.request import urlretrieve +import torchvision.models +from brainscore_vision.model_helpers.activations.pytorch import PytorchWrapper +from brainscore_vision.model_helpers.activations.pytorch import load_preprocess_images +from pathlib import Path +from brainscore_vision.model_helpers import download_weights +import torch + +# This is an example implementation for submitting resnet-50 as a pytorch model + +# Attention: It is important, that the wrapper identifier is unique per model! +# The results will otherwise be the same due to brain-scores internal result caching mechanism. +# Please load your pytorch model for usage in CPU. There won't be GPUs available for scoring your model. +# If the model requires a GPU, contact the brain-score team directly. +from brainscore_vision.model_helpers.check_submission import check_models + + +def get_model_list(): + return ["r50_tvpt"] + + +def get_model(name): + assert name == "r50_tvpt" + model = torchvision.models.resnet50(pretrained=True) + preprocessing = functools.partial(load_preprocess_images, image_size=224) + wrapper = PytorchWrapper( + identifier="resnet50", model=model, preprocessing=preprocessing + ) + wrapper.image_size = 224 + return wrapper + + +def get_layers(name): + assert name == "r50_tvpt" + outs = ["conv1", "layer1", "layer2", "layer3", "layer4"] + return outs + + +def get_bibtex(model_identifier): + return """xx""" + + +if __name__ == "__main__": + check_models.check_base_models(__name__) diff --git a/brainscore_vision/models/r50_tvpt/setup.py b/brainscore_vision/models/r50_tvpt/setup.py new file mode 100644 index 000000000..421914cfb --- /dev/null +++ b/brainscore_vision/models/r50_tvpt/setup.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from setuptools import setup, find_packages + +requirements = [ "torchvision", + "torch" +] + +setup( + packages=find_packages(exclude=['tests']), + include_package_data=True, + install_requires=requirements, + license="MIT license", + zip_safe=False, + keywords='brain-score template', + classifiers=[ + 'Development Status :: 2 - Pre-Alpha', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: MIT License', + 'Natural Language :: English', + 'Programming Language :: Python :: 3.7', + ], + test_suite='tests', +) diff --git a/brainscore_vision/models/r50_tvpt/test.py b/brainscore_vision/models/r50_tvpt/test.py new file mode 100644 index 000000000..e594ba9e1 --- /dev/null +++ b/brainscore_vision/models/r50_tvpt/test.py @@ -0,0 +1 @@ +# Left empty as part of 2023 models migration