Hi,
I am trying to deploy the model from the Week 1 assignment, the one for predicting diseases based on a Chest X-Ray. I am trying to deploy it with TerraformJS, so that I can have a static web page.
However, I am not getting the expected results. If anyone who is more familiar with Terraform/TerraformJS than myself could give me a hand, I would appreciate.
This is the javascript code
async function run() {
// Import model
image = document.getElementById("example_image");
const model = await tf.loadLayersModel('http://localhost/ml/saved_model.tfjs/model.json');
// Infere
tensorImg = tf.browser.fromPixels(image).resizeNearestNeighbor([320, 320]).toFloat().sub(tf.scalar(127)).div(tf.scalar(127)).expandDims();
const prediction = model.predict(tensorImg).dataSync();
document.getElementById("prediction").innerText = prediction;
alert("Done!");
}
run();
and the HTML:
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@2.0.0/dist/tf.min.js">
import * as tf from '@tensorflow/tfjs';
</script>
</head>
<body>
Hello World
<img id="example_image" src="00008270_015.png"/>
<div id="prediction">prediction</div>
<script src="./app.js"> </script>
</body>
</html>
The predictions I am getting for 00008270_015.png are:
0.005539100617170334,0.03543306514620781,0.015558389946818352,0.12826170027256012,0.4334452152252197,0.06943535804748535,0.12194258719682693,0.09075117111206055,0.04148877039551735,0.07736095041036606,0.15867561101913452,0.06838551163673401,0.010514311492443085,0.08459567278623581
They don’t look like what we get in the assignment … so I was wondering what could I be doing wrong? I suspect is how I deal with the sample… I tried scaling and normalizing but seems is not enough to get the same predictions.
Many thanks in advance
jordi