I have saved a TFJS model to a document in cloud firestore, if I run this code straight from the browser:
const jsonObject = JSON.parse(TFModeljson);
loadedModel = await tf.loadLayersModel(tf.io.fromMemory(jsonObject));
const inputTensor = tf.tensor2d(numericValues, [1, numericValues.length]);
loadedModel.predict(inputTensor).data().then(prediction => {
//same predictions based on the same data
}
It works fine but when I try to run it in a Firebase cloud function like this:
const TFModel = JSON.parse(TFModeljson);
const model = await tf.loadLayersModel(tf.io.fromMemory(TFModel));
let type;
for (let i = 0; i < looplength; i++) {
const row = data[i];
console.log(row);
const tensor = tf.tensor2d([row]);
const prediction = model.predict(tensor).dataSync();
console.log('Prediction:', prediction);
}
I get different predictions every time and its not even close, (last runs I got back 1060.4051513671875, 949.4125366210938, 1934.115966796875, -1049.058837890625)
In both pieces of code TFModeljson is the data from Firestore. If I send 3 rows to the cloud function with the same rows I do get 3 times the same prediction back, but when I rerun this function I get another prediction again. Does anyone know what’s wrong with my code?