basecls.layers#
- class basecls.layers.ELU(alpha=1.0, name=None)[源代码]#
基类:
ModuleELU activation function.
\[\begin{split}\text{ELU}(x) = \begin{cases} x, & \text{if } x > 0, \\ \alpha \left( \exp(x) - 1 \right), & \text{if } x \le 0 \end{cases}\end{split}\]- 参数
alpha (
float) – the \(\alpha\) value for the ELU formulation. Default:1.0
- class basecls.layers.HSigmoid(name=None)[源代码]#
基类:
ModuleHard sigmoid activation function.
\[\begin{split}\text{HSigmoid}(x) = \begin{cases} 0 & \text{if } x \le -3, \\ 1 & \text{if } x \ge 3, \\ x / 6 + 1 / 2 & \text{otherwise} \end{cases}\end{split}\]
- class basecls.layers.HSwish(name=None)[源代码]#
基类:
ModuleHard swish activation function.
\[\begin{split}\text{HSwish}(x) = \begin{cases} 0 & \text{if } x \le -3, \\ x & \text{if } x \ge 3, \\ x (x + 3) / 6 & \text{otherwise} \end{cases}\end{split}\]
- class basecls.layers.ReLU6(name=None)[源代码]#
基类:
ModuleReLU6 activation function.
\[\text{ReLU6}(x) = \min \left( \max(0, x), 6 \right)\]
- class basecls.layers.Tanh(name=None)[源代码]#
基类:
ModuleTanh activation function.
\[\text{Tanh}(x) = \text{tanh}(x) = \frac{\exp(x) - \exp(-x)}{\exp(x) + \exp(-x)}\]
- class basecls.layers.ClsHead(w_in, w_out=1000, width=0, dropout_prob=0.0, norm_name='BN', act_name='relu', bias=True)[源代码]#
基类:
ModuleCls head: Conv, BN, Act, AvgPool, FC.
- 参数
w_in (
int) – input width.w_out (
int) – output width, normally the number of classes. Default:1000width (
int) – width for first conv in head, conv will be omitted if set to 0. Default:0dropout_prob (
float) – dropout probability. Default:0.0norm_name (
str) – normalization function. Default:"BN"act_name (
str) – activation function. Default:"relu"bias (
bool) – whether fc has bias. Default:True
- class basecls.layers.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)[源代码]#
基类:
ModuleMobileNet 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.0se_r (
float) – Squeeze-and-Excitation (SE) ratio. Default:0.0norm_name (
str) – normalization function. Default:"BN"act_name (
str) – activation function. Default:"hswish"bias (
bool) – whether fc has bias. Default:True
- class basecls.layers.VGGHead(w_in, w_out=1000, width=4096, dropout_prob=0.5, act_name='relu', **kwargs)[源代码]#
基类:
ModuleVGG head: AvgPool, [FC, Act, Dropout] x2, FC.
- 参数
- basecls.layers.build_head(w_in, head_args=None, norm_name='BN', act_name='relu')[源代码]#
The factory function to build head.
备注
if
head_argsisNoneorhead_args["name"]isNone, this function will do nothing and returnNone.- 参数
w_in (
int) – input width.head_args (
Optional[Mapping[str,Any]]) – head args. Default:Nonenorm_name (
str) – default normalization function, will be overridden by the same key inhead_args. Default:"BN"act_name (
str) – default activation function, will be overridden by the same key inhead_args. Default:"relu"
- 返回类型
- 返回
A head.
- class basecls.layers.BinaryCrossEntropy(**kwargs)[源代码]#
基类:
ModuleThe module for binary cross entropy.
See
binary_cross_entropy()for more details.
- class basecls.layers.CrossEntropy(axis=1, label_smooth=0.0)[源代码]#
基类:
ModuleThe module for cross entropy.
It supports both categorical labels and one-hot labels. See
cross_entropy()for more details.
- basecls.layers.build_loss(cfg)[源代码]#
The factory function to build loss.
- 参数
cfg (
ConfigDict) – config for building loss function.- 返回类型
- 返回
A loss function.
- class basecls.layers.SE(w_in, w_se, act_name, approx_sigmoid=False)[源代码]#
基类:
ModuleSqueeze-and-Excitation (SE) block: AvgPool, FC, Act, FC, Sigmoid.
- 参数
- avg_pool#
gad2d layer.
- f_ex#
sequantial which conbines conv2d -> act -> conv2d -> sigmoid.
- class basecls.layers.DropPath(drop_prob=0.0, **kwargs)[源代码]#
基类:
DropoutDropPath block.
- 参数
drop_prob – the probability to drop (set to zero) each path.
- basecls.layers.conv2d(w_in, w_out, k, *, stride=1, dilation=1, groups=1, bias=False)[源代码]#
Helper for building a conv2d layer.
It will calculate padding automatically.
- basecls.layers.gap2d(shape=1)[源代码]#
Helper for building a gap2d layer.
- 参数
shape – output shape. Default:
1- 返回类型
- 返回
A gap2d module.
- basecls.layers.adjust_block_compatibility(ws, bs, gs)[源代码]#
Adjusts the compatibility of widths, bottlenecks and groups.
- basecls.layers.compute_precise_bn_stats(cfg, model, dataloader)[源代码]#
Computes precise BN stats on training data.
References: facebookresearch/pycls
- 参数
cfg (
ConfigDict) – config for precising BN.model (
Module) – model for precising BN.dataloader (
Union[DataLoader,FakeDataLoader]) – dataloader for precising BN.
- basecls.layers.init_vit_weights(module)[源代码]#
Initialization for Vision Transformer (ViT).
References: rwightman/pytorch-image-models
- 参数
m – module to be initialized.
- basecls.layers.init_weights(m, pytorch_style=False, zero_init_final_gamma=False)[源代码]#
Performs ResNet-style weight initialization.
About zero-initialize: Zero-initialize the last BN in each residual branch, so that the residual branch starts with zeros, and each residual block behaves like an identity. This improves the model by 0.2~0.3% according to https://arxiv.org/abs/1706.02677.
References: facebookresearch/pycls