resnet
ResNet
Overview
ResNet is a type of convolutional neural network (CNN) that is commonly used for image classification tasks. ResNet is a fully convolutional network that consists of a series of convolutional layers and pooling layers. The pooling layers are used to downsample the input while the convolutional layers are used to upsample the input. The skip connections between the pooling layers and convolutional layers allow ResNet to preserve spatial/temporal information while also allowing for faster training and inference times.
For more info, refer to the original paper Deep Residual Learning for Image Recognition.
Classes:
-
ResNetParams
–ResNet parameters
-
ResNetModel
–Helper class to generate model from parameters
Functions:
-
generate_bottleneck_block
–Generate functional bottleneck block
-
generate_residual_block
–Generate functional residual block
-
resnet_layer
–Generate functional ResNet model
Additions
- Enable 1D and 2D variants.
Classes
ResNetBlockParams
ResNetParams
ResNet parameters
Attributes:
-
blocks
(list[ResNetBlockParams]
) –ResNet blocks
-
input_filters
(int
) –Input filters
-
input_kernel_size
(int | tuple[int, int]
) –Input kernel size
-
input_strides
(int | tuple[int, int]
) –Input stride
-
input_activation
(str
) –Input activation
-
include_top
(bool
) –Include top
-
output_activation
(str | None
) –Output activation
-
dropout
(float
) –Dropout rate
-
name
(str
) –Model name
ResNetModel
Helper class to generate model from parameters
Functions
layer_from_params
staticmethod
Create layer from parameters
Source code in neuralspot_edge/models/resnet.py
model_from_params
staticmethod
Create model from parameters
Source code in neuralspot_edge/models/resnet.py
Functions
generate_bottleneck_block
generate_bottleneck_block(filters: int, kernel_size: int | tuple[int, int] = 3, strides: int | tuple[int, int] = 1, expansion: int = 4, activation: str = 'relu6') -> keras.Layer
Generate functional bottleneck block.
Parameters:
-
filters
(int
) –Filter size
-
kernel_size
(int | tuple[int, int]
, default:3
) –Kernel size. Defaults to 3.
-
strides
(int | tuple[int, int]
, default:1
) –Stride length. Defaults to 1.
-
expansion
(int
, default:4
) –Expansion factor. Defaults to 4.
Returns:
-
Layer
–keras.Layer: TF functional layer
Source code in neuralspot_edge/models/resnet.py
generate_residual_block
generate_residual_block(filters: int, kernel_size: int | tuple[int, int] = 3, strides: int | tuple[int, int] = 1, activation: str = 'relu6') -> keras.Layer
Generate functional residual block
Parameters:
-
filters
(int
) –Filter size
-
kernel_size
(int | tuple[int, int]
, default:3
) –Kernel size. Defaults to 3.
-
strides
(int | tuple[int, int]
, default:1
) –Stride length. Defaults to 1.
Returns:
-
Layer
–keras.Layer: TF functional layer
Source code in neuralspot_edge/models/resnet.py
resnet_layer
resnet_layer(x: keras.KerasTensor, params: ResNetParams, num_classes: int | None = None) -> keras.KerasTensor
Generate functional ResNet model. Args: x (keras.KerasTensor): Inputs params (ResNetParams): Model parameters. num_classes (int, optional): Number of class outputs. Defaults to None.
Returns:
-
KerasTensor
–keras.KerasTensor: Output tensor