Dynamic Unet Code

def Learner_create_unet(cls, data:DataBunch, arch:Callable, pretrained:bool=True,
         split_on:Optional[SplitFuncOrIdxList]=None, **kwargs:Any)->None:
"Build Unet learners."
meta = cnn_config(arch)
body = create_body(arch(pretrained), meta['cut'])
model = models.unet.DynamicUnet(body, n_classes=data.c).cuda()
learn = cls(data, model, **kwargs)
learn.split(ifnone(split_on,meta['split']))
if pretrained: learn.freeze()
apply_init(model[2], nn.init.kaiming_normal_)
return learn

for the unet code, can some one tell me what is meta is and what is meta[‘cut’] doing? I know it is cutting the model but exactly how?

What is
learn = cls(data, model, **kwargs) and learn.split(ifnone(split_on,meta['split']))

doing? What is cls specifically?

From :https://docs.fast.ai/vision.models.unet.html#UnetBlock
Where can I pass in class UnetBlock` into my models.unet.DynamicUnet()? If I

meta['cut'] contains the information to know where to cut the model of its final layers, to only keep the encoder (no max/average pooling or final linear layers). meta['split'] contains the information of how to split those layers for differential learning rates (where we give the lower learning rate, the middle ones or the higher one).

This is a factory method so cls is the class you are using, here Learner (but it could be a subclass of Learner).

The DynamicUnet already has UnetBlock, you don’t need to pass them.

1 Like

I have one question about the Unet Code: I have noticed that DynamicUnet is using F.interpolate to do the upsampling instead of transpose convolutions, also, just at the end of the model there is a transpose convolution. Can you please give me some light on why was this the choice (interpolate instead of transpose convs) and why we are still using a tranpose conv at the end.

I’m doing some segmentation on 3D medical images and want to incorporate good practices. Thanks :slight_smile:.

Yes even I think transpose convolution would produce better results as interpolation is learnable.

@sgugger can you please give us some insights about this choice (interpolation over TConv)?