conformer
Conformer Model
Conformer model implementation in Keras.
Classes:
-
SubsampleBlockParams
–Subsample block parameters
-
ConformerBlockParams
–Conformer block parameters
-
ConformerParams
–Conformer parameters
-
ConformerModel
–Helper class to generate model from parameters
Functions:
-
subsampler
–Subsampler block
-
fc_block
–Fully connected block
-
conv_block
–Convolutional block
-
att_block
–Attention block
-
conformer_block
–Conformer block
-
conformer_layer
–Conformer functional layer
Classes
SubsampleBlockParams
ConformerBlockParams
Conformer block parameters
Attributes:
-
depth
(int
) –Depth
-
fc_ex_factor
(float
) –FC expansion factor
-
fc_res_factor
(float
) –FC residual factor
-
embedding
(str
) –Embedding type
-
num_heads
(int
) –Number of heads
-
kernel_size
(int
) –Kernel size
-
dropout
(float
) –Dropout rate
-
use_bias
(bool
) –Use bias
ConformerParams
Conformer parameters
Attributes:
-
subsamples
(list[SubsampleBlockParams]
) –Subsample blocks
-
blocks
(list[ConformerBlockParams]
) –Conformer blocks
-
output_activation
(str | None
) –Output activation
-
include_top
(bool
) –Include top
-
name
(str
) –Model name
ConformerModel
Helper class to generate model from parameters
Functions
layer_from_params
staticmethod
layer_from_params(inputs: keras.Input, params: ConformerParams | dict, num_classes: int | None = None)
Create layer from parameters
Source code in neuralspot_edge/models/conformer.py
model_from_params
staticmethod
model_from_params(inputs: keras.Input, params: ConformerParams | dict, num_classes: int | None = None)
Create model from parameters
Source code in neuralspot_edge/models/conformer.py
Functions
subsampler
subsampler(blocks: SubsampleBlockParams, kernel_initializer: str = 'glorot_uniform', bias_initializer: str = 'zeros', kernel_regularizer=None, bias_regularizer=None, name: str | None = None) -> keras.Layer
Subsampler block
Parameters:
-
blocks
(SubsampleBlockParams
) –Subsample block parameters
-
kernel_initializer
(str
, default:'glorot_uniform'
) –Kernel initializer. Defaults to "glorot_uniform".
-
bias_initializer
(str
, default:'zeros'
) –Bias initializer. Defaults to "zeros".
-
kernel_regularizer
([type]
, default:None
) –Kernel regularizer. Defaults to None.
-
bias_regularizer
([type]
, default:None
) –Bias regularizer. Defaults to None.
-
name
(str
, default:None
) –Name. Defaults to None.
Returns:
-
Layer
–keras.Layer: Subsampler layer
Source code in neuralspot_edge/models/conformer.py
fc_block
fc_block(depth: int, ex_factor: int = 4, residual_factor: float = 0.5, dropout: float = 0, use_bias: bool = True, kernel_initializer: str = 'glorot_uniform', bias_initializer: str = 'zeros', kernel_regularizer=None, bias_regularizer=None, name: str = 'fc_block') -> keras.Layer
Fully connected block
Parameters:
-
depth
(int
) –Depth
-
ex_factor
(int
, default:4
) –Expansion factor. Defaults to 4.
-
residual_factor
(float
, default:0.5
) –Residual factor. Defaults to 0.5.
-
dropout
(float
, default:0
) –Dropout rate. Defaults to 0.
-
use_bias
(bool
, default:True
) –Use bias. Defaults to True.
-
kernel_initializer
(str
, default:'glorot_uniform'
) –Kernel initializer. Defaults to "glorot_uniform".
-
bias_initializer
(str
, default:'zeros'
) –Bias initializer. Defaults to "zeros".
-
kernel_regularizer
([type]
, default:None
) –Kernel regularizer. Defaults to None.
-
bias_regularizer
([type]
, default:None
) –Bias regularizer. Defaults to None.
-
name
(str
, default:'fc_block'
) –Name. Defaults to "fc_block".
Returns:
-
Layer
–keras.Layer: Functional layer
Source code in neuralspot_edge/models/conformer.py
conv_block
conv_block(depth: int, kernel_size: int = 9, dropout: float = 0.0, padding: str = 'same', scale_factor: int = 2, kernel_initializer: str = 'glorot_uniform', bias_initializer: str = 'zeros', kernel_regularizer=None, bias_regularizer=None, name: str = 'conv_module') -> keras.Layer
Convolutional block
Parameters:
-
depth
(int
) –Depth
-
kernel_size
(int
, default:9
) –Kernel size. Defaults to 9.
-
dropout
(float
, default:0.0
) –Dropout rate. Defaults to 0.0.
-
padding
(str
, default:'same'
) –Padding. Defaults to "same".
-
scale_factor
(int
, default:2
) –Scale factor. Defaults to 2.
-
kernel_initializer
(str
, default:'glorot_uniform'
) –Kernel initializer. Defaults to "glorot_uniform".
-
bias_initializer
(str
, default:'zeros'
) –Bias initializer. Defaults to "zeros".
-
kernel_regularizer
([type]
, default:None
) –Kernel regularizer. Defaults to None.
-
bias_regularizer
([type]
, default:None
) –Bias regularizer. Defaults to None.
-
name
(str
, default:'conv_module'
) –Name. Defaults to "conv_module".
Returns:
-
Layer
–keras.Layer: Functional layer
Source code in neuralspot_edge/models/conformer.py
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
|
att_block
att_block(depth: int, embedding: str = 'rel', num_heads: int = 4, dropout: float = 0.1, name: str = 'att_block') -> keras.Layer
Attention block
Parameters:
-
depth
(int
) –Depth
-
embedding
(str
, default:'rel'
) –Embedding type. Defaults to "rel".
-
num_heads
(int
, default:4
) –Number of heads. Defaults to 4.
-
dropout
(float
, default:0.1
) –Dropout rate. Defaults to 0.1.
-
name
(str
, default:'att_block'
) –Name. Defaults to "att_block".
Returns:
-
Layer
–keras.Layer: Functional layer
Source code in neuralspot_edge/models/conformer.py
conformer_block
conformer_block(depth: int, fc_ex_factor: int = 4, fc_res_factor: int = 0.5, embedding: str = 'relative', num_heads: int = 4, kernel_size: int = 9, dropout: float = 0.1, use_bias: bool = True, name: str = 'cf_block') -> keras.Layer
Conformer block
Parameters:
-
depth
(int
) –Depth
-
fc_ex_factor
(int
, default:4
) –FC expansion factor. Defaults to 4.
-
fc_res_factor
(int
, default:0.5
) –FC residual factor. Defaults to 0.5.
-
embedding
(str
, default:'relative'
) –Embedding type. Defaults to "relative".
-
num_heads
(int
, default:4
) –Number of heads. Defaults to 4.
-
kernel_size
(int
, default:9
) –Kernel size. Defaults to 9.
-
dropout
(float
, default:0.1
) –Dropout rate. Defaults to 0.1.
-
use_bias
(bool
, default:True
) –Use bias. Defaults to True.
-
name
(str
, default:'cf_block'
) –Name. Defaults to "cf_block".
Returns:
-
Layer
–keras.Layer: Functional layer
Source code in neuralspot_edge/models/conformer.py
conformer_layer
conformer_layer(x: keras.KerasTensor, params: ConformerParams, num_classes: int | None = None) -> keras.KerasTensor
Conformer functional layer
Parameters:
-
x
(KerasTensor
) –Input tensor
-
params
(ConformerParams
) –Model parameters.
-
num_classes
(int
, default:None
) –Number of classes.
Returns:
-
KerasTensor
–keras.KerasTensor: Output tensor