Scikit-learn interface for fully-connected quantized neural networks.
- QNN_AUTO_KWARGS
A Fully-Connected Neural Network regressor with FHE.
This class wraps a quantized neural network implemented using Torch tools as a scikit-learn estimator. The skorch package allows to handle training and scikit-learn compatibility, and adds quantization as well as compilation functionalities. The neural network implemented by this class is a multi layer fully connected network trained with Quantization Aware Training (QAT).
Inputs and targets that are float64 will be casted to float32 before training as Torch does not handle float64 types properly. Thus should not have a significant impact on the model's performances. An error is raised if these values are not floating points.
__init__(
criterion=<class 'torch.nn.modules.loss.MSELoss'>,
optimizer=<class 'torch.optim.adam.Adam'>,
lr=0.01,
max_epochs=10,
batch_size=128,
iterator_train=<class 'torch.utils.data.dataloader.DataLoader'>,
iterator_valid=<class 'torch.utils.data.dataloader.DataLoader'>,
dataset=<class 'skorch.dataset.Dataset'>,
train_split=None,
callbacks=None,
predict_nonlinearity='auto',
warm_start=False,
verbose=1,
device='cpu',
**kwargs
)
Get the Torch module.
Returns:
SparseQuantNeuralNetwork
: The fitted underlying module.
Get the input quantizers.
Returns:
List[UniformQuantizer]
: The input quantizers.
Indicate if the model is compiled.
Returns:
bool
: If the model is compiled.
Indicate if the model is fitted.
Returns:
bool
: If the model is fitted.
Get the ONNX model.
Is None if the model is not fitted.
Returns:
onnx.ModelProto
: The ONNX model.
Get the output quantizers.
Returns:
List[UniformQuantizer]
: The output quantizers.
fit(
X: Union[ndarray, Tensor, ForwardRef('DataFrame'), List],
y: Union[ndarray, Tensor, ForwardRef('DataFrame'), ForwardRef('Series'), List],
*args,
**kwargs
)
fit_benchmark(
X: Union[ndarray, Tensor, ForwardRef('DataFrame'), List],
y: Union[ndarray, Tensor, ForwardRef('DataFrame'), ForwardRef('Series'), List],
*args,
**kwargs
)
predict(
X: Union[ndarray, Tensor, ForwardRef('DataFrame'), List],
fhe: Union[FheMode, str] = <FheMode.DISABLE: 'disable'>
) → ndarray
predict_proba(
X: Union[ndarray, Tensor, ForwardRef('DataFrame'), List],
fhe: Union[FheMode, str] = <FheMode.DISABLE: 'disable'>
) → ndarray
A Fully-Connected Neural Network classifier with FHE.
This class wraps a quantized neural network implemented using Torch tools as a scikit-learn estimator. The skorch package allows to handle training and scikit-learn compatibility, and adds quantization as well as compilation functionalities. The neural network implemented by this class is a multi layer fully connected network trained with Quantization Aware Training (QAT).
Inputs that are float64 will be casted to float32 before training as Torch does not handle float64 types properly. Thus should not have a significant impact on the model's performances. If the targets are integers of lower bit-width, they will be safely casted to int64. Else, an error is raised.
__init__(
criterion=<class 'torch.nn.modules.loss.CrossEntropyLoss'>,
optimizer=<class 'torch.optim.adam.Adam'>,
classes=None,
lr=0.01,
max_epochs=10,
batch_size=128,
iterator_train=<class 'torch.utils.data.dataloader.DataLoader'>,
iterator_valid=<class 'torch.utils.data.dataloader.DataLoader'>,
dataset=<class 'skorch.dataset.Dataset'>,
train_split=None,
callbacks=None,
predict_nonlinearity='auto',
warm_start=False,
verbose=1,
device='cpu',
**kwargs
)
Get the Torch module.
Returns:
SparseQuantNeuralNetwork
: The fitted underlying module.
Get the input quantizers.
Returns:
List[UniformQuantizer]
: The input quantizers.
Indicate if the model is compiled.
Returns:
bool
: If the model is compiled.
Indicate if the model is fitted.
Returns:
bool
: If the model is fitted.
Get the ONNX model.
Is None if the model is not fitted.
Returns:
onnx.ModelProto
: The ONNX model.
Get the output quantizers.
Returns:
List[UniformQuantizer]
: The output quantizers.
fit(
X: Union[ndarray, Tensor, ForwardRef('DataFrame'), List],
y: Union[ndarray, Tensor, ForwardRef('DataFrame'), ForwardRef('Series'), List],
*args,
**kwargs
)
fit_benchmark(
X: Union[ndarray, Tensor, ForwardRef('DataFrame'), List],
y: Union[ndarray, Tensor, ForwardRef('DataFrame'), ForwardRef('Series'), List],
*args,
**kwargs
)
predict(
X: Union[ndarray, Tensor, ForwardRef('DataFrame'), List],
fhe: Union[FheMode, str] = <FheMode.DISABLE: 'disable'>
) → ndarray
predict_proba(
X: Union[ndarray, Tensor, ForwardRef('DataFrame'), List],
fhe: Union[FheMode, str] = <FheMode.DISABLE: 'disable'>
) → ndarray