Package smile.deep
Class Model
java.lang.Object
smile.deep.Model
- Direct Known Subclasses:
VisionModel
The deep learning models.
-
Constructor Summary
ConstructorDescriptionModel
(LayerBlock net) Constructor.Model
(LayerBlock net, Function<Tensor, Tensor> transform) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionorg.bytedeco.pytorch.Module
asTorch()
Returns the PyTorch Module object.device()
Returns the device on which the model is stored.dtype()
Returns the data type.eval()
Sets the model in the evaluation/inference mode.Evaluates the model accuracy on a test dataset.Forward propagation (or forward pass) through the model.Loads a checkpoint.Serialize the model as a checkpoint.void
setLearningRateSchedule
(TimeFunction learningRateSchedule) Sets the learning rate schedule.Moves the model to a device.to
(Device device, ScalarType dtype) Moves the model to a device.toString()
train()
Sets the model in the training mode.void
Trains the model.void
train
(int epochs, Optimizer optimizer, Loss loss, Dataset train, Dataset test, String checkpoint, Metric... metrics) Trains the model.
-
Constructor Details
-
Model
Constructor.- Parameters:
net
- the neural network.
-
Model
Constructor.- Parameters:
net
- the neural network.transform
- the optional data preprocessing function.
-
-
Method Details
-
toString
-
asTorch
public org.bytedeco.pytorch.Module asTorch()Returns the PyTorch Module object.- Returns:
- the PyTorch Module object.
-
train
Sets the model in the training mode.- Returns:
- this model.
-
eval
Sets the model in the evaluation/inference mode.- Returns:
- this model.
-
device
Returns the device on which the model is stored.- Returns:
- the compute device.
-
dtype
Returns the data type.- Returns:
- the data type.
-
to
Moves the model to a device.- Parameters:
device
- the compute device.- Returns:
- this model.
-
to
Moves the model to a device.- Parameters:
device
- the compute device.dtype
- the data type.- Returns:
- this model.
-
load
Loads a checkpoint.- Parameters:
path
- the checkpoint file path.- Returns:
- this model.
-
save
Serialize the model as a checkpoint.- Parameters:
path
- the checkpoint file path.- Returns:
- this model.
-
apply
-
forward
Forward propagation (or forward pass) through the model.- Parameters:
input
- the input tensor.- Returns:
- the output tensor.
-
setLearningRateSchedule
Sets the learning rate schedule.- Parameters:
learningRateSchedule
- the learning rate schedule.
-
train
Trains the model.- Parameters:
epochs
- the number of training epochs.optimizer
- the optimization algorithm.loss
- the loss function.train
- the training data.
-
train
public void train(int epochs, Optimizer optimizer, Loss loss, Dataset train, Dataset test, String checkpoint, Metric... metrics) Trains the model.- Parameters:
epochs
- the number of training epochs.optimizer
- the optimization algorithm.loss
- the loss function.train
- the training data.test
- optional validation data.checkpoint
- optional checkpoint file path.metrics
- the evaluation metrics.
-
eval
Evaluates the model accuracy on a test dataset.- Parameters:
dataset
- the test dataset.metrics
- the evaluation metrics.- Returns:
- the accuracy.
-