CNNArch
- class ketos.neural_networks.cnn.CNNArch(*args, **kwargs)[source]
Implement a Convolutional Neural Network
- Note: in addition to the dense layers specified in the ‘dense_layers’ argument, an extra dense
layer will always be added to the end. The output of this layer is determined by the ‘n_classes’ parameter.
- Args:
- convolutional_layers: list
A list of dictionaries containing the detailed specification for the convolutional layers. Each layer is specified as a dictionary with the following format:
>>> {'n_filters':96, "filter_shape":(11,11), 'strides':4, 'padding':'valid', activation':'relu', 'max_pool': {'pool_size':(3,3) , 'strides':(2,2)}, 'batch_normalization':True}
- dense_layers: list
A list of dictionaries containing the detailed specification for the fully connected layers. Each layer is specified as a dictionary with the following format:
>>> {'n_hidden':4096, 'activation':'relu', 'batch_normalization':True, 'dropout':0.5}
This list should not include the output layr, which will be automatically added based on the ‘n_classes’ parameter.
- pre_trained_base: instance of CNNArch
A pre-trained CNN 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
- n_classes:int
The number of classes the network will be used to classify. The output will be this number of values representing the scores for each class. Scores sum to 1.0.
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 the convolutional block
Freeze the classification (dense) block
Retrive the feature extraction base (initial convolutional layer + residual blocks)
Unfreeze the convolutional block
Unfreeze the classification (dense) block
Attributes
activity_regularizerOptional regularizer function for the output of this layer.
compute_dtypeThe dtype of the layer's computations.
distribute_strategyThe tf.distribute.Strategy this model was created under.
dtypeThe dtype of the layer weights.
dtype_policyThe dtype policy associated with this layer.
dynamicWhether the layer is dynamic (eager-only); set in the constructor.
inbound_nodesDeprecated, do NOT use! Only for compatibility with external Keras.
inputRetrieves the input tensor(s) of a layer.
input_maskRetrieves the input mask tensor(s) of a layer.
input_shapeRetrieves the input shape(s) of a layer.
input_specInputSpec instance(s) describing the input format for this layer.
layerslossesList of losses added using the add_loss() API.
metricsReturns the model's metrics added using compile(), add_metric() APIs.
metrics_namesReturns the model's display labels for all outputs.
nameName of the layer (string), set in the constructor.
name_scopeReturns a tf.name_scope instance for this class.
non_trainable_variablesSequence of non-trainable variables owned by this module and its submodules.
non_trainable_weightsList of all non-trainable weights tracked by this layer.
outbound_nodesDeprecated, do NOT use! Only for compatibility with external Keras.
outputRetrieves the output tensor(s) of a layer.
output_maskRetrieves the output mask tensor(s) of a layer.
output_shapeRetrieves the output shape(s) of a layer.
run_eagerlySettable attribute indicating whether the model should run eagerly.
state_updatesDeprecated, do NOT use!
statefulsubmodulesSequence of all sub-modules.
supports_maskingWhether this layer supports computing a mask using compute_mask.
trainabletrainable_variablesSequence of trainable variables owned by this module and its submodules.
trainable_weightsList of all trainable weights tracked by this layer.
updatesvariable_dtypeAlias of Layer.dtype, the dtype of the weights.
variablesReturns the list of all layer variables/weights.
weightsReturns 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 CNNArch
The new model with the old feature extraction base and new classification top.