Skip to content

Commit

Permalink
Synchronize develop with master (#1349)
Browse files Browse the repository at this point in the history
* Revert "add sam_test_resnet_3 to models (#1309)" (#1310)

This reverts commit 85ed01e.

* add sam_test_resnet_4 to models (#1313)

Co-authored-by: Jenkins <[email protected]>

* add mvimgnet_rf to models (#1339)

Co-authored-by: Jenkins <[email protected]>

* add mvimgnet_ss_00 to models (#1340)

Co-authored-by: Jenkins <[email protected]>

* add mvimgnet_ss_03 to models (#1342)

Co-authored-by: Jenkins <[email protected]>

* add mvimgnet_ss_05 to models (#1343)

Co-authored-by: Jenkins <[email protected]>

* add mvimgnet_ss_03 to models (#1345)

Co-authored-by: Jenkins <[email protected]>

* add mvimgnet_ms_05 to models (#1346)

Co-authored-by: Jenkins <[email protected]>

* add mvimgnet_ss_02 to models (#1347)

Co-authored-by: Jenkins <[email protected]>

* add mvimgnet_ss_04 to models (#1348)

Co-authored-by: Jenkins <[email protected]>

---------

Co-authored-by: Sam Winebrake <[email protected]>
Co-authored-by: Katherine Fairchild <[email protected]>
Co-authored-by: Jenkins <[email protected]>
  • Loading branch information
4 people authored Oct 15, 2024
1 parent 1acda4e commit 7349f4a
Show file tree
Hide file tree
Showing 32 changed files with 734 additions and 0 deletions.
9 changes: 9 additions & 0 deletions brainscore_vision/models/mvimgnet_ms_05/__init__.py
Original file line number Diff line number Diff line change
@@ -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["mvimgnet_ms_05"] = lambda: ModelCommitment(
identifier="mvimgnet_ms_05",
activations_model=get_model("mvimgnet_ms_05"),
layers=get_layers("mvimgnet_ms_05"),
)
64 changes: 64 additions & 0 deletions brainscore_vision/models/mvimgnet_ms_05/model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
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
from collections import OrderedDict

# 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 ["mvimgnet_ms_05"]


def get_model(name):
assert name == "mvimgnet_ms_05"
url = "https://users.flatironinstitute.org/~tyerxa/slow_steady/training_checkpoints/slow_steady/multiscale/512_10/lmda_0.5/latest-rank0.pt"
fh = urlretrieve(url)
state_dict = torch.load(fh[0], map_location=torch.device("cpu"))["state"]["model"]
model = load_composer_classifier(state_dict)
preprocessing = functools.partial(load_preprocess_images, image_size=224)
wrapper = PytorchWrapper(identifier=name, model=model, preprocessing=preprocessing)
wrapper.image_size = 224
return wrapper

def load_composer_classifier(sd):
model = torchvision.models.resnet.resnet50()
new_sd = OrderedDict()
for k, v in sd.items():
if 'lin_cls' in k:
new_sd['fc.' + k.split('.')[-1]] = v
if ".f." not in k:
continue
parts = k.split(".")
idx = parts.index("f")
new_k = ".".join(parts[idx + 1 :])
new_sd[new_k] = v
model.load_state_dict(new_sd, strict=True)
return model

def get_layers(name):
assert name == "mvimgnet_ms_05"

outs = ["layer1", "layer2", "layer3", "layer4"]
return outs


def get_bibtex(model_identifier):
return """xx"""


if __name__ == "__main__":
check_models.check_base_models(__name__)
25 changes: 25 additions & 0 deletions brainscore_vision/models/mvimgnet_ms_05/setup.py
Original file line number Diff line number Diff line change
@@ -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',
)
1 change: 1 addition & 0 deletions brainscore_vision/models/mvimgnet_ms_05/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Left empty as part of 2023 models migration
9 changes: 9 additions & 0 deletions brainscore_vision/models/mvimgnet_rf/__init__.py
Original file line number Diff line number Diff line change
@@ -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["mvimgnet_rf"] = lambda: ModelCommitment(
identifier="mvimgnet_rf",
activations_model=get_model("mvimgnet_rf"),
layers=get_layers("mvimgnet_rf"),
)
64 changes: 64 additions & 0 deletions brainscore_vision/models/mvimgnet_rf/model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
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
from collections import OrderedDict

# 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 ["mvimgnet_rf"]


def get_model(name):
assert name == "mvimgnet_rf"
url = "https://users.flatironinstitute.org/~tyerxa/slow_steady/training_checkpoints/slow_steady/r2/LARS/rf/latest-rank0.pt"
fh = urlretrieve(url)
state_dict = torch.load(fh[0], map_location=torch.device("cpu"))["state"]["model"]
model = load_composer_classifier(state_dict)
preprocessing = functools.partial(load_preprocess_images, image_size=224)
wrapper = PytorchWrapper(identifier=name, model=model, preprocessing=preprocessing)
wrapper.image_size = 224
return wrapper

def load_composer_classifier(sd):
model = torchvision.models.resnet.resnet50()
new_sd = OrderedDict()
for k, v in sd.items():
if 'lin_cls' in k:
new_sd['fc.' + k.split('.')[-1]] = v
if ".f." not in k:
continue
parts = k.split(".")
idx = parts.index("f")
new_k = ".".join(parts[idx + 1 :])
new_sd[new_k] = v
model.load_state_dict(new_sd, strict=True)
return model

def get_layers(name):
assert name == "mvimgnet_rf"

outs = ["layer1", "layer2", "layer3", "layer4"]
return outs


def get_bibtex(model_identifier):
return """xx"""


if __name__ == "__main__":
check_models.check_base_models(__name__)
25 changes: 25 additions & 0 deletions brainscore_vision/models/mvimgnet_rf/setup.py
Original file line number Diff line number Diff line change
@@ -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',
)
1 change: 1 addition & 0 deletions brainscore_vision/models/mvimgnet_rf/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Left empty as part of 2023 models migration
9 changes: 9 additions & 0 deletions brainscore_vision/models/mvimgnet_ss_00/__init__.py
Original file line number Diff line number Diff line change
@@ -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["mvimgnet_ss_00"] = lambda: ModelCommitment(
identifier="mvimgnet_ss_00",
activations_model=get_model("mvimgnet_ss_00"),
layers=get_layers("mvimgnet_ss_00"),
)
64 changes: 64 additions & 0 deletions brainscore_vision/models/mvimgnet_ss_00/model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
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
from collections import OrderedDict

# 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 ["mvimgnet_ss_00"]


def get_model(name):
assert name == "mvimgnet_ss_00"
url = "https://users.flatironinstitute.org/~tyerxa/slow_steady/training_checkpoints/slow_steady/r2/LARS/lmda_0.0/latest-rank0.pt"
fh = urlretrieve(url)
state_dict = torch.load(fh[0], map_location=torch.device("cpu"))["state"]["model"]
model = load_composer_classifier(state_dict)
preprocessing = functools.partial(load_preprocess_images, image_size=224)
wrapper = PytorchWrapper(identifier=name, model=model, preprocessing=preprocessing)
wrapper.image_size = 224
return wrapper

def load_composer_classifier(sd):
model = torchvision.models.resnet.resnet50()
new_sd = OrderedDict()
for k, v in sd.items():
if 'lin_cls' in k:
new_sd['fc.' + k.split('.')[-1]] = v
if ".f." not in k:
continue
parts = k.split(".")
idx = parts.index("f")
new_k = ".".join(parts[idx + 1 :])
new_sd[new_k] = v
model.load_state_dict(new_sd, strict=True)
return model

def get_layers(name):
assert name == "mvimgnet_ss_00"

outs = ["layer1", "layer2", "layer3", "layer4"]
return outs


def get_bibtex(model_identifier):
return """xx"""


if __name__ == "__main__":
check_models.check_base_models(__name__)
25 changes: 25 additions & 0 deletions brainscore_vision/models/mvimgnet_ss_00/setup.py
Original file line number Diff line number Diff line change
@@ -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',
)
1 change: 1 addition & 0 deletions brainscore_vision/models/mvimgnet_ss_00/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Left empty as part of 2023 models migration
9 changes: 9 additions & 0 deletions brainscore_vision/models/mvimgnet_ss_02/__init__.py
Original file line number Diff line number Diff line change
@@ -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["mvimgnet_ss_02"] = lambda: ModelCommitment(
identifier="mvimgnet_ss_02",
activations_model=get_model("mvimgnet_ss_02"),
layers=get_layers("mvimgnet_ss_02"),
)
64 changes: 64 additions & 0 deletions brainscore_vision/models/mvimgnet_ss_02/model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
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
from collections import OrderedDict

# 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 ["mvimgnet_ss_02"]


def get_model(name):
assert name == "mvimgnet_ss_02"
url = "https://users.flatironinstitute.org/~tyerxa/slow_steady/training_checkpoints/slow_steady/r2/LARS/lmda_0.2/latest-rank0.pt"
fh = urlretrieve(url)
state_dict = torch.load(fh[0], map_location=torch.device("cpu"))["state"]["model"]
model = load_composer_classifier(state_dict)
preprocessing = functools.partial(load_preprocess_images, image_size=224)
wrapper = PytorchWrapper(identifier=name, model=model, preprocessing=preprocessing)
wrapper.image_size = 224
return wrapper

def load_composer_classifier(sd):
model = torchvision.models.resnet.resnet50()
new_sd = OrderedDict()
for k, v in sd.items():
if 'lin_cls' in k:
new_sd['fc.' + k.split('.')[-1]] = v
if ".f." not in k:
continue
parts = k.split(".")
idx = parts.index("f")
new_k = ".".join(parts[idx + 1 :])
new_sd[new_k] = v
model.load_state_dict(new_sd, strict=True)
return model

def get_layers(name):
assert name == "mvimgnet_ss_02"

outs = ["layer1", "layer2", "layer3", "layer4"]
return outs


def get_bibtex(model_identifier):
return """xx"""


if __name__ == "__main__":
check_models.check_base_models(__name__)
Loading

0 comments on commit 7349f4a

Please sign in to comment.