Пример #1
0
        /// <summary>
        /// Runs the epoch.
        /// </summary>
        /// <param name="iteration">The iteration.</param>
        /// <param name="train">The train.</param>
        /// <param name="val">The value.</param>
        /// <returns></returns>
        private int RunEpoch(int iteration, DataFrameIter train, DataFrameIter val = null)
        {
            train_losses.Clear();
            train_metrics.Clear();
            val_losses.Clear();
            val_metrics.Clear();

            train.Reset();
            if (val != null)
            {
                val.Reset();
            }

            while (train.Next())
            {
                var(x, y) = train.GetBatch();
                RunTrainOnBatch(iteration, x, y);
                x.Dispose();
                y.Dispose();
            }

            if (val != null)
            {
                while (val.Next())
                {
                    var(x, y) = val.GetBatch();

                    var pred = Forward(x);

                    var lossVal   = LossFn.Forward(pred, y);
                    var metricVal = MetricFn.Calc(pred, y);
                    val_losses.Add(K.Mean(lossVal));
                    val_metrics.Add(K.Mean(metricVal));
                    x.Dispose();
                    y.Dispose();
                    lossVal.Dispose();
                    metricVal.Dispose();
                }
            }

            return(iteration);
        }