tensor_model#
Source code: sensai/tensor_model.py
This module contains base classes for models that input and output tensors, for examples CNNs. The fitting and predictions will still be performed on data frames, like in VectorModel, but now it will be expected that all entries of the input data frame passed to the model are tensors of the same shape. Lists of scalars of the same lengths are also accepted. The same is expected of the ground truth data frames. Everything will work as well if the entries are just scalars but in this case it is recommended to use VectorModel instead.
If we denote the shapes of entries in the dfs as inputTensorShape and outputTensorShape, the model will be fit on input tensors of shape (N_rows, N_inputColumns, inputTensorShape) and output tensors of shape (N_rows, N_outputColumns, outputTensorShape), where empty dimensions (e.g. for one-column data frames) will be stripped.
- class TensorToScalarRegressionModel(check_input_shape=True, check_input_columns=True)[source]#
Bases:
VectorRegressionModel
,TensorModel
,ABC
Base class for regression models that take tensors as input and output scalars. They can be evaluated in the same way as non-tensor regression models
- Parameters:
check_input_shape – Whether to check if during predict input tensors have the same shape as during fit. For certain applications, e.g. using CNNs on larger inputs than the training set, this has to be disabled
check_input_columns – Whether to check if input columns at predict time coincide with those at fit time
- class TensorToScalarClassificationModel(check_input_shape=True, check_input_columns=True)[source]#
Bases:
VectorClassificationModel
,TensorModel
,ABC
Base class for classification models that take tensors as input and output scalars. They can be evaluated in the same way as non-tensor classification models
- Parameters:
check_input_shape – Whether to check if during predict input tensors have the same shape as during fit. For certain applications, e.g. using CNNs on larger inputs than the training set, this has to be disabled
check_input_columns – Whether to check if input columns at predict time coincide with those at fit time
- class TensorToTensorRegressionModel(check_input_shape=True, check_output_shape=True, check_input_columns=True)[source]#
Bases:
VectorRegressionModel
,TensorModel
,ABC
Base class for regression models that output tensors. Multiple targets can be used by putting them into separate columns. In that case it is required that all target tensors have the same shape.
- Parameters:
check_input_shape – Whether to check if during predict tensors have the same shape as during fit. For certain applications, e.g. using CNNs on larger inputs than the training set, this has to be disabled
check_output_shape – Whether to check if predictions have the same shape as ground truth data during fit. For certain applications, e.g. using CNNs on larger inputs than the training set, this has to be disabled
check_input_columns – Whether to check if input columns at predict time coincide with those at fit time
- class TensorToTensorClassificationModel(check_input_shape=True, check_output_shape=True, check_input_columns=True)[source]#
Bases:
VectorModel
,TensorModel
,ABC
Base class for classification models that output tensors, e.g. for semantic segregation. The models can be fit on a ground truth data frame with a single column. The entries in this column should be binary tensors with one-hot-encoded labels, i.e. of shape (*predictionShape, numLabels)
- Parameters:
check_input_shape – Whether to check if during predict tensors have the same shape as during fit. For certain applications, e.g. using CNNs on larger inputs than the training set, this has to be disabled
check_output_shape – Whether to check if predictions have the same shape as ground truth data during fit. For certain applications, e.g. using CNNs on larger inputs than the training set, this has to be disabled
check_input_columns – Whether to check if input columns at predict time coincide with those at fit time
- fit(x: DataFrame, y: DataFrame, fit_preprocessors=True, fit_model=True)[source]#
- Parameters:
x – data frame containing input tensors on which to train
y – ground truth has to be an array containing only zeroes and ones (one-hot-encoded labels) of the shape (*prediction_shape, numLabels)
fit_preprocessors – whether the model’s preprocessors (feature generators and data frame transformers) shall be fitted
fit_model – whether the model itself shall be fitted
- convert_class_probabilities_to_predictions(df: DataFrame)[source]#
Converts from a result returned by predictClassProbabilities to a result as return by predict.
- Parameters:
df – the output data frame from predictClassProbabilities
- Returns:
an output data frame as it would be returned by predict