-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Genet from timm #344
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
Merged
Merged
Genet from timm #344
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3511221
gernet from regnet
AlexanderYaroshevichIAC 099c08f
basic gernet
AlexanderYaroshevichIAC cc42d1c
depth set to 5, and requirements+import update
AlexanderYaroshevichIAC bc92a9f
docs
AlexanderYaroshevichIAC 3b1961b
Fix summary error
AlexanderYaroshevichIAC 97f8114
remove input size
AlexanderYaroshevichIAC e5e19dc
manet fix and test with latest timm
AlexanderYaroshevichIAC 0d8c7a6
Merge branch 'master' into master
qubvel 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
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
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
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
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,121 @@ | ||
from timm.models import ByobCfg, BlocksCfg, ByobNet | ||
|
||
from ._base import EncoderMixin | ||
import torch.nn as nn | ||
|
||
|
||
class GERNetEncoder(ByobNet, EncoderMixin): | ||
def __init__(self, out_channels, depth=5, **kwargs): | ||
super().__init__(**kwargs) | ||
self._depth = depth | ||
self._out_channels = out_channels | ||
self._in_channels = 3 | ||
|
||
del self.head | ||
|
||
def get_stages(self): | ||
return [ | ||
nn.Identity(), | ||
self.stem, | ||
self.stages[0], | ||
self.stages[1], | ||
self.stages[2], | ||
nn.Sequential(self.stages[3], self.stages[4], self.final_conv) | ||
] | ||
Vozf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def forward(self, x): | ||
stages = self.get_stages() | ||
|
||
features = [] | ||
for i in range(self._depth + 1): | ||
x = stages[i](x) | ||
features.append(x) | ||
|
||
return features | ||
|
||
def load_state_dict(self, state_dict, **kwargs): | ||
state_dict.pop("head.fc.weight") | ||
state_dict.pop("head.fc.bias") | ||
super().load_state_dict(state_dict, **kwargs) | ||
|
||
|
||
regnet_weights = { | ||
'timm-gernet_s': { | ||
'imagenet': 'https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-ger-weights/gernet_s-756b4751.pth', | ||
}, | ||
'timm-gernet_m': { | ||
'imagenet': 'https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-ger-weights/gernet_m-0873c53a.pth', | ||
}, | ||
'timm-gernet_l': { | ||
'imagenet': 'https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-ger-weights/gernet_l-f31e2e8d.pth', | ||
}, | ||
} | ||
|
||
pretrained_settings = {} | ||
for model_name, sources in regnet_weights.items(): | ||
pretrained_settings[model_name] = {} | ||
for source_name, source_url in sources.items(): | ||
pretrained_settings[model_name][source_name] = { | ||
"url": source_url, | ||
'input_range': [0, 1], | ||
'mean': [0.485, 0.456, 0.406], | ||
'std': [0.229, 0.224, 0.225], | ||
'num_classes': 1000 | ||
} | ||
|
||
timm_gernet_encoders = { | ||
'timm-gernet_s': { | ||
'encoder': GERNetEncoder, | ||
"pretrained_settings": pretrained_settings["timm-gernet_s"], | ||
'params': { | ||
'out_channels': (3, 13, 48, 48, 384, 1920), | ||
'cfg': ByobCfg( | ||
blocks=( | ||
BlocksCfg(type='basic', d=1, c=48, s=2, gs=0, br=1.), | ||
BlocksCfg(type='basic', d=3, c=48, s=2, gs=0, br=1.), | ||
BlocksCfg(type='bottle', d=7, c=384, s=2, gs=0, br=1 / 4), | ||
BlocksCfg(type='bottle', d=2, c=560, s=2, gs=1, br=3.), | ||
BlocksCfg(type='bottle', d=1, c=256, s=1, gs=1, br=3.), | ||
), | ||
stem_chs=13, | ||
num_features=1920, | ||
) | ||
}, | ||
}, | ||
'timm-gernet_m': { | ||
'encoder': GERNetEncoder, | ||
"pretrained_settings": pretrained_settings["timm-gernet_m"], | ||
'params': { | ||
'out_channels': (3, 32, 128, 192, 640, 2560), | ||
'cfg': ByobCfg( | ||
blocks=( | ||
BlocksCfg(type='basic', d=1, c=128, s=2, gs=0, br=1.), | ||
BlocksCfg(type='basic', d=2, c=192, s=2, gs=0, br=1.), | ||
BlocksCfg(type='bottle', d=6, c=640, s=2, gs=0, br=1 / 4), | ||
BlocksCfg(type='bottle', d=4, c=640, s=2, gs=1, br=3.), | ||
BlocksCfg(type='bottle', d=1, c=640, s=1, gs=1, br=3.), | ||
), | ||
stem_chs=32, | ||
num_features=2560, | ||
) | ||
}, | ||
}, | ||
'timm-gernet_l': { | ||
'encoder': GERNetEncoder, | ||
"pretrained_settings": pretrained_settings["timm-gernet_l"], | ||
'params': { | ||
'out_channels': (3, 32, 128, 192, 640, 2560), | ||
'cfg': ByobCfg( | ||
blocks=( | ||
BlocksCfg(type='basic', d=1, c=128, s=2, gs=0, br=1.), | ||
BlocksCfg(type='basic', d=2, c=192, s=2, gs=0, br=1.), | ||
BlocksCfg(type='bottle', d=6, c=640, s=2, gs=0, br=1 / 4), | ||
BlocksCfg(type='bottle', d=5, c=640, s=2, gs=1, br=3.), | ||
BlocksCfg(type='bottle', d=4, c=640, s=1, gs=1, br=3.), | ||
), | ||
stem_chs=32, | ||
num_features=2560, | ||
) | ||
}, | ||
}, | ||
} |
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
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.
This inherits from byobnet same as new repvgg so we should consider adding generic ByoBnetEncoder to comply with future timm changes https://github.com/rwightman/pytorch-image-models/blob/d8e69206be253892b2956341fea09fdebfaae4e3/timm/models/byobnet.py#L645