src.model.deeplearn.handle.dl_model_handler
Classes
|
Abstract class to handle deep learning models. |
- class src.model.deeplearn.handle.dl_model_handler.DLModelHandler(arch, **kwargs)
Abstract class to handle deep learning models. Typically, fitting, predicting, and compiling are the main operations supported by deep learning model handlers.
- Variables:
arch (
Architecture) – The model’s architecture.class_names (list) – The name for each class involved in the classification problem, if any (it can be ignored by regression models).
compiler – See
DLModelCompiler.compiled – It is None by default, but it will be assigned the compiled model after calling the fit or predict methods.
- Ivar:
compilation_args: The key-word specification on how to compile the model.
- __init__(arch, **kwargs)
Initialize/instantiate a deep learning model handler.
- Parameters:
arch (
Architecture) – The architecture to be handled.kwargs – The key-word specification to instantiate the DLModelHandler.
- fit(X, y)
Fit the handled model to given data.
- Parameters:
X (
np.ndarray) – The structure space matrix, typically the matrix with the x, y, z coordinates as columns.y (
np.ndarray) – The vector of expected labels, the ground-truth from the supervised training perspective.
- Returns:
The fit model handler.
- Return type:
- predict(X, y=None, zout=None, plots_and_reports=True)
Compute predictions for the given input data.
- Parameters:
X – The input data for the deep learning model, typically the structure space (e.g., the x, y, z, coordinates for a 3D point cloud) and potentially the feature space (e.g., the matrix whose rows give the point-wise features).
y (
np.ndarray) – The vector of expected labels, the ground-truth from the supervised training perspective. While it is not necessary to compute predictions, when available it can be given because some models can use it for evaluation and analysis purposes.zout – It can be given as an empty list in which case its last element after the call will contain the output from the last layer of the neural network, e.g., the softmax scores for a point-wise classification neural network. It can be None, in which case the output from the last layer will not be considered. Note also that zout does not necessarily return the softmax output, it can be defined to consider different output layers or metrics for some potential model.
plots_and_reports (bool) – Control whether to compute and export the plots and reports associated to the computation of predictions (True) or not (False).
- Returns:
The predictions.
- Return type:
np.ndarray
- abstractmethod compile(X=None, y=None, y_rf=None, **kwargs)
The method that provides the logic to compile a model.
- Parameters:
X – Optionally, the coordinates might be used for a better initialization (e.g., automatically derive the number of expected input points, or the dimensionality of the space where the points belong to).
y – Optionally, the labels might be used for a better initialization (e.g., automatically derive the number of classes).
y_rf – The expected values for each receptive field. Can be used to derive class weights.
- Returns:
The model handler itself after compiling the architecture, which implies modifying its internal state.
- Return type:
- is_compiled()
Check whether the handled model has been compiled (True) or not (False).
- Returns:
True if the handled model has been compiled, False otherwise.
- Return type:
bool
- overwrite_pretrained_model(spec)
Assist the
model.Model.overwrite_pretrained_model()method for deep learning models.See
DLPretrainedHandler.- Parameters:
spec (dict) – The key-word specification containing the model’s arguments.
- build_callbacks()
Build the callbacks for the model.
By default, the abstract baseline DLModelHandler does not provide an implementation to build callbacks. Derived classes that need to work with model callbacks must override this method to implement the building of any necessary callback.
- Returns:
List of built callbacks
- Return type:
list