pythontensorflowtensorflow2.0eager-execution

How do you pass session object in TensorFlow v2?


I have a function change_weight() that modifies weights in any given model. This function resides in a different python file.

So if I have a simple neural network that classifies MNIST images, I test the accuracy before and after calling this function and I see that it works. This was easy to do in TensorFlow v1, as I just had to pass the Session sess object in the function call, and I could get the weights of this session in the other file.

With eager execution in TensorFlow v2, how do I do this? I don't have a Session object anymore. What do I pass?


Solution

  • I was able to do this by passing the Model object instead and getting the weights by model.trainable_variables in the other function.