class_docstr: Callback for logging Tensorflow training metrics to MLflow.
  
  This callback logs model information at training start, and logs training metrics every epoch or
  every n steps (defined by the user) to MLflow.
  
  Args:
      run: an `mlflow.entities.run.Run` instance, the MLflow run.
      log_every_epoch: bool, If True, log metrics every epoch. If False, log metrics every n
          steps.
      log_every_n_steps: int, log metrics every n steps. If None, log metrics every epoch.
          Must be `None` if `log_every_epoch=True`.
  
  .. code-block:: python
      :caption: Example
  
      from tensorflow import keras
      import mlflow
      import numpy as np
  
      # Prepare data for a 2-class classification.
      data = tf.random.uniform([8, 28, 28, 3])
      label = tf.convert_to_tensor(np.random.randint(2, size=8))
  
      model = keras.Sequential(
          [
              keras.Input([28, 28, 3]),
              keras.layers.Flatten(),
              keras.layers.Dense(2),
          ]
      )
  
      model.compile(
          loss=keras.losses.SparseCategoricalCrossentropy(from_logits=True),
          optimizer=keras.optimizers.Adam(0.001),
          metrics=[keras.metrics.SparseCategoricalAccuracy()],
      )
  
      with mlflow.start_run() as run:
          model.fit(
              data,
              label,
              batch_size=4,
              epochs=2,
              callbacks=[MLflowCallback(run)],
          )
code: def __init__(self, run, log_every_epoch=True, log_every_n_steps=None):
      self.metrics_logger = BatchMetricsLogger(run.info.run_id)
      self.log_every_epoch = log_every_epoch
      self.log_every_n_steps = log_every_n_steps
  
      if log_every_epoch and log_every_n_steps is not None:
          raise ValueError(
              "`log_every_n_steps` must be None if `log_every_epoch=True`, received "
              f"`log_every_epoch={log_every_epoch}` and `log_every_n_steps={log_every_n_steps}`."
          )
      if not log_every_epoch and log_every_n_steps is None:
          raise ValueError(
              "`log_every_n_steps` must be specified if `log_every_epoch=False`, received"
              "`log_every_n_steps=False` and `log_every_n_steps=None`."
          )
  
file_path: mlflow/mlflow/tensorflow/callback.py
imports: from tensorflow import keras
  from mlflow import log_params, log_text
  from mlflow.utils.autologging_utils import BatchMetricsLogger
label_desc: Use image node_id 1 to create a new MLflowCallback object from inherited base classes: keras.callbacks with example: obj = MLflowCallback(run, log_every_epoch, log_every_n_steps)