const fs = require("fs");
const tf = require("@tensorflow/tfjs-node");
const mobilenet = require("@tensorflow-models/mobilenet");
const knnClassifier = require("@tensorflow-models/knn-classifier");
const classifier = knnClassifier.create();

const cat = fs.readFileSync("./photos/cat.png");
const dog = fs.readFileSync("./photos/dog.png");



const cat_ = tf.node.decodeImage(cat, 3);
const dog_ = tf.node.decodeImage(dog, 3);
let net = "";
async function Start() {
  const mynet = await mobilenet.load();
  net = mynet;
}

async function Train() {
  const ac = net.infer(cat_,true);
  classifier.addExample(ac,0)
  const ac2 = net.infer(dog_,true)
  classifier.addExample(ac2,1);
}
 
async function Run(obj) {
  const ac = net.infer(obj, "conv_preds")
  let pred = await classifier.predictClass(ac)
  console.log(pred)
}