Currently, I am delving into the realm of developing an ML model with TensorFlow JS. Although I am fairly new to both JavaScript and ML, I have managed to create a functional model that provides satisfactory predictions. However, I encountered an issue when attempting to save the model and load it into a client-side UI - the min/max values used for normalization also need to match in order to ensure consistent predictions (at least, that's what I believe is causing the discrepancy). I tried various methods such as retrieving the min/max data as individual tensor values or extracting the entire tensor to iterate through and identify the min/max values. Additionally, I experimented with hardcoding the min/max as either a number or an object.
Despite being able to view the tensor data, I faced difficulty accessing the min/max values which resulted in a NaN error during prediction. Given my limited experience in this field, I assume there must be a glaringly obvious oversight on my part. Any assistance would be greatly appreciated as I find myself growing increasingly frustrated trying to pinpoint where I might have gone wrong.
//saving tensor normalisedFeature for future retrieval of min/max
function downloadJ() {
let values = {
normalisedFeature
};
let json = JSON.stringify(values);
//Convert JSON string to BLOB.
json = [json];
let blob1 = new Blob(json, { type: "text/json;charset=utf-8" });
let url = window.URL || window.webkitURL;
link = url.createObjectURL(blob1);
let a = document.createElement("a");
a.download = "tValues.json";
a.href = link;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
//loading tensor saved values
let normalisedFeatureJ = {};
$.ajax({
url: "model/tValues.json",
async: false,
dataType: 'json',
success: function(data) {
normalisedFeatureJ = (data);
}
});
console.log(Object.values(normalisedFeatureJ));
//tried dataSync(), looping, parsing etc. Unable to access min/max values
//JSON file structure:
{"normalisedFeature":
{"tensor": {"isDisposedInternal":false,"shape":[10000,17],"dtype":"float32","size":170000,"strides":[17],"dataId":{},"id":28,"rankType":"2"},
"min":{"isDisposedInternal":false,"shape":[],"dtype":"float32","size":1,"strides":[],"dataId":{},"id":6,"rankType":"0"},
"max":{"isDisposedInternal":false,"shape":[],"dtype":"float32","size":1,"strides":[],"dataId":{},"id":16,"rankType":"0"}}}
While attempting to work out the calculations without leveraging tensor operations, things quickly descended into chaos :)