如何使用Tensorflow Js部署自定义Keras图像分类

时间:2020-04-25 20:27:35

标签: javascript tensorflow keras

如何获得模型的预测? 我尝试使用.dataSync(),但未返回预测

这是我的代码:

<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@1.0.0/dist/tf.min.js"></script>

  <script>

  async function start() {

  const model1 = await tf.loadLayersModel('model_xray/model.json');
  const model2 = await tf.loadLayersModel('model_covid/model.json');

   const canvas = document.getElementById("myCanvas");
   var ctx = canvas.getContext("2d");
   var tmpImage = new Image();
   tmpImage.src = 'radiografie.jpg';
   tmpImage.onload = function(){
   ctx.drawImage(tmpImage,0,0,224,224);
   imageData = ctx.getImageData(null, 0, 64, 64);
   const tensor = tf.browser.fromPixels(imageData);
   const eTensor = tensor.expandDims(0);
   var prediction = model1.predict(eTensor);
   console.log(prediction.dataSync());
   console.log(imageData);
   console.log(tensor);
   console.log(eTensor);
}

}

start();

  </script>

这是控制台日志结果: this is the console log result

0 个答案:

没有答案