I’m trying to train DeepLabV3 with a MobileNetV3 backbone on a dataset with four channels. What is the preferred way of modifying the backbone to perform this? There does not seem to be a parameter for setting the number of input channels. I can not find any as straight forward approach as when using ResNet as the backbone:
The following solution works, but it does not feel right to change a protected attribute.
from functools import partial from torch import nn from torchvision import models from torchvision.ops.misc import ConvNormActivation model = models.segmentation.deeplabv3_mobilenet_v3_large(pretrained=False, num_classes=2) model.backbone._modules['0'] = ConvNormActivation(4, 16, kernel_size=3, stride=2, norm_layer=partial(nn.BatchNorm2d, eps=0.001, momentum=0.01), activation_layer=nn.Hardswish)