zae_engine.nn_night.blocks package

Submodules

zae_engine.nn_night.blocks.conv_block module

class zae_engine.nn_night.blocks.conv_block.ConvBlock(ch_in: int = 3, ch_out: int = 3, kernel_size: int | ~typing.Tuple[int, int] = 3, dilate: int = 1, pre_norm: bool = False, conv_layer: ~torch.nn.modules.module.Module = <class 'torch.nn.modules.conv.Conv2d'>, norm_layer: ~torch.nn.modules.module.Module = <class 'torch.nn.modules.batchnorm.BatchNorm2d'>, act_layer: ~torch.nn.modules.module.Module = <class 'torch.nn.modules.activation.ReLU'>)[소스]

기반 클래스: Module

forward(x: Tensor) Tensor[소스]

Forward pass through the ConvBlock block.

매개변수:

x (torch.Tensor) – Input tensor of shape (batch_size, channel_in, height, width).

반환:

Output tensor of shape (batch_size, channel_out, height, width).

반환 형식:

torch.Tensor

kernel_type

Residual Block with Convolution, Batch Normalization, and ReLU Activation.

This module performs a convolution followed by batch normalization and ReLU activation. It serves as a fundamental building block in the RSU (Residual U-block) structure.

매개변수:
  • ch_in (int, optional) – Number of input channels. Default is 3.

  • ch_out (int, optional) – Number of output channels. Default is 3.

  • dilate (int, optional) – Dilation rate for the convolution. Default is 1.

int | Tuple[int, int]의 별칭

zae_engine.nn_night.blocks.resblock module

class zae_engine.nn_night.blocks.resblock.BasicBlock(ch_in: int, ch_out: int, stride: int = 1, groups: int = 1, dilation: int = 1, norm_layer: ~typing.Callable[[...], ~torch.nn.modules.module.Module] = <class 'torch.nn.modules.batchnorm.BatchNorm2d'>)[소스]

기반 클래스: Module

Basic residual block.

매개변수:
  • ch_in (int) – Number of input channels.

  • ch_out (int) – Number of output channels.

  • stride (int, optional) – Stride of the convolution. Default is 1.

  • groups (int, optional) – Number of groups for the convolution. Default is 1.

  • dilation (int, optional) – Dilation for the convolution. Default is 1.

  • norm_layer (Callable[..., nn.Module], optional) – Normalization layer to use. Default is nn.BatchNorm2d.

참조

He, K., Zhang, X., Ren, S., & Sun, J. (2016). Deep residual learning for image recognition. In Proceedings of the IEEE conference on computer vision and pattern recognition (pp. 770-778).

expansion: int = 1
forward(x: Tensor) Tensor[소스]

Defines the computation performed at every call.

Should be overridden by all subclasses.

참고

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class zae_engine.nn_night.blocks.resblock.Bottleneck(ch_in: int, ch_out: int, stride: int = 1, groups: int = 1, dilation: int = 1, norm_layer: ~typing.Callable[[...], ~torch.nn.modules.module.Module] = <class 'torch.nn.modules.batchnorm.BatchNorm2d'>)[소스]

기반 클래스: Module

Bottleneck residual block.

매개변수:
  • ch_in (int) – Number of input channels.

  • ch_out (int) – Number of output channels.

  • stride (int, optional) – Stride of the convolution. Default is 1.

  • groups (int, optional) – Number of groups for the convolution. Default is 1.

  • dilation (int, optional) – Dilation for the convolution. Default is 1.

  • norm_layer (Callable[..., nn.Module], optional) – Normalization layer to use. Default is nn.BatchNorm2d.

참조

He, K., Zhang, X., Ren, S., & Sun, J. (2016). Deep residual learning for image recognition. In Proceedings of the IEEE conference on computer vision and pattern recognition (pp. 770-778).

expansion: int = 4
forward(x: Tensor) Tensor[소스]

Defines the computation performed at every call.

Should be overridden by all subclasses.

참고

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

zae_engine.nn_night.blocks.spatial_attention module

class zae_engine.nn_night.blocks.spatial_attention.CBAM1d(ch_in: int, kernel_size: int | Tuple[int] = 7, reduction: int = 8, bias: bool = False, conv_pool: bool = False, *args, **kwargs)[소스]

기반 클래스: Module

Convolutional Block Attention Module for 1D inputs.

This module implements the Convolutional Block Attention Module (CBAM).

매개변수:
  • ch_in (int) – The channel-wise dimension of the input tensor.

  • kernel_size (_size_1_t, optional) – The kernel size for the convolutional layer. Default is 7.

  • reduction (int, optional) – The reduction ratio for the SE block. Default is 8. Must be a divisor of ch_in.

  • bias (bool, optional) – Whether to use bias in the convolutional and fully connected layers. Default is False.

  • conv_pool (bool, optional) – If True, use convolutional pooling for the spatial attention mechanism. Default is False.

참조

forward(x)[소스]

Defines the computation performed at every call.

Should be overridden by all subclasses.

참고

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

spatial_wise(x: Tensor)[소스]
class zae_engine.nn_night.blocks.spatial_attention.SE1d(ch_in: int, reduction: int = 8, bias: bool = False, *args, **kwargs)[소스]

기반 클래스: Module

Squeeze and Excitation module for 1D inputs.

This module implements the Squeeze and Excitation (SE) block.

매개변수:
  • ch_in (int) – The channel-wise dimension of the input tensor.

  • reduction (int, optional) – The reduction ratio for the SE block. Default is 8. Must be a divisor of ch_in.

  • bias (bool, optional) – Whether to use bias in the fully connected layers. Default is False.

참조

channel_wise(x)[소스]
forward(x)[소스]

Defines the computation performed at every call.

Should be overridden by all subclasses.

참고

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

zae_engine.nn_night.blocks.unet_block module

class zae_engine.nn_night.blocks.unet_block.RSUBlock(ch_in: int, ch_mid: int, ch_out: int, height: int = 7, dilation_height: int = 7, pool_size: int = 2)[소스]

기반 클래스: Module

Recurrent Residual U-block (RSU) implementation.

매개변수:
  • ch_in (int) – Number of input channels.

  • ch_mid (int) – Number of middle channels.

  • ch_out (int) – Number of output channels.

  • height (int) – Number of layers in the RSU block (e.g., RSU4 has height=4, RSU7 has height=7).

  • dilation_height (int) – Dilation rate for convolutions within the block.

  • pool_size (int, optional) – Pooling kernel size. Default is 2.

참조

down_layer(at_first: bool = False)[소스]

Returns a downsampling layer or identity based on the position.

forward(x: Tensor) Tensor[소스]

Forward pass through the RSUBlock.

매개변수:

x (torch.Tensor) – Input tensor of shape (batch_size, channels, height, width).

반환:

Output tensor of shape (batch_size, out_ch, height, width).

반환 형식:

torch.Tensor

up_layer(at_last: bool = False)[소스]

Returns an upsampling layer or identity based on the position.

class zae_engine.nn_night.blocks.unet_block.UNetBlock(ch_in: int, ch_out: int, stride: int = 1, groups: int = 1, norm_layer: ~typing.Callable[[...], ~torch.nn.modules.module.Module] = <class 'torch.nn.modules.batchnorm.BatchNorm2d'>, *args, **kwargs)[소스]

기반 클래스: BasicBlock

Two times of [Conv-normalization-activation] block for UNet architecture.

This module is a modified version of the BasicBlock used in ResNet, adapted for the UNet architecture.

매개변수:
  • ch_in (int) – The number of input channels.

  • ch_out (int) – The number of output channels.

  • stride (int, optional) – The stride of the convolution. Default is 1.

  • groups (int, optional) – The number of groups for the convolution. Default is 1.

  • norm_layer (Callable[..., nn.Module], optional) – The normalization layer to use. Default is nn.BatchNorm2d.

expansion

The expansion factor of the block, set to 1.

Type:

int

참조

expansion: int = 1
forward(x: Tensor) Tensor[소스]

Forward pass for the UNetBlock.

매개변수:

x (Tensor) – Input tensor.

반환:

Output tensor after applying the block operations.

반환 형식:

Tensor

Module contents