GraphTrainableModel

abstract class GraphTrainableModel(layers: Layer) : TrainableModel

GraphTrainableModel model groups a linear stack of layers into a graph-based TensorFlow Model. Also, it provides training and inference features on this model.

Constructors

GraphTrainableModel
Link copied to clipboard
fun GraphTrainableModel(vararg layers: Layer)

Creates a GraphTrainableModel model via sequence of layers.

Functions

close
Link copied to clipboard
open override fun close()

Closes internal resources: session and kGraph.

compile
Link copied to clipboard
open override fun compile(optimizer: Optimizer, loss: LossFunction, metric: Metric, callback: Callback)
open override fun compile(optimizer: Optimizer, loss: LossFunction, metric: Metrics, callback: Callback)
open override fun compile(optimizer: Optimizer, loss: Losses, metric: Metric, callback: Callback)
open override fun compile(optimizer: Optimizer, loss: Losses, metric: Metrics, callback: Callback)

Configures the model for training.

copy
Link copied to clipboard
open override fun copy(copiedModelName: String?, saveOptimizerState: Boolean, copyWeights: Boolean): TensorFlowInferenceModel

Creates a copy.

evaluate
Link copied to clipboard
open override fun evaluate(dataset: Dataset, batchSize: Int): EvaluationResult

Returns the metrics and loss values for the model in test (evaluation) mode.

fun evaluate(dataset: Dataset, metric: Metrics): Double

Evaluates dataset via metric.

fit
Link copied to clipboard
open override fun fit(dataset: Dataset, epochs: Int, batchSize: Int): TrainingHistory
open override fun fit(trainingDataset: Dataset, validationDataset: Dataset, epochs: Int, trainBatchSize: Int, validationBatchSize: Int): TrainingHistory

Trains the model for a fixed number of epochs (iterations over a dataset).

fun fit(dataset: OnHeapDataset, validationRate: Double, epochs: Int, trainBatchSize: Int, validationBatchSize: Int): TrainingHistory

Trains the model for a fixed number of epochs (iterations on a dataset).

getLayer
Link copied to clipboard
infix fun getLayer(layerName: String): Layer

Return layer by layerName.

graphToString
Link copied to clipboard
fun graphToString(): String

Forms the graph description in string format.

init
Link copied to clipboard
fun init()

Initializes kGraph variables.

input
Link copied to clipboard
fun input(inputOp: Input)

Chain-like setter to set up inputOp.

kGraph
Link copied to clipboard
fun kGraph(): KGraph

Returns KGraph.

loadWeights
Link copied to clipboard
open override fun loadWeights(modelDirectory: File, loadOptimizerState: Boolean)

Loads variable data from .txt files.

output
Link copied to clipboard
fun output(outputOp: Output)

Chain-like setter to set up outputOp.

predict
Link copied to clipboard
open override fun predict(inputData: FloatArray): Int

Generates output prediction for the input sample.

fun predict(dataset: Dataset): List<Int>

Predicts labels for all observation in dataset.

open override fun predict(inputData: FloatArray, predictionTensorName: String): Int

Generates output prediction for the input sample using output of the predictionTensorName tensor.

open override fun predict(dataset: Dataset, batchSize: Int): IntArray

Generates output predictions for the input samples.

predictAndGetActivations
Link copied to clipboard
open override fun predictAndGetActivations(inputData: FloatArray, predictionTensorName: String): Pair<Int, List<*>>

Predicts and returns not only prediction but list of activations values from intermediate model layers (for visualisation or debugging purposes).

predictSoftly
Link copied to clipboard
open override fun predictSoftly(inputData: FloatArray, predictionTensorName: String): FloatArray

Predicts vector of probabilities instead of specific class in predict method.

open override fun predictSoftly(dataset: Dataset, batchSize: Int): Array<FloatArray>

Generates output predictions for the input samples. Each prediction is a vector of probabilities instead of specific class in predict method.

reshape
Link copied to clipboard
open override fun reshape(vararg dims: Long)

Chain-like setter to set up input shape.

save
Link copied to clipboard
open override fun save(modelDirectory: File, savingFormat: SavingFormat, saveOptimizerState: Boolean, writingMode: WritingMode)

Saves the model as graph and weights.

summary
Link copied to clipboard
open override fun summary(): ModelSummary

Returns model summary.

toString
Link copied to clipboard
open override fun toString(): String

Properties

inputDimensions
Link copied to clipboard
open override val inputDimensions: LongArray

Returns input dimensions in order HWC (height, width, channels)

inputLayer
Link copied to clipboard
val inputLayer: Input

First layer that is responsible for the input shape of the Neural Network.

isBuiltForForwardMode
Link copied to clipboard
var isBuiltForForwardMode: Boolean = false

Is true when model is ready for forward mode.

isModelCompiled
Link copied to clipboard
var isModelCompiled: Boolean = false

Is true when model is compiled.

isModelInitialized
Link copied to clipboard
var isModelInitialized: Boolean = false

Is true when model is initialized.

isOptimizerVariableInitialized
Link copied to clipboard
var isOptimizerVariableInitialized: Boolean = false

Is true when model optimizer variables are initialized.

kGraph
Link copied to clipboard
lateinit var kGraph: KGraph

TensorFlow wrapped computational graph.

layers
Link copied to clipboard
var layers: List<Layer>

The layers to describe the model design. Main part of the internal state of the model.

logger
Link copied to clipboard
val logger: KLogger

Logger for the model.

loss
Link copied to clipboard
var loss: LossFunction

Loss function.

name
Link copied to clipboard
var name: String? = null

Model name.

numberOfClasses
Link copied to clipboard
var numberOfClasses: Long

Number of classes for classification tasks. -1 is a default value for regression tasks.

shape
Link copied to clipboard
lateinit var shape: LongArray

Data shape for prediction.

stopTraining
Link copied to clipboard
var stopTraining: Boolean = false

Special flag for callbacks.

Inheritors

Functional
Link copied to clipboard
Sequential
Link copied to clipboard

Extensions

loadWeights
Link copied to clipboard
fun GraphTrainableModel.loadWeights(hdfFile: HdfFile)

Loads weights from hdf5 file created in Keras TensorFlow framework.

fun GraphTrainableModel.loadWeights(hdfFile: HdfFile, layerList: MutableList<Layer>)

Loads weights from hdf5 file created in Keras TensorFlow framework for pre-defined list of layers.

loadWeightsByPaths
Link copied to clipboard
fun GraphTrainableModel.loadWeightsByPaths(hdfFile: HdfFile, weightPaths: List<LayerPaths>, missedWeights: MissedWeightsStrategy = MissedWeightsStrategy.INITIALIZE)

Loads weights from hdf5 file created in Keras TensorFlow framework.

fun GraphTrainableModel.loadWeightsByPaths(hdfFile: HdfFile, layerList: MutableList<Layer>, kernelDataPathTemplate: String = KERNEL_DATA_PATH_TEMPLATE, biasDataPathTemplate: String = BIAS_DATA_PATH_TEMPLATE)

Loads weights from hdf5 file created in Keras TensorFlow framework for pre-defined list of layers.

loadWeightsByPathTemplates
Link copied to clipboard
fun GraphTrainableModel.loadWeightsByPathTemplates(hdfFile: HdfFile, kernelDataPathTemplate: String = KERNEL_DATA_PATH_TEMPLATE, biasDataPathTemplate: String = BIAS_DATA_PATH_TEMPLATE)

Loads weights from hdf5 file created in Keras TensorFlow framework.

fun GraphTrainableModel.loadWeightsByPathTemplates(hdfFile: HdfFile, layerList: MutableList<Layer>, kernelDataPathTemplate: String = KERNEL_DATA_PATH_TEMPLATE, biasDataPathTemplate: String = BIAS_DATA_PATH_TEMPLATE)

Loads weights from hdf5 file created in Keras TensorFlow framework for pre-defined list of layers.

loadWeightsForFrozenLayers
Link copied to clipboard
fun GraphTrainableModel.loadWeightsForFrozenLayers(hdfFile: HdfFile)

Loads weights from hdf5 file created in Keras TensorFlow framework for non-trainable (or frozen) layers only.

saveModelConfiguration
Link copied to clipboard
fun GraphTrainableModel.saveModelConfiguration(jsonConfigFile: File, isKerasFullyCompatible: Boolean = false)

Saves model description as json configuration file fully compatible with the Keras TensorFlow framework.