0

It is difficult to retrain my models in new data because I never remember my initial optimizer, loss function, and hyperparameters. How can I extract all arguments I am passing to a TensorFlow function? Let's say from the code below, how to extract a list with the arguments learning_rate, beta_1, beta_2, and so on.

optimizer = tf.keras.optimizers.Adam(learning_rate=0.001,
                                    beta_1=0.9,beta_2=0.999, 
                                     epsilon=1e-07, amsgrad=False, 
                                      name="Adam")

I just want to extract names thus I can later on call them by for example:

optimizer.learning_rate

I have try .keys(), .classes(), but nothing work. Of course I can inspect it using dir(optimizer) but the output is not filtered.

deijany91
  • 9
  • 4

1 Answers1

0

I just found a way. The drawback it requires compiling the model first. I will post it because maybe someone has the same issue.

model.optimizer.get_config()
deijany91
  • 9
  • 4
  • It does not work if I have a variable, that is not compiled on the model as for example ```metrics = tf.keras.metrics.MeanAbsolutePercentageError(name="metrics", dtype=None)``` – deijany91 Feb 02 '23 at 12:32