pdfcoffee

soumyasankar99
from soumyasankar99 More from this publisher
09.05.2023 Views

}Chapter 13const container = {name: 'Accuracy', tab: 'Evaluation'};tfvis.show.perClassAccuracy(container, classAccuracy, classNames);labels.dispose();async function showConfusion(model, data) {const [preds, labels] = doPrediction(model, data);const confusionMatrix = await tfvis.metrics.confusionMatrix(labels, preds);const container = {name: 'Confusion Matrix', tab: 'Evaluation'};tfvis.render.confusionMatrix(container, {values: confusionMatrix}, classNames);labels.dispose();}Finally, the run() function will call all these functions in sequence to build an endto-endML pipeline:import {MnistData} from './data.js';async function run() {const data = new MnistData();await data.load();await showExamples(data);const model = getModel();tfvis.show.modelSummary({name: 'Model Architecture'}, model);await train(model, data);await showAccuracy(model, data);await showConfusion(model, data);}document.addEventListener('DOMContentLoaded', run);Refreshing the browser location http://localhost:8000/index.html will invokethe run() method above. The table below shows the model architecture, and theplots below that show the progress of the training.[ 483 ]

TensorFlow for Mobile and IoT and TensorFlow.jsOn the left are the loss and accuracy values on the validation dataset observedat the end of each batch, and on the right are the same loss and accuracy valuesobserved on the training dataset (blue) and validation dataset (red) at the end ofeach epoch:In addition, the following figure shows the accuracies across different classes forpredictions from our trained model on the test dataset, as well as the confusionmatrix of predicted versus actual classes for test dataset samples:[ 484 ]

}

Chapter 13

const container = {name: 'Accuracy', tab: 'Evaluation'};

tfvis.show.perClassAccuracy(container, classAccuracy, classNames);

labels.dispose();

async function showConfusion(model, data) {

const [preds, labels] = doPrediction(model, data);

const confusionMatrix = await tfvis.metrics.confusionMatrix(

labels, preds);

const container = {name: 'Confusion Matrix', tab: 'Evaluation'};

tfvis.render.confusionMatrix(

container, {values: confusionMatrix}, classNames);

labels.dispose();

}

Finally, the run() function will call all these functions in sequence to build an endto-end

ML pipeline:

import {MnistData} from './data.js';

async function run() {

const data = new MnistData();

await data.load();

await showExamples(data);

const model = getModel();

tfvis.show.modelSummary({name: 'Model Architecture'}, model);

await train(model, data);

await showAccuracy(model, data);

await showConfusion(model, data);

}

document.addEventListener('DOMContentLoaded', run);

Refreshing the browser location http://localhost:8000/index.html will invoke

the run() method above. The table below shows the model architecture, and the

plots below that show the progress of the training.

[ 483 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!