docstr: Args:
      validation_data (DataFlow or InputSource): to be used for inference.
          The inference callback is added as the first in the callback list.
          If you need to use it in a different order, please write it in the callback list manually.
      kwargs: same arguments as :meth:`Trainer.train_with_defaults`.
docstr_tok: ["Args",":","validation_data","(","DataFlow","or","InputSource",")",":","to","be","used","for","inference",".","The","inference","callback","is","added","as","the","first","in","the","callback","list",".","If","you","need","to","use","it","in","a","different","order",",","please","write","it","in","the","callback","list","manually",".","kwargs",":","same","arguments","as",":","meth",":","`","Trainer.train_with_defaults","`","."]
code: def fit(self, validation_data=None, **kwargs):
      """
      Args:
          validation_data (DataFlow or InputSource): to be used for inference.
              The inference callback is added as the first in the callback list.
              If you need to use it in a different order, please write it in the callback list manually.
          kwargs: same arguments as :meth:`Trainer.train_with_defaults`.
      """
      callbacks = kwargs.pop("callbacks", [])
      if validation_data is not None:
          # There is no way to guess where users want this callback. So we have to choose one.
          # MinSaver may need results from this callback,
          # so we put this callback at first.
          callbacks.insert(
              0,
              InferenceRunner(
                  validation_data, ScalarStats(self._stats_to_inference)
              ),
          )
      self.trainer.train_with_defaults(callbacks=callbacks, **kwargs)
  
imports: from contextlib import contextmanager
  import six
  import tensorflow
  from tensorflow import keras
  from ..callbacks import Callback, CallbackToHook, InferenceRunner, InferenceRunnerBase, ScalarStats
  from ..models.regularize import regularize_cost_from_collection
  from ..tfutils.collection import backup_collection, restore_collection
  from ..tfutils.common import get_op_tensor_name
  from ..tfutils.scope_utils import cached_name_scope
  from ..tfutils.summary import add_moving_summary
  from ..tfutils.tower import get_current_tower_context
  from ..train import SimpleTrainer, SyncMultiGPUTrainerParameterServer, Trainer
  from ..train.interface import apply_default_prefetch
  from ..train.trainers import DistributedTrainerBase
  from ..utils import logger
  from ..utils.gpu import get_nr_gpu
label_desc: Use image node_id 3 for calling the KerasModel obj's underlying member method code with example usage: obj.fit(validation_data) without return types