src.model.deeplearn.arch.architecture

Classes

Architecture(**kwargs)

class src.model.deeplearn.arch.architecture.Architecture(**kwargs)
Author:

Alberto M. Esmoris Pena

The architecture class represents any deep learning architecture for classification and regression tasks in point clouds.

Any deep learning architecture can be divided intro three parts:

1) The preprocessing. What needs to be computed on the input before feeding it to the neural network. See architecture.Architecture.run_pre().

2) The neural network. The neural network itself. See architecture.Architecture.build().

3) The postprocessing. What needs to be computed on the neural network’s output to obtain the final output. See architecture.Architecture.run_post().

The responsibility of an architecture is to define all the previous parts. However, compiling, training, and predicting are operations that lie outside the scope of the architecture. Instead, they must be handled by any model that uses the architecture.

Variables:
  • pre_runnable (callable) – The callable to run the preprocessing logic.

  • post_runnable (callable) – The callable to run the postprocessing logic.

  • nn – The built neural network.

  • nn_path (str) – The path to the file that represents the built neural network. The neural network will only be serialized when a not None path is provided.

  • build_args (dict) – The key-word arguments used to build the neural network.

  • architecture_graph_path (str) – The path where the graph representing the architecture will be stored. If None, no architecture graph is plotted.

  • architecture_graph_args (dict) – The key-word arguments governing the format of the graph representing the architecture.

__init__(**kwargs)

Initialize the member attributes of the architecture.

Parameters:

kwargs – The key-word specification defining the architecture.

run_pre(inputs, **kwargs)

Run the preprocessing logic.

Parameters:
  • inputs – The arbitrary inputs for the architecture.

  • kwargs – The key-word arguments to govern the preprocessing.

Returns:

The transformed input ready for the neural network.

run_post(outputs, **kwargs)

Run the postprocessing logic.

Parameters:
  • outputs – The outputs from the architecture’s neural network.

  • kwargs – The key-word arguments to govern the postprocessing.

Returns:

The transformed output.

build(**kwargs)

Build the neural network model.

This method can be overriden by derived classes to update the building logic. However, the baseline architecture provides a basic building logic to any child model:

  1. Build the input layer, \(x_{\mathrm{in}}\)

  2. Build the hidden layer, \(x = f(x_{\mathrm{in}})\)

  3. Build the output layer, \(y = g(x)\)

Parameters:

kwargs – The key-word arguments to govern the building of the neural network.

Returns:

Nothing, but the nn attribute is updated.

is_built()

Check whether the architecture has been built (True) or not (False).

Returns:

True if the architecture has been built, False otherwise.

Return type:

bool

abstractmethod build_input(**kwargs)

Any derived class that aims to provide an operating architecture must override this method to define the inputs of the neural network.

Parameters:

kwargs – The key-word arguments governing the neural network’s inputs.

Returns:

The input layer or a list/tuple/dict of input layers.

Return type:

tf.Tensor or list or tuple or dict

abstractmethod build_hidden(inputs, **kwargs)

Any derived class that aims to provide an operating architecture must override this method to define the hidden layers of the architecture.

Parameters:
  • inputs – The neural network’s inputs.

  • kwargs – The key-word arguments governing the neural network’s hidden layers.

Returns:

The last hidden layer or a list/tuple/dict of hidden layers.

Return type:

tf.Tensor or list or tuple or dict

abstractmethod build_output(inputs, **kwargs)

Any derived class that aims to provide an operating architecture must override this method to define the outputs of the neural network.

Parameters:
  • inputs – The inputs to compute the outputs (i.e., the inputs for the output layer/s, not the inputs for the neural network).

  • kwargs – The key-word arguments governing the neural network’s output layers.

Returns:

The output layer or a list/tuple/dict of output layers.

Return type:

tf.Tensor or list or tuple or dict

plot()

Plot the model’s architecture as a graph if requested, i.e., a path for the architecture’s graph is available as member attribute.

Returns:

Nothing, but the plot is written to a file.

overwrite_pretrained_model(spec)

Assist the model.Model.overwrite_pretrained_model() method through assisting the dl_model_handler.DLModelHandler.overwrite_pretrained_model() method.

Parameters:

spec (dict) – The key-word specification containing the model’s arguments.

get_num_output_heads()

By default, neural network architectures are expected to have exactly one output head. Any architecture that changes this must also override this method to return the correct number of output heads.

Returns:

The number of output heads.

Return type:

int

pre_processor_to_temporary_file()

Export the current state of the pre-processor to a temporary file in the disk. It can be later restored by calling Architecture.pre_processor_from_temporary_file(). This can be useful to save memory but also to back up and restore the state of the pre-processor with some operations that transform it in the middle. For example, DLOfflineSequencer uses the pre-processor many times with different point clouds. At the end, it is necessary to restore the original state of the pre-processor or the execution will fail.

Note that this method does not explicitly release memory resources but simply writes the pre-processor (self.pre_runnable) to a temporary file.

Returns:

Nothing, but all the attributes of the pre-processor that define its state are exported to a temporary file.

pre_processor_from_temporary_file()

Load the state of the pre-processor from a temporary file in the disk. This method is the counterpart of Architecture.pre_processor_to_temporary_file().

Returns:

Nothing, but the state of the pre-processor is restored from the values in the disk.