如何获得模型的预测? 我尝试使用.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>