Skip to content
Advertisement

If-Else Statement in Custom Training Loop in Tensorflow

I created a model class which is a subclass of keras.Model. While training the model, I want to change the weights of the loss functions after some epochs. In order to do that I created boolean variables to my model indicating that the model should start training with additional loss function. I add a pseudo code that mainly shows what I am trying to achieve.

JavaScript

My questions is:

  • Is it valid to use if-else statement whose value changes after some time? If it is not, how can achieve this?

Advertisement

Answer

Yes. You can create a tf.Variable and then assign a new value to it based on some training criteria.

Example:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement