basecls.layers.heads#

basecls.layers.heads.build_head(w_in, head_args=None, norm_name='BN', act_name='relu')[源代码]#

The factory function to build head.

备注

if head_args is None or head_args["name"] is None, this function will do nothing and return None.

参数
  • w_in (int) – input width.

  • head_args (Optional[Mapping[str, Any]]) – head args. Default: None

  • norm_name (str) – default normalization function, will be overridden by the same key in head_args. Default: "BN"

  • act_name (str) – default activation function, will be overridden by the same key in head_args. Default: "relu"

返回类型

Module

返回

A head.

class basecls.layers.heads.ClsHead(w_in, w_out=1000, width=0, dropout_prob=0.0, norm_name='BN', act_name='relu', bias=True)[源代码]#

基类:Module

Cls head: Conv, BN, Act, AvgPool, FC.

参数
  • w_in (int) – input width.

  • w_out (int) – output width, normally the number of classes. Default: 1000

  • width (int) – width for first conv in head, conv will be omitted if set to 0. Default: 0

  • dropout_prob (float) – dropout probability. Default: 0.0

  • norm_name (str) – normalization function. Default: "BN"

  • act_name (str) – activation function. Default: "relu"

  • bias (bool) – whether fc has bias. Default: True

forward(x)[源代码]#
返回类型

Tensor

class basecls.layers.heads.MBV3Head(w_in, w_out=1000, width=960, w_h=1280, dropout_prob=0.0, se_r=0.0, norm_name='BN', act_name='hswish', bias=True)[源代码]#

基类:Module

MobileNet V3 head: Conv, BN, Act, AvgPool, SE, FC, Act, FC.

参数
  • w_in (int) – input width.

  • w_out (int) – output width, normally the number of classes.

  • width (int) – width for first conv in head.

  • w_h (int) – width for first linear in head.

  • dropout_prob (float) – dropout probability. Default: 0.0

  • se_r (float) – Squeeze-and-Excitation (SE) ratio. Default: 0.0

  • norm_name (str) – normalization function. Default: "BN"

  • act_name (str) – activation function. Default: "hswish"

  • bias (bool) – whether fc has bias. Default: True

forward(x)[源代码]#
返回类型

Tensor

class basecls.layers.heads.VGGHead(w_in, w_out=1000, width=4096, dropout_prob=0.5, act_name='relu', **kwargs)[源代码]#

基类:Module

VGG head: AvgPool, [FC, Act, Dropout] x2, FC.

参数
  • w_in (int) – input width.

  • w_out (int) – output width, normally the number of classes. Default: 1000

  • width (int) – width for linear in head. Default: 4096

  • dropout_prob (float) – dropout probability. Default: 0.5

  • act_name (str) – activation function. Default: "relu"

forward(x)[源代码]#
返回类型

Tensor