Skip to content
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

Improve backbones #273

Merged
merged 8 commits into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
key: ${{ runner.os }}

- name: pytest
run: pytest --cov=solo tests/args tests/losses tests/methods tests/utils
run: pytest --cov=solo tests/args tests/backbones tests/losses tests/methods tests/utils

- name: Statistics
if: success()
Expand All @@ -61,4 +61,4 @@ jobs:
file: coverage.xml
flags: cpu
name: Coverage
fail_ci_if_error: false
fail_ci_if_error: false
4 changes: 2 additions & 2 deletions solo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2021 solo-learn development team.
# Copyright 2022 solo-learn development team.

# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
Expand All @@ -20,4 +20,4 @@

from solo import args, losses, methods, utils

__all__ = ["args", "losses", "methods", "utils"]
__all__ = ["args", "backbones", "losses", "methods", "utils"]
2 changes: 1 addition & 1 deletion solo/args/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2021 solo-learn development team.
# Copyright 2022 solo-learn development team.

# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
Expand Down
2 changes: 1 addition & 1 deletion solo/args/dataset.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2021 solo-learn development team.
# Copyright 2022 solo-learn development team.

# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
Expand Down
2 changes: 1 addition & 1 deletion solo/args/setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2021 solo-learn development team.
# Copyright 2022 solo-learn development team.

# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
Expand Down
2 changes: 1 addition & 1 deletion solo/args/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2021 solo-learn development team.
# Copyright 2022 solo-learn development team.

# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
Expand Down
56 changes: 56 additions & 0 deletions solo/backbones/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright 2022 solo-learn development team.

# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
# Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all copies
# or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
# FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.


from .convnext import convnext_tiny, convnext_small, convnext_base, convnext_large
from .poolformer import (
poolformer_s12,
poolformer_s24,
poolformer_s36,
poolformer_m36,
poolformer_m48,
)
from .resnet import resnet18, resnet50
from .swin import swin_tiny, swin_small, swin_base, swin_large
from .vit import vit_tiny, vit_small, vit_base, vit_large
from .wide_resnet import wide_resnet28w2, wide_resnet28w8

__all__ = [
"resnet18",
"resnet50",
"vit_tiny",
"vit_small",
"vit_base",
"vit_large",
"swin_tiny",
"swin_small",
"swin_base",
"swin_large",
"poolformer_s12",
"poolformer_s24",
"poolformer_s36",
"poolformer_m36",
"poolformer_m48",
"convnext_tiny",
"convnext_small",
"convnext_base",
"convnext_large",
"wide_resnet28w2",
"wide_resnet28w8",
]
42 changes: 42 additions & 0 deletions solo/backbones/convnext/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright 2022 solo-learn development team.

# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
# Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all copies
# or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
# FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

from .convnext import convnext_tiny as default_convnext_tiny
from .convnext import convnext_small as default_convnext_small
from .convnext import convnext_base as default_convnext_base
from .convnext import convnext_large as default_convnext_large


def convnext_tiny(method, *args, **kwargs):
return default_convnext_tiny(*args, **kwargs)


def convnext_small(method, *args, **kwargs):
return default_convnext_small(*args, **kwargs)


def convnext_base(method, *args, **kwargs):
return default_convnext_base(*args, **kwargs)


def convnext_large(method, *args, **kwargs):
return default_convnext_large(*args, **kwargs)


__all__ = ["convnext_tiny", "convnext_small", "convnext_base", "convnext_large"]
51 changes: 51 additions & 0 deletions solo/backbones/convnext/convnext.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright 2022 solo-learn development team.

# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
# Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all copies
# or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
# FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

# Adapted from timm https://github.com/rwightman/pytorch-image-models/blob/master/timm/

from timm.models.convnext import _create_convnext
from timm.models.registry import register_model


@register_model
def convnext_tiny(**kwargs):
model_args = dict(depths=(3, 3, 9, 3), dims=(96, 192, 384, 768), **kwargs)
model = _create_convnext("convnext_tiny", pretrained=False, num_classes=0, **model_args)
return model


@register_model
def convnext_small(**kwargs):
model_args = dict(depths=[3, 3, 27, 3], dims=[96, 192, 384, 768], **kwargs)
model = _create_convnext("convnext_small", pretrained=False, num_classes=0, **model_args)
return model


@register_model
def convnext_base(**kwargs):
model_args = dict(depths=[3, 3, 27, 3], dims=[128, 256, 512, 1024], **kwargs)
model = _create_convnext("convnext_base", pretrained=False, num_classes=0, **model_args)
return model


@register_model
def convnext_large(**kwargs):
model_args = dict(depths=[3, 3, 27, 3], dims=[192, 384, 768, 1536], **kwargs)
model = _create_convnext("convnext_large", pretrained=False, num_classes=0, **model_args)
return model
47 changes: 47 additions & 0 deletions solo/backbones/poolformer/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright 2022 solo-learn development team.

# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
# Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all copies
# or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
# FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

from .poolformer import poolformer_s12 as default_poolformer_s12
from .poolformer import poolformer_s24 as default_poolformer_s24
from .poolformer import poolformer_s36 as default_poolformer_s36
from .poolformer import poolformer_m36 as default_poolformer_m36
from .poolformer import poolformer_m48 as default_poolformer_m48


def poolformer_s12(method, *args, **kwargs):
return default_poolformer_s12(*args, **kwargs)


def poolformer_s24(method, *args, **kwargs):
return default_poolformer_s24(*args, **kwargs)


def poolformer_s36(method, *args, **kwargs):
return default_poolformer_s36(*args, **kwargs)


def poolformer_m36(method, *args, **kwargs):
return default_poolformer_m36(*args, **kwargs)


def poolformer_m48(method, *args, **kwargs):
return default_poolformer_m48(*args, **kwargs)


__all__ = ["poolformer_s12", "poolformer_s24", "poolformer_s36", "poolformer_m36", "poolformer_m48"]
Loading