0
votes

I am using a pretrained (in Python) Keras model by loading it into JavaScript with tensorflow.js and using the tensorflow.js library. This model has a GaussianNoise input layer, and a GaussianDropout layer, with respective properties stddev and rate.

After loading the model, say:

let model;
(async function () {
    model = await tf.loadLayersModel("TensorFlowModels/dnn_fscav.json");
})();

In the same path I keep the weights in a .bin file. Now, my problem is that I need to change the stddev of the GaussianNoise layer and the rate of the GaussianDropout after loading the model, ideally directly from the model. I have looked into the model tensorflow object and its layers, but I could not find these properties.

I also know I can directly change these properties from the JSON file, but that means reading the JSON, modify it, and then read it with tensorflow.. which is not ideal. I have also looked at the tensorflow.js API reference, but found no explanation on how to do this.

Does anyone know a cleaner way to change layers properties from a loaded model?

1

1 Answers

0
votes

In case this helps anyone, after looking closer to the Tensorflow model object, I realised it has a circular structure. That meaning, some object properties call other object properties, which at the same time call the previous object properties. I could find the layer properties in the following object properties:

model.layers[layer_number].outboundNodes[0].outboundLayer.property = new_value

In my case, property is stddev for GaussianNoise layer of the neural network and rate for the GaussianDropout layer. By changing that property to a new value and saving the model, I could confirm that the properties of the layers are changed. I guess you can also access the properties from any of the other circular features in the object, as they all point to the same value.