Inception

inception sub-module within the ketos.neural_networks module

This module provides classes that implement Inception Neural Networks.

Contents:

ConvBatchNormRelu class InceptionBlock class Inception class InceptionInterface

class ketos.neural_networks.inception.ConvBatchNormRelu(n_filters, filter_shape=3, strides=1, padding='same')[source]

Bases: tensorflow.python.keras.engine.training.Model

Convolutional layer with batch normalization and relu activation.

Used in Inception Blocks

Args:
n_filters: int

Number of filters in the convolutional layer

filter_shape: int

The filter (i.e.: kernel) shape.

strides: int

Strides to be used for the convolution operation

padding:str

Type of padding: ‘same’ or ‘valid’

call(x, 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).

Arguments:

inputs: A tensor or list of tensors. training: Boolean or boolean scalar tensor, indicating whether to run

the Network in training mode or inference mode.

mask: A mask or list of masks. A mask can be

either a tensor or None (no mask).

Returns:

A tensor if there is a single output, or a list of tensors if there are more than one outputs.

class ketos.neural_networks.inception.InceptionArch(n_blocks, n_classes, pre_trained_base=None, initial_filters=16, **kwargs)[source]

Bases: tensorflow.python.keras.engine.training.Model

Implements an Inception network, building on InceptionBlocks

Args:
n_blocks:int

Number of Inception Blocks

n_classes:int

Number of possible classes

initial_filters:int

Number of filters (i.e.: channels) in the first block

pre_trained_base: instance of InceptionArch

A pre-trained inception 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

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).

Arguments:

inputs: A tensor or list of tensors. training: Boolean or boolean scalar tensor, indicating whether to run

the Network in training mode or inference mode.

mask: A mask or list of masks. A mask can be

either a tensor or None (no mask).

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 InceptionArch

The new model with the old feature extraction base and new classification top.

freeze_block(block_ids)[source]

Freeze specific inception blocks

Args:
blocks_ids: list of ints

The block numbers to be freezed (starting from zero)

freeze_init_layer()[source]

Freeze the initial convolutional layer

freeze_top()[source]

Freeze the classification block

get_feature_extraction_base()[source]

Retrive the feature extraction base (initial convolutional layer + residual blocks)

Returns:

list containing the feature extraction layers

unfreeze_block(block_ids)[source]

Unfreeze specific inception blocks

Args:
blocks_ids: list of ints

The block numbers to be freezed (starting from zero)

unfreeze_init_layer()[source]

Unfreeze the initial convolutional layer

unfreeze_top()[source]

Unfreeze the classification block

class ketos.neural_networks.inception.InceptionBlock(n_filters, strides=1)[source]

Bases: tensorflow.python.keras.engine.training.Model

Inception Block for the Inception Architecture

Args:
n_filters:int

The number of filters (i.e.: channels) to be used in each convolutional layer of the block

strides: int

Strides used in the first 3 and and 5th convolutional layers of the block

call(x, 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).

Arguments:

inputs: A tensor or list of tensors. training: Boolean or boolean scalar tensor, indicating whether to run

the Network in training mode or inference mode.

mask: A mask or list of masks. A mask can be

either a tensor or None (no mask).

Returns:

A tensor if there is a single output, or a list of tensors if there are more than one outputs.

class ketos.neural_networks.inception.InceptionInterface(n_blocks=3, n_classes=2, initial_filters=16, optimizer=Adam ketos recipe, loss_function=BinaryCrossentropy ketos recipe, metrics=[BinaryAccuracy ketos recipe, Precision ketos recipe, Recall ketos recipe])[source]

Bases: ketos.neural_networks.dev_utils.nn_interface.NNInterface

Creates an Inception model with the standardized Ketos interface.

Args:
num_blocks: int

The number of inception blocks to be used.

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.

optimizer: ketos.neural_networks.RecipeCompat object

A recipe compatible optimizer (i.e.: wrapped by the ketos.neural_networksRecipeCompat class)

loss_function: ketos.neural_networks.RecipeCompat object

A recipe compatible loss_function (i.e.: wrapped by the ketos.neural_networksRecipeCompat class)

metrics: list of ketos.neural_networks.RecipeCompat objects

A list of recipe compatible metrics (i.e.: wrapped by the ketos.neural_networksRecipeCompat class). These metrics will be computed on each batch during training.