class_docstr: A predictor for TensorFlow models.
  
  Args:
      model: A Tensorflow Keras model to use for predictions.
      preprocessor: A preprocessor used to transform data batches prior
          to prediction.
      model_weights: List of weights to use for the model.
      use_gpu: If set, the model will be moved to GPU on instantiation and
          prediction happens on GPU.
class_docstr_tok: ["A","predictor","for","TensorFlow","models",".","Args",":","model",":","A","Tensorflow","Keras","model","to","use","for","predictions",".","preprocessor",":","A","preprocessor","used","to","transform","data","batches","prior","to","prediction",".","model_weights",":","List","of","weights","to","use","for","the","model",".","use_gpu",":","If","set",",","the","model","will","be","moved","to","GPU","on","instantiation","and","prediction","happens","on","GPU","."]
code: def __init__(
      self,
      *,
      model: Optional[tf.keras.Model] = None,
      preprocessor: Optional["Preprocessor"] = None,
      use_gpu: bool = False,
  ):
      self.use_gpu = use_gpu
      # TensorFlow model objects cannot be pickled, therefore we use
      # a callable that returns the model and initialize it here,
      # instead of having an initialized model object as an attribute.
      # Predictors are not serializable (see the implementation of __reduce__)
      # in the Predictor class, so we can safely store the initialized model
      # as an attribute.
      if use_gpu:
          # TODO (jiaodong): #26249 Use multiple GPU devices with sharded input
          with tf.device("GPU:0"):
              self._model = model
      else:
          self._model = model
          gpu_devices = tf.config.list_physical_devices("GPU")
          if len(gpu_devices) > 0 and log_once(
              "tf_predictor_not_using_gpu"
          ):
              logger.warning(
                  "You have `use_gpu` as False but there are "
                  f"{len(gpu_devices)} GPUs detected on host where "
                  "prediction will only use CPU. Please consider explicitly "
                  "setting `TensorflowPredictor(use_gpu=True)` or "
                  "`batch_predictor.predict(ds, num_gpus_per_worker=1)` to "
                  "enable GPU prediction."
              )
      super().__init__(preprocessor)
  
file_path: ray/python/ray/train/tensorflow/tensorflow_predictor.py
imports: import logging
  from typing import TYPE_CHECKING, Callable, Dict, Optional, Type, Union
  import numpy
  import tensorflow
  from ray.air._internal.tensorflow_utils import convert_ndarray_batch_to_tf_tensor_batch
  from ray.train._internal.dl_predictor import DLPredictor
  from ray.train.predictor import DataBatchType
  from ray.train.tensorflow import TensorflowCheckpoint
  from ray.util import log_once
  from ray.util.annotations import DeveloperAPI, PublicAPI
label_desc: Use image node_id 1 to create a new TensorflowPredictor object from inherited base classes: DLPredictor with example: obj = TensorflowPredictor()