0

I've defined a custom keras model using Model subclass. And I want to convert this model to estimator for distributed training. Simple codes are as follow:

    tf.logging.set_verbosity(tf.logging.INFO)

    model = EstimatorModel()

    model.compile(optimizer=tf.keras.optimizers.Adam(),
                  loss='categorical_crossentropy',
                  metrics=['accuracy'])

    estimator_model = tf.keras.estimator.model_to_estimator(
        keras_model=model, model_dir=FLAGS.model_path)

    estimator_model.train(input_fn=input_fn)

Code can run normally. Now, the question is the estimator only print the loss, and didn't print the metric. I've tried to add metric to estimator_model using tf.estimator.add_metrics(estimator_model, my_auc), but it still not work. What should I do to solve this?

Alexander
  • 523
  • 5
  • 21
  • 1
    see here https://stackoverflow.com/questions/45353389/printing-extra-training-metrics-with-tensorflow-estimator/45716062#45716062 – eugen Sep 19 '19 at 11:05
  • @eugen Thanks for that, according to the method, I found a way that can add to logging_hook to train_spec in `tf.estimator.train_and_evaluate`. But another question is that I can't get the tesor names of loss and accuracy from `keras to estimator model`, because the loss and metric are defined in `keras model compile`. I've tried get the name from tensorboard, but raise error `The name 'output_1_loss' refers to a Tensor which does not exist.`. – Alexander Sep 20 '19 at 10:07

0 Answers0