class_docstr: Keras to Ray Tune reporting callback
  
  Reports metrics to Ray Tune.
  
  Args:
      metrics: Metrics to report to Tune. If this is a list,
          each item describes the metric key reported to Keras,
          and it will reported under the same name to Tune. If this is a
          dict, each key will be the name reported to Tune and the respective
          value will be the metric key reported to Keras. If this is None,
          all Keras logs will be reported.
      on: When to trigger checkpoint creations. Must be one of
          the Keras event hooks (less the ``on_``), e.g.
          "train_start", or "predict_end". Defaults to "epoch_end".
  
  Example:
  
  .. code-block:: python
  
      from ray.tune.integration.keras import TuneReportCallback
  
      # Report accuracy to Tune after each epoch:
      model.fit(
          x_train,
          y_train,
          batch_size=batch_size,
          epochs=epochs,
          verbose=0,
          validation_data=(x_test, y_test),
          callbacks=[TuneReportCallback(
              {"mean_accuracy": "accuracy"}, on="epoch_end")])
class_docstr_tok: ["Keras","to","Ray","Tune","reporting","callback","Reports","metrics","to","Ray","Tune",".","Args",":","metrics",":","Metrics","to","report","to","Tune",".","If","this","is","a","list",",","each","item","describes","the","metric","key","reported","to","Keras",",","and","it","will","reported","under","the","same","name","to","Tune",".","If","this","is","a","dict",",","each","key","will","be","the","name","reported","to","Tune","and","the","respective","value","will","be","the","metric","key","reported","to","Keras",".","If","this","is","None",",","all","Keras","logs","will","be","reported",".","on",":","When","to","trigger","checkpoint","creations",".","Must","be","one","of","the","Keras","event","hooks","(","less","the","``","on_","``",")",",","e.g",".","``","train_start","''",",","or","``","predict_end","''",".","Defaults","to","``","epoch_end","''",".","Example",":","..","code-block",":",":","python","from","ray.tune.integration.keras","import","TuneReportCallback","#","Report","accuracy","to","Tune","after","each","epoch",":","model.fit","(","x_train",",","y_train",",","batch_size=batch_size",",","epochs=epochs",",","verbose=0",",","validation_data=","(","x_test",",","y_test",")",",","callbacks=","[","TuneReportCallback","(","{","``","mean_accuracy","''",":","``","accuracy","''","}",",","on=","''","epoch_end","''",")","]",")"]
code: def _handle(self, logs: Dict, when: str = None):
      if not self._metrics:
          report_dict = logs
      else:
          report_dict = {}
          for key in self._metrics:
              if isinstance(self._metrics, dict):
                  metric = self._metrics[key]
              else:
                  metric = key
              report_dict[key] = logs[metric]
      tune.report(**report_dict)
  
file_path: ray/python/ray/tune/integration/keras.py
imports: import os
  from collections import Counter
  from typing import Dict, List, Optional, Union
  from ray import tune
  from ray.util.annotations import Deprecated
  from ray.air.integrations.keras import _Callback
label_desc: Use image node_id 2 for calling the TuneReportCallback obj's underlying member method code with example usage: obj._handle(logs, when) without return types