This is the last block, the one fastai adds as tail of a pretrained.
It seems that v1 adds a lambda layer alongside the usual stuff. AFAIK, this is undocumented.
Assuming that such lambda is the same as keras’ lambdas (a custom anonymous layer with no trainable weights), I’d like to know what this specific lambda is intended for.
I’m on mobile now so can not verify for sure, but I remember in the notebook dev 001, there is a lambda layer to flatten a layer . Can you check it in the fastai_doc ?
When creating the classification head a Flatten layers is called:
From fastai/layers.py:
class Lambda(nn.Module):
"An easy way to create a pytorch layer for a simple `func`."
def __init__(self, func:LambdaFunc):
"create a layer that simply calls `func` with `x`"
super().__init__()
self.func=func
def forward(self, x): return self.func(x)
def Flatten()->Tensor:
"Flattens `x` to a single dimension, often used at the end of a model."
return Lambda(lambda x: x.view((x.size(0), -1)))
For more info you can see the source code for create_head (invoked within create_cnn when no custom head is defined) where a Flatten layer is added to flatten the output of AdaptiveConcatPool2d().