forked from ngxbac/Kaggle-Recursion-Cellular
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/ngxbac/Kaggle-Recursion-C…
- Loading branch information
Showing
6 changed files
with
112 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
from .resnet import ResNet | ||
from .senet import cell_senet | ||
from .senet import cell_senet, SENetTIMM | ||
from .densenet import cell_densenet | ||
from .efficientnet import EfficientNet | ||
from .efficientnet import EfficientNet | ||
from .inceptionv3 import InceptionV3TIMM | ||
from .gluon_resnet import GluonResnetTIMM |
This file contains 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,38 @@ | ||
from cnn_finetune import make_model | ||
import timm | ||
from .utils import * | ||
|
||
|
||
class GluonResnetTIMM(nn.Module): | ||
def __init__(self, model_name="gluon_resnet50_v1d", | ||
num_classes=1108, | ||
n_channels=6): | ||
super(GluonResnetTIMM, self).__init__() | ||
|
||
self.model = timm.create_model(model_name, pretrained=True, num_classes=num_classes) | ||
print(self.model) | ||
conv1 = self.model.conv1 | ||
self.model.conv1 = nn.Conv2d(in_channels=n_channels, | ||
out_channels=conv1.out_channels, | ||
kernel_size=conv1.kernel_size, | ||
stride=conv1.stride, | ||
padding=conv1.padding, | ||
bias=conv1.bias) | ||
|
||
# copy pretrained weights | ||
self.model.conv1.weight.data[:, :3, :, :] = conv1.weight.data | ||
self.model.conv1.weight.data[:, 3:n_channels, :, :] = conv1.weight.data[:, :int(n_channels - 3), :, :] | ||
|
||
def forward(self, x): | ||
return self.model(x) | ||
|
||
def freeze(self): | ||
for param in self.model.parameters(): | ||
param.requires_grad = False | ||
|
||
for param in self.model.get_classifier().parameters(): | ||
param.requires_grad = True | ||
|
||
def unfreeze(self): | ||
for param in self.model.get_classifier().parameters(): | ||
param.requires_grad = True |
This file contains 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,37 @@ | ||
from cnn_finetune import make_model | ||
import timm | ||
from .utils import * | ||
|
||
|
||
class InceptionV3TIMM(nn.Module): | ||
def __init__(self, model_name="gluon_inception_v3", | ||
num_classes=1108, | ||
n_channels=6): | ||
super(InceptionV3TIMM, self).__init__() | ||
|
||
self.model = timm.create_model(model_name, pretrained=True, num_classes=num_classes) | ||
conv1 = self.model.Conv2d_1a_3x3.conv | ||
self.model.Conv2d_1a_3x3.conv = nn.Conv2d(in_channels=n_channels, | ||
out_channels=conv1.out_channels, | ||
kernel_size=conv1.kernel_size, | ||
stride=conv1.stride, | ||
padding=conv1.padding, | ||
bias=conv1.bias) | ||
|
||
# copy pretrained weights | ||
self.model.Conv2d_1a_3x3.conv.weight.data[:, :3, :, :] = conv1.weight.data | ||
self.model.Conv2d_1a_3x3.conv.weight.data[:, 3:n_channels, :, :] = conv1.weight.data[:, :int(n_channels - 3), :, :] | ||
|
||
def forward(self, x): | ||
return self.model(x) | ||
|
||
def freeze(self): | ||
for param in self.model.parameters(): | ||
param.requires_grad = False | ||
|
||
for param in self.model.fc.parameters(): | ||
param.requires_grad = True | ||
|
||
def unfreeze(self): | ||
for param in self.model.fc.parameters(): | ||
param.requires_grad = True |
This file contains 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