Skip to content

Instantly share code, notes, and snippets.

@selynna
Last active May 24, 2019 17:02
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 selynna/8f5bce0a006d1af7ccb570ba2e4e74c0 to your computer and use it in GitHub Desktop.
Save selynna/8f5bce0a006d1af7ccb570ba2e4e74c0 to your computer and use it in GitHub Desktop.
// Train classifier
console.log("Training...");
let trainingIteration = await trainer.trainProject(project.id);
console.log("Training started...");
while (trainingIteration.status == "Training") {
await setTimeoutPromise(1000, null);
trainingIteration = await trainer.getIteration(project.id, trainingIteration.id)
}
console.log("Training status: " + trainingIteration.status);
// Publish the iteration to endpoint
await trainer.publishIteration(project.id, trainingIteration.id, publishIterationName, predictionResourceId);
const predictor = new PredictionApiClient(predictionKey, endpoint);
const testFile = fs.readFileSync(`${dataRoot}/test/maybe-pizza.jpeg`);
const results = await predictor.classifyImage(project.id, publishIterationName, testFile);
// Show results
console.log("Results:");
results.predictions.forEach(predictedResult => {
console.log(`\t ${predictedResult.tagName}: ${(predictedResult.probability * 100.0).toFixed(2)}%`);
});
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment