When I load a trained model (In tensorflow.js within Node.js) that I have previously saved, the model topology is being loaded, but none of the weights are loaded (so I have to train the model from scratch). No errors are thrown.
To save the model, I am using:
async function save(path) {
//misc. unrelated code goes here
await model.save('file://' + path);
}
All files appear (model.json and weights.bin), and no errors are thrown.
To load the file, I am using :
async function load(path) {
//misc. unrelated code goes here.
model = await tf.loadLayersModel('file://' + path + '/model.json');
}
Again, no errors are thrown. The model topology is loaded correctly. The weights aren't though, and the model behaves as if I had just constructed/compiled it.
I am using tfjs-node save:
const tf = require('@tensorflow/tfjs');
require("tfjs-node-save");
I would really appreciate any help or advice!!! Thank you!
save() and loadLayersModel() are async functions.
model.save(url).then(result => console.log(result));
tf.loadLayersModel(url).then(result => console.log(result))
So it turns out this was just a dumb mistake.
I had a wrapper function to add some functionality to model.compile().
For some godforsaken reason, in that function, I called my initialization function, which overwrote the model.
tl;dr, don't overwrite a model you want to keep.