Home > Mobile >  Externally add a Variable to a model in TensorFlow
Externally add a Variable to a model in TensorFlow

Time:05-20

I have an existing TensorFlow model, and I want to add a new "parameter" (a tf.Variable) to the model's list of parameters (such that it's trainable) and add it externally to the model's list of parameters / computational graph.

One approach that I tried, is to append the new parameters to the model's list of trainable weights, something like this (here new_parameter is a tf.Variable) -

model.layers[-1].trainable_weights.extend([new_parameter])
model.compile(....)

But I'm not sure if that's the best way to go about it. In PyTorch, we have nn.Parameter instead of tf.Variable, and we have Sample

  • Related