Functional

class Functional(layers: Layer) : GraphTrainableModel

A Functional model is defined as a directed graph of layers.

Constructors

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

Creates a Functional model via sequence of layers.

Types

Companion
Link copied to clipboard
object Companion

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, metrics: List<Metric>)
open override fun compile(optimizer: Optimizer, loss: LossFunction, metric: Metric)
open override fun compile(optimizer: Optimizer, loss: LossFunction, metric: Metrics)
open override fun compile(optimizer: Optimizer, loss: Losses, metric: Metric)
open override fun compile(optimizer: Optimizer, loss: Losses, metric: Metrics)

Configures the model for training.

copy
Link copied to clipboard
fun copy(saveOptimizerState: Boolean = false, copyWeights: Boolean = true): Functional

Returns a copy of this model.

open override fun copy(copiedModelName: String?, saveOptimizerState: Boolean, copyWeights: Boolean): TensorFlowInferenceModel

Creates a copy.

evaluate
Link copied to clipboard
fun evaluate(dataset: Dataset, metric: Metrics): Double

Evaluates dataset via metric.

open override fun evaluate(dataset: Dataset, batchSize: Int, callbacks: List<Callback>): EvaluationResult
fun evaluate(dataset: Dataset, batchSize: Int = 256, callback: Callback): EvaluationResult

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

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

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

fun fit(dataset: Dataset, epochs: Int = 5, batchSize: Int = 32, callback: Callback): TrainingHistory
fun fit(trainingDataset: Dataset, validationDataset: Dataset, epochs: Int = 5, trainBatchSize: Int = 32, validationBatchSize: Int = 256, callback: Callback): 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, callbacks: List<Callback> = listOf()): TrainingHistory
fun fit(dataset: OnHeapDataset, validationRate: Double, epochs: Int, trainBatchSize: Int, validationBatchSize: Int, callback: Callback): 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, callbacks: List<Callback>): IntArray
fun predict(dataset: Dataset, batchSize: Int, callback: Callback): 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, callbacks: List<Callback>): Array<FloatArray>

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

fun predictSoftly(dataset: Dataset, batchSize: Int, callback: Callback): Array<FloatArray>

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

removeLastLayer
Link copied to clipboard
fun removeLastLayer(): Functional

Removes the last layer from the Functional model, if it's not compiled yet! .

reset
Link copied to clipboard
fun reset()

It ignores that model is initialized already and call initializers under the hood to re-initialize kGraph variables.

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.