You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The most likely way to solve this is by utilizing the some PyTorch API and Python class manipulation. As you can see in the DeepLabV3 class, there is a self.encoder module (and in all pretty much all models of this library). You should instantiate your DeepLabV3 model, and modify the encoder.
importsegmentation_models_pytorchassmpmodel=smp.DeepLabV3(
encoder_name="resnet34", # or any other backboneencoder_weights="imagenet",
in_channels=3,
classes=1,
)
model.encoder=<modified_encoder>
For simplicity, let's assume the encoder was created with timm.create_model(). The following function modifies the dilation rate of every Conv2d module present in the resnet34 "layer4" backbone. You should be careful, as this may require you to manually change other attributes, such as kernel_size, stride, and padding.
importtorchimporttorch.nnasnnimporttimmencoder=timm.create_model('resnet34')
defupdate_dilation(module):
forname, childinmodule.named_children():
ifisinstance(child, nn.Conv2d):
child.dilation= (2, 2)
child.kernel_size= ...
else:
update_dilation(child)
returnmodulemodule=encoder.layer4updated_module=update_dilation(module)
encoder.layer4=updated_moduleprint(encoder) # to see the changes made
If you want to modify specific convolutions in different layers, you need to understand the backbone structure you're working with an perhaps manually access them in order to make the desired modifications.
Is there any way to change the dilation rate of the convolution layers in the last few layers (like DeepLabV3 style) through the SMP API?
The text was updated successfully, but these errors were encountered: