Skip to content

Instantly share code, notes, and snippets.

@mdfarragher
Created December 2, 2019 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdfarragher/413d0b5040b79882cb0619409378e111 to your computer and use it in GitHub Desktop.
Save mdfarragher/413d0b5040b79882cb0619409378e111 to your computer and use it in GitHub Desktop.
// train one epoch on batches
loss[epoch] = 0.0;
trainingError[epoch] = 0.0;
batchCount = 0;
training_data.Index().Shuffle().Batch(batchSize, (indices, begin, end) =>
{
// get the current batch
var featureBatch = features.GetBatch(training_data, indices, begin, end);
var labelBatch = labels.GetBatch(training_labels, indices, begin, end);
// train the network on the batch
var result = trainer.TrainBatch(
new[] {
(features, featureBatch),
(labels, labelBatch)
},
false
);
loss[epoch] += result.Loss;
trainingError[epoch] += result.Evaluation;
batchCount++;
});
// show results
loss[epoch] /= batchCount;
trainingError[epoch] /= batchCount;
Console.Write($"{epoch}\t{loss[epoch]:F3}\t{trainingError[epoch]:F3}\t");
// testing code goes here...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment