SiaNet/TrainPredict.cs
/// <summary>
/// Runs the train on batch.
/// </summary>
/// <param name="i">The i.</param>
/// <param name="x">The x.</param>
/// <param name="y">The y.</param>
Runs the train on batch.
Runs the train on batch .
private void RunTrainOnBatch(int i, Tensor x, Tensor y)
        {
            Tensor pred = Forward(x);
            Tensor lossVal = LossFn.Forward(pred, y);
            Tensor grad = LossFn.Backward(pred, y);
            lossVal = ApplyRegularizer(lossVal);
            var metricVal = MetricFn.Calc(pred, y);
            train_losses.Add(K.Mean(lossVal));
            train_metrics.Add(K.Mean(metricVal));
            Backward(grad);
            ApplyDeltaRegularizer();
            foreach (var layer in Layers)
            {
                OptimizerFn.Update(i, layer);
            }
            pred.Dispose();
            lossVal.Dispose();
            grad.Dispose();
        }
private void RunTrainOnBatch ( int i , Tensor x , Tensor y ) { Tensor pred = Forward ( x ) ; Tensor lossVal = LossFn . Forward ( pred , y ) ; Tensor grad = LossFn . Backward ( pred , y ) ; lossVal = ApplyRegularizer ( lossVal ) ; var metricVal = MetricFn . Calc ( pred , y ) ; train_losses . Add ( K . Mean ( lossVal ) ) ; train_metrics . Add ( K . Mean ( metricVal ) ) ; Backward ( grad ) ; ApplyDeltaRegularizer ( ) ; foreach ( var layer in Layers ) { OptimizerFn . Update ( i , layer ) ; } pred . Dispose ( ) ; lossVal . Dispose ( ) ; grad . Dispose ( ) ; }
Runs the train on batch.
Runs the train on batch .
i
int
None
x
Tensor
None
y
Tensor
None