ResNet1DArch
- class ketos.neural_networks.resnet.ResNet1DArch(*args, **kwargs)[source]
Implements a 1D (temporal) ResNet architecture, building on top of ResNetBlocks.
- Args:
- block_sets: list of ints
A list specifying the block sets and how many blocks each set contains. Example: [2,2,2] will create a ResNet with 3 block sets, each containing 2 ResNetBlocks (i.e.: a total of 6 residual blocks)
- n_classes:int
The number of classes. The output layer uses a Softmax activation and will contain this number of nodes, resulting in model outputs with this many values summing to 1.0.
- initial_filters:int
The number of filters used in the first ResNetBlock. Subsequent blocks will have two times more filters than their previous block.
- initial_strides: int
Strides used in the first convolutional layer
- initial_kernel: int
Kernel size used in the first convolutional layer
- strides: int
Strides used in convolutional layers within the blocks
- kernel: int
Kernel size used in convolutional layers within the blocks
- pre_trained_base: instance of ResNet1DArch
A pre-trained resnet model from which the residual blocks will be taken. Use by the the clone_with_new_top method when creating a clone for transfer learning
- batch_norm_momentum: float between 0 and 1
Momentum for the moving average of all the batch normalization layers in the network. The default value is 0.99. For an explanation of how the momentum affects the batch normalisation operation, see <https://www.tensorflow.org/api_docs/python/tf/keras/layers/BatchNormalization>
- dropout_rate: float between 0 and 1
Fraction of the input units to drop in all the dropout layers in the network. Set this parameter to 0 to disable dropout (default).
- Returns:
A ResNet1DArch object, which is a tensorflow model.
Methods
call
(inputs[, training])Calls the model on new inputs.
clone_with_new_top
([n_classes, freeze_base])Clone this instance but replace the original classification top with a new (untrained) one
freeze_block
(block_ids)Freeze specific residual blocks
Freeze the initial convolutional layer
Freeze the classification block
Retrive the feature extraction base (initial convolutional layer + residual blocks)
set_batch_norm_momentum
(momentum)Set the momentum for the moving average of all the batch normalization layers in the network.
set_dropout_rate
(rate)Set the fraction of the input units to drop in all the dropout layers in the network.
unfreeze_block
(block_ids)Unfreeze specific residual blocks
Unffreeze the initial convolutional layer
Unfreeze the classification block
Attributes
activity_regularizer
Optional regularizer function for the output of this layer.
compute_dtype
The dtype of the layer's computations.
distribute_strategy
The tf.distribute.Strategy this model was created under.
dtype
The dtype of the layer weights.
dtype_policy
The dtype policy associated with this layer.
dynamic
Whether the layer is dynamic (eager-only); set in the constructor.
inbound_nodes
Deprecated, do NOT use! Only for compatibility with external Keras.
input
Retrieves the input tensor(s) of a layer.
input_mask
Retrieves the input mask tensor(s) of a layer.
input_shape
Retrieves the input shape(s) of a layer.
input_spec
InputSpec instance(s) describing the input format for this layer.
layers
losses
List of losses added using the add_loss() API.
metrics
Returns the model's metrics added using compile(), add_metric() APIs.
metrics_names
Returns the model's display labels for all outputs.
name
Name of the layer (string), set in the constructor.
name_scope
Returns a tf.name_scope instance for this class.
non_trainable_variables
Sequence of non-trainable variables owned by this module and its submodules.
non_trainable_weights
List of all non-trainable weights tracked by this layer.
outbound_nodes
Deprecated, do NOT use! Only for compatibility with external Keras.
output
Retrieves the output tensor(s) of a layer.
output_mask
Retrieves the output mask tensor(s) of a layer.
output_shape
Retrieves the output shape(s) of a layer.
run_eagerly
Settable attribute indicating whether the model should run eagerly.
state_updates
Deprecated, do NOT use!
stateful
submodules
Sequence of all sub-modules.
supports_masking
Whether this layer supports computing a mask using compute_mask.
trainable
trainable_variables
Sequence of trainable variables owned by this module and its submodules.
trainable_weights
List of all trainable weights tracked by this layer.
updates
variable_dtype
Alias of Layer.dtype, the dtype of the weights.
variables
Returns the list of all layer variables/weights.
weights
Returns the list of all layer variables/weights.
- call(inputs, training=None)[source]
Calls the model on new inputs.
In this case call just reapplies all ops in the graph to the new inputs (e.g. build a new computational graph from the provided inputs).
- Args:
- inputs: Tensor or list of tensors
A tensor or list of tensors
- training: Bool
Boolean or boolean scalar tensor, indicating whether to run the Network in training mode or inference mode.
- Returns:
A tensor if there is a single output, or a list of tensors if there are more than one outputs.
- clone_with_new_top(n_classes=None, freeze_base=True)[source]
Clone this instance but replace the original classification top with a new (untrained) one
- Args:
- n_classes:int
The number of classes the new classification top should output. If None(default), the original number of classes will be used.
- freeze_base:bool
If True, the weights of the feature extraction base will be froze (untrainable) in the new model.
- Returns:
- cloned_model: instance of ResNetArch
The new model with the old feature extraction base and new classification top.
- freeze_block(block_ids)[source]
Freeze specific residual blocks
- Args:
- blocks_ids: list of ints
The block numbers to be freezed (starting from zero)
- get_feature_extraction_base()[source]
Retrive the feature extraction base (initial convolutional layer + residual blocks)
- Returns:
list containing the feature extraction layers
- set_batch_norm_momentum(momentum)[source]
Set the momentum for the moving average of all the batch normalization layers in the network.
For an explanation of how the momentum affects the batch normalisation operation, see <https://www.tensorflow.org/api_docs/python/tf/keras/layers/BatchNormalization>
- Args:
- momentum: float between 0 and 1
Momentum for the moving average of the batch normalization layers.
- Returns:
None
- set_dropout_rate(rate)[source]
Set the fraction of the input units to drop in all the dropout layers in the network.
- Args:
- rate: float between 0 and 1
Fraction of the input units to drop in the dropout layers.
- Returns:
None