This module builds a dynamic U-Net from any backbone pretrained on ImageNet, automatically inferring the intermediate sizes.
from fastai.gen_doc.nbdoc import *
from fastai.vision.models.unet import *

This is the original U-Net. The difference here is that the left part is a pretrained model.
show_doc(DynamicUnet, doc_string=False)
class DynamicUnet[source]
DynamicUnet(encoder:Module,n_classes:int) ::Sequential
Builds a U-Net from a given encoder (that can be a pretrained model) and with a final output of n_classes. During the initialization, it uses Hooks to determine the intermediate features sizes by passing a dummy input throught the model.
show_doc(UnetBlock, doc_string=False)
Builds a U-Net block that receives the output of the last block to be upsampled (size up_in_c) and the activations features from an intermediate layer of the encoder (size x_in_c, this is the lateral connection). The hook is set to this intermediate layer to store the output needed for this block.
show_doc(UnetBlock.forward)
forward[source]
forward(up_in:Tensor) →Tensor
Defines the computation performed at every call. Should be overridden by all subclasses.
.. note::
Although the recipe for forward pass needs to be defined within
this function, one should call the :class:Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.