A head is a regular `torch.nn.Module` that can be attached to a backbone.
Arguments to FullyConnectedHead:
input_shape(ShapeSpec): input shapenum_classes(int): Number of classes for the head.pool_type(str): The pooling layer to use. Check here.drop_rate(float): If >0.0 then applies dropout between the pool_layer and the fc layer.use_conv(bool): Use a convolutional layer as the final fc layer.lr(float): Learning rate for the modules.wd(float): Weight decay for the modules.filter_wd(bool): Filter outbias,bnfromweight_decay.
input_shape = ShapeSpec(channels=512)
tst = FullyConnectedHead(input_shape, 10)
tst
input_shape = ShapeSpec(channels=512)
c = OmegaConf.structured(FCHeadDataClass(num_classes=10))
tst = FullyConnectedHead.from_config_dict(c, input_shape=input_shape)
tst
The head begins with AdaptiveConcatPool2d if concat_pool=True otherwise, it uses traditional average pooling. Then it uses a Flatten layer before going on blocks of BatchNorm, Dropout and Linear layers.
Those blocks start at in_planes, then every element of lin_ftrs (defaults to [512]) and end at num_classes. ps is a list of probabilities used for the dropouts (if you only pass 1, it will use half the value then that value as many times as necessary).
Arguments to FastaiHead:
input_shape(ShapeSpec): input shapenum_classes(int): Number of classes for the head.act(str): name of the activation function to use. If None uses the default activations else the name must be in ACTIVATION_REGISTRY. Activation layers are used after every block (BatchNorm,DropoutandLinearlayers) if it is not the last block.lin_ftrs(List): Features of the Linear layers. (defaults to [512])ps(List): list of probabilities used for the dropouts.concat_pool(bool): Wether to useAdaptiveConcatPool2dorAdaptiveAveragePool2d.first_bn(bool): BatchNorm Layer after pool.bn_final(bool): Final Layer is BatchNorm.lr(float): Learning rate for the modules.wd(float): Weight decay for the modules.filter_wd(bool): Filter outbias,bnfromweight_decay.
input_shape = ShapeSpec(channels=512)
tst = FastaiHead(input_shape=input_shape, num_classes=10)
tst
conf = OmegaConf.structured(FastaiHeadDataClass(num_classes=10))
tst = FastaiHead.from_config_dict(conf, input_shape=input_shape)
tst