Skip to content

Validator

Description

Handler designed to simplify the process of model validation for the user by eliminating the need to manually prescribe a sequence of actions. It is a kind of a wrapper function around the operations on data.

Info

In handlers, depending on the location of the data, splitting can be performed in the following ways:

  • data is placed on the disk: first, data is split into macrobatches - blocks that are entirely placed in the GPU, whereafter the macrobatch is split into smaller batches, which are then fed directly to the model input;
  • data has already been placed in the GPU: it is split into batches, which are then fed directly to the input of the model.

Initializing

def __init__(self, mod, cost, onBatchFinish=None, batchsize=128):

Parameters

Parameter Allowed types Description Default
mod Module Trainable neural network -
cost Cost Target function -
onBatchFinish callable Function that will be called upon completion processing of a data batch None
batchsize int Size of a data batch 128

Explanations

-

Methods

All the basic methods of handlers can be found in the documentation for the parent class Handler.

validateFromHost

def validateFromHost(self, data, target, macroBatchSize=10000, onMacroBatchFinish=None):

Functionality

Wrapper function around the handleFromHost() method of the Handlerparent class, taking into account the specifics of the validation process: the model is switched to inference mode (some network layers can behave differently in the training and inference modes), whereafter the error is calculated on the transmitted data. Returns the error value

Parameters

Parameter Allowed types Description Default
data tensor Data tensor -
target tensor Tensor of data corresponding labels None
macroBatchSize int Size of a macrobatch. The data will be split into macrobatches sized macrobatchSize 10000
onMacroBatchFinish callable Function that will be called upon completion of processing of a macrobatch None

Explanations

-

validate

def validate(self, data, target):

Functionality

Wrapper function around the handle() method of the Handler parent class, taking into account the specifics of the validation process: the model is switched to inference mode (some network layers can behave differently in the training and inference modes), whereafter the error is calculated on the transmitted data. Returns the error value.

Parameters

Parameter Allowed types Description Default
data GPUArray Data tensor placed in the GPU -
target GPUArray Tensor of data corresponding labels, placed in the GPU None

Explanations

-

handleBatch

def handleBatch(self, batch, idx, resid, state):
Functionality

Root method of the validation handler. Calculates the error value on the batch.

Parameters

Parameter Allowed types Description Default
batch list List of two elements: [data, target] -
idx int Index number of the data batch -
state dict Dictionary containing information about the total error -

Explanations

-