Skip to content

Instantly share code, notes, and snippets.

@olokobayusuf
Last active January 30, 2022 20: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 olokobayusuf/f995c633f4fc2b3ed228d11e0b5471ad to your computer and use it in GitHub Desktop.
Save olokobayusuf/f995c633f4fc2b3ed228d11e0b5471ad to your computer and use it in GitHub Desktop.
Testing our NatML Hub predictor in NodeJS
import { MLModelData, MLImageFeature } from "natml"
import { ResNet18HubPredictor } from "../src"
async function main () {
// Fetch the model from NatML Hub
const modelData = await MLModelData.fromHub("@natsuite/resnet18", process.env.ACCESS_KEY);
const model = modelData.deserialize();
// Create the predictor
const predictor = new ResNet18Predictor(model);
// Predict
const feature = new MLImageFeature("cat.jpg");
const [label, score] = await predictor.predict(feature);
console.log(`Image contains ${label} with confidence ${score}`);
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment