-
Notifications
You must be signed in to change notification settings - Fork 99
brain-score.org submission (user:672) | (public:False) #2308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
KartikP
wants to merge
1
commit into
master
Choose a base branch
from
web_submission_1107/add_plugins
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 brainscore_vision.model_helpers.brain_transformation import ModelCommitment | ||
| from .model import get_model, get_layers | ||
|
|
||
| model_registry['resnet50_st_wzc_seed6_2'] = lambda: ModelCommitment(identifier='resnet50_st_wzc_seed6_2', activations_model=get_model('resnet50_st_wzc_seed6_2'), layers=get_layers('resnet50_st_wzc_seed6_2')) |
This file contains hidden or 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,99 @@ | ||
| from brainscore_vision.model_helpers.check_submission import check_models | ||
| import functools | ||
| import numpy as np | ||
| from PIL import Image | ||
| import torch | ||
| import torchvision.transforms as transforms | ||
| import torchvision.models | ||
| from brainscore_vision.model_helpers.activations.pytorch import PytorchWrapper | ||
| from brainscore_vision.model_helpers.activations.pytorch import load_preprocess_images | ||
|
|
||
| # 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.s3 import load_file | ||
| device = torch.device("cpu") | ||
|
|
||
| def get_model_list(): | ||
| return ['resnet50_st_wzc_seed6_2'] | ||
|
|
||
| def get_model(name): | ||
| assert name == 'resnet50_st_wzc_seed6_2' | ||
|
|
||
| file_path = load_file(bucket="brainscore-storage", folder_name="brainscore-vision/models/user_672/", | ||
| relative_path="resnet50_st_seed6_checkpoint_89.pth", | ||
| version_id="IqRckizpWZw_OJ8yENF7Uph8DEBe4kaV", | ||
| ), | ||
|
|
||
| checkpoint = torch.load(str(file_path[0]), map_location=lambda storage, loc: storage) | ||
| new_state_dict = {} | ||
| for key, value in checkpoint["state_dict"].items(): | ||
| new_key = key.replace('module.', '', 1) | ||
| new_state_dict[new_key] = value | ||
|
|
||
| model = torchvision.models.__dict__["resnet50"]() | ||
| model.load_state_dict(new_state_dict, strict=True) | ||
| model.to(device) | ||
| model.eval() | ||
| # model = torchvision.models.resnet50(pretrained=True) | ||
| preprocessing = functools.partial(load_preprocess_images_change, image_size=224) | ||
| wrapper = PytorchWrapper(identifier='resnet50_st_wzc_seed6_2', model=model, preprocessing=preprocessing) | ||
| wrapper.image_size = 224 | ||
| return wrapper | ||
|
|
||
| # def get_layers(name): | ||
| # assert name == 'resnet50_st_wzc' | ||
| #return ['conv1','layer1', 'layer2', 'layer3', 'layer4', 'fc'] | ||
| def get_layers(name): | ||
| assert name == 'resnet50_st_wzc_seed6_2' | ||
| layer_names = (['conv1'] + [f'layer1.{i}' for i in range(3)] + | ||
| [f'layer2.{i}' for i in range(4)] + | ||
| [f'layer3.{i}' for i in range(6)] + | ||
| [f'layer4.{i}' for i in range(3)] + ['avgpool']) | ||
| # layer_names = (['conv1'] + [f'layer1.{0}'] + | ||
| # [f'layer2.{0}'] + | ||
| # [f'layer3.{0}'] + | ||
| # [f'layer4.{0}'] + [f'layer4.{2}'] + ['avgpool']) | ||
| return layer_names | ||
|
|
||
|
|
||
| def get_bibtex(model_identifier): | ||
| return """""" | ||
|
|
||
| #-------------------------------------------------------------------- | ||
|
|
||
|
|
||
| def load_preprocess_images_change(image_filepaths, image_size, **kwargs): | ||
| images = [load_image(image_filepath) for image_filepath in image_filepaths] #load_images(image_filepaths) | ||
| images = preprocess_images_change(images, image_size=image_size, **kwargs) | ||
| return images | ||
|
|
||
| def load_image(image_filepath): | ||
| with Image.open(image_filepath) as pil_image: | ||
| if 'L' not in pil_image.mode.upper() and 'A' not in pil_image.mode.upper() \ | ||
| and 'P' not in pil_image.mode.upper(): # not binary and not alpha and not palletized | ||
| # work around to https://github.com/python-pillow/Pillow/issues/1144, | ||
| # see https://stackoverflow.com/a/30376272/2225200 | ||
| return pil_image.copy() | ||
| else: # make sure potential binary images are in RGB | ||
| rgb_image = Image.new("RGB", pil_image.size) | ||
| rgb_image.paste(pil_image) | ||
| return rgb_image | ||
|
|
||
| def preprocess_images_change(images, image_size, **kwargs): | ||
| preprocess = transforms.Compose([ | ||
| transforms.Resize((image_size, image_size)), | ||
| transforms.ToTensor(), | ||
| lambda img: img.unsqueeze(0) | ||
| ]) | ||
| images = [preprocess(image) for image in images] | ||
| images = np.concatenate(images) | ||
| return images | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| check_models.check_base_models(__name__) | ||
6 changes: 6 additions & 0 deletions
6
...score_vision/models/resnet50_st_wzc_seed6_2/region_layer_map/resnet50_st_wzc_seed6_2.json
This file contains hidden or 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,6 @@ | ||
| { | ||
| "V1": "layer1.0", | ||
| "V2": "layer3.0", | ||
| "V4": "layer3.0", | ||
| "IT": "layer4.0" | ||
| } |
2 changes: 2 additions & 0 deletions
2
brainscore_vision/models/resnet50_st_wzc_seed6_2/requirements.txt
This file contains hidden or 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 @@ | ||
| torchvision | ||
| torch |
This file contains hidden or 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,8 @@ | ||
| import pytest | ||
| import brainscore_vision | ||
|
|
||
|
|
||
| @pytest.mark.travis_slow | ||
| def test_has_identifier(): | ||
| model = brainscore_vision.load_model('resnet50_st_wzc_seed6_2') | ||
| assert model.identifier == 'resnet50_st_wzc_seed6_2' |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s3.py in
model_helpershas been deprecated and move tobrainscore_core.supported_data_standards.brainio