Skip to content

Instantly share code, notes, and snippets.

@Rishit-dagli
Created March 31, 2020 15:06
Show Gist options
  • Save Rishit-dagli/625fc0023653d5b7ff937b888628b24a to your computer and use it in GitHub Desktop.
Save Rishit-dagli/625fc0023653d5b7ff937b888628b24a to your computer and use it in GitHub Desktop.
Training a sample model TF.js
async function trainModel(model, inputs, labels) {
// Prepare the model for training.
model.compile({
optimizer: tf.train.adam(),
loss: tf.losses.meanSquaredError,
metrics: ['mse'],
});
const batchSize = 32;
const epochs = 50;
return await model.fit(inputs, labels, {
batchSize,
epochs,
shuffle: true,
callbacks: tfvis.show.fitCallbacks(
{ name: 'Training Performance' },
['loss', 'mse'],
{ height: 200, callbacks: ['onEpochEnd'] }
)
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment