piscis.networks.conv#

Attributes#

Classes#

Conv

Convolutional block with batch norm and activation.

SqueezeExcite

Squeeze and excite block.

MBConv

Mobile inverted bottleneck convolutional block.

FusedMBConv

Fused mobile inverted bottleneck convolutional block.

Module Contents#

piscis.networks.conv.ModuleDef#
class piscis.networks.conv.Conv(in_channels: int, out_channels: int, kernel_size: int | Sequence[int] = 3, stride: int | Sequence[int] = 1, padding: int | Sequence[int] | str | None = None, dilation: int | Sequence[int] = 1, groups: int = 1, bias: bool | None = None, padding_mode: str = 'zeros', conv: ModuleDef = nn.Conv2d, bn: ModuleDef = nn.BatchNorm2d, act: ModuleDef = nn.SiLU, layers: Sequence[str] = ('conv', 'bn', 'act'))#

Bases: torch.nn.Module

Convolutional block with batch norm and activation.

Parameters:
in_channelsint

Number of input channels.

out_channelsint

Number of output channels.

kernel_sizeUnion[int, Sequence[int]]

Size of the convolutional kernel. Default is 3.

strideUnion[int, Sequence[int]]

Stride of the convolution. Default is 1.

paddingOptional[Union[int, Sequence[int], str]], optional

Padding of the convolution. Default is None.

dilationUnion[int, Sequence[int]], optional

Dilation of the convolution. Default is 1.

groupsint, optional

Number of groups of the convolution. Default is 1.

biasOptional[bool], optional

Whether to use bias in the convolution. Default is None.

padding_modestr, optional

Padding mode of the convolution. Default is ‘zeros’.

convModuleDef, optional

Convolution module. Default is nn.Conv2d.

bnModuleDef, optional

Batch norm module. Default is nn.BatchNorm2d.

actModuleDef, optional

Activation function. Default is nn.SiLU.

layersSequence[str], optional

Sequence of layers to apply. Default is (‘conv’, ‘bn’, ‘act’).

conv#
forward(x)#
piscis.networks.conv.ConvBatchAct#
class piscis.networks.conv.SqueezeExcite(in_channels: int, squeeze_channels: int, conv: ModuleDef = nn.Conv2d, act: ModuleDef = nn.SiLU)#

Bases: torch.nn.Module

Squeeze and excite block.

Parameters:
in_channelsint

Number of input channels.

squeeze_channelsint

Number of squeeze channels.

convModuleDef, optional

Convolution module. Default is nn.Conv2d.

actModuleDef, optional

Activation function. Default is nn.SiLU.

reduce#
act#
expand#
sigmoid#
forward(x: torch.Tensor) torch.Tensor#
class piscis.networks.conv.MBConv(in_channels: int, out_channels: int, expand_ratio: int, kernel_size: int | Sequence[int], stride: int, se_ratio: float, stochastic_depth_prob: float, conv: ModuleDef = nn.Conv2d, bn: ModuleDef = nn.BatchNorm2d, act: ModuleDef = nn.SiLU)#

Bases: torch.nn.Module

Mobile inverted bottleneck convolutional block.

Parameters:
in_channelsint

Number of input channels.

out_channelsint

Number of output channels.

expand_ratioint

Expansion ratio.

kernel_sizeUnion[int, Sequence[int]]

Size of the convolutional kernel.

strideint

Stride of the convolution.

se_ratiofloat

Squeeze and excitation ratio.

stochastic_depth_probfloat

Stochastic depth probability.

convModuleDef, optional

Convolution module. Default is nn.Conv2d.

bnModuleDef, optional

Batch norm module. Default is nn.BatchNorm2d.

actModuleDef, optional

Activation function. Default is nn.SiLU.

block#
use_res_connect#
stochastic_depth#
forward(x: torch.Tensor) torch.Tensor#
class piscis.networks.conv.FusedMBConv(in_channels: int, out_channels: int, expand_ratio: int, kernel_size: int | Sequence[int], stride: int, se_ratio: float, stochastic_depth_prob: float, conv: ModuleDef = nn.Conv2d, bn: ModuleDef = nn.BatchNorm2d, act: ModuleDef = nn.SiLU)#

Bases: torch.nn.Module

Fused mobile inverted bottleneck convolutional block.

Parameters:
in_channelsint

Number of input channels.

out_channelsint

Number of output channels.

expand_ratioint

Expansion ratio.

kernel_sizeUnion[int, Sequence[int]]

Size of the convolutional kernel.

strideint

Stride of the convolution.

se_ratiofloat

Squeeze and excitation ratio.

stochastic_depth_probfloat

Stochastic depth probability.

convModuleDef, optional

Convolution module. Default is nn.Conv2d.

bnModuleDef, optional

Batch norm module. Default is nn.BatchNorm2d.

actModuleDef, optional

Activation function. Default is nn.SiLU.

block#
use_res_connect#
stochastic_depth#
forward(x: torch.Tensor) torch.Tensor#