i’m sorry about the week language.
I want to use the DeepLabV3+_resnet101 model pretrained, and to add some new connection between layers.
for example, in the first step I want to apply a new conv2d layer on the input layer and the last conv layer in the model.
I tried to looking for examples of transfer learning, but all what I find is examples of changing just the last FC layer…
I tried to take the layers form the model, and reconstuct them with some new layers, such in the following section (it’s not the model I wanted to build, it’s just a test).
import math import torch import torch.nn as nn import torch.nn.functional as F import torch.utils.model_zoo as model_zoo import torchvision.models as models class deeplab_v3_separation(nn.Module): def __init__(self): super(deeplab_v3_separation, self).__init__() deepLabV3ResNet101 = models.segmentation.deeplabv3_resnet101(pretrained=True, progress=True) features_convs_and_ASSP = list(deepLabV3ResNet101.modules()) self.features_convs_and_ASSP = torch.nn.Sequential(*features_convs_and_ASSP[:]) self.conv1 = nn.Conv2d(3, 21, kernel_size=1, bias=False) self.conv2 = nn.Conv2d(21, 5, kernel_size=1, bias=False) self.bn1 = nn.BatchNorm2d(5) def forward(self, x): x = self.features_convs_and_ASSP(x) x = self.conv1(x) x = self.conv2(x) x = self.bn1(x) return x
I would appreciate your assistance !