Exemplo n.º 1
0
def predict_distributed(model,
                        x=None,
                        batch_size=None,
                        verbose=0,
                        steps=None,
                        callbacks=None):
  """Predict loop for Distribution Strategies."""
  distributed_training_utils.validate_inputs(
      x, None, model._distribution_strategy)
  first_x_value = nest.flatten(x)[0]
  if isinstance(first_x_value, np.ndarray):
    steps, batch_size = distributed_training_utils.get_input_params(
        model._distribution_strategy, first_x_value, steps, batch_size)
  batch_size = model._validate_or_infer_batch_size(batch_size, steps, x)
  iterator = model._distribution_standardize_user_data(
      x,
      batch_size=batch_size,
      check_steps=True,
      steps_name='steps',
      steps=steps)
  if distributed_training_utils.is_tpu_strategy(model._distribution_strategy):
    # TODO(fchollet): why aren't callbacks supported here?
    return experimental_tpu_predict_loop(
        model, iterator, verbose=verbose, steps=steps)
  else:
    return training_arrays.predict_loop(
        model,
        iterator,
        batch_size=batch_size,
        verbose=verbose,
        steps=steps,
        callbacks=callbacks)
Exemplo n.º 2
0
def predict_distributed(model,
                        x=None,
                        batch_size=None,
                        verbose=0,
                        steps=None,
                        callbacks=None):
  """Predict loop for Distribution Strategies."""
  distributed_training_utils.validate_inputs(
      x, None, model._distribution_strategy)
  first_x_value = nest.flatten(x)[0]
  if isinstance(first_x_value, np.ndarray):
    steps, batch_size = distributed_training_utils.get_input_params(
        model._distribution_strategy, first_x_value, steps, batch_size)
  batch_size = model._validate_or_infer_batch_size(batch_size, steps, x)
  dataset = model._distribution_standardize_user_data(
      x,
      batch_size=batch_size,
      check_steps=True,
      steps_name='steps',
      steps=steps)
  if distributed_training_utils.is_tpu_strategy(model._distribution_strategy):
    # TODO(fchollet): why aren't callbacks supported here?
    return experimental_tpu_predict_loop(
        model, dataset, verbose=verbose, steps=steps)
  else:
    return training_arrays.predict_loop(
        model,
        dataset,
        batch_size=batch_size,
        verbose=verbose,
        steps=steps,
        callbacks=callbacks)
Exemplo n.º 3
0
def predict_distributed(model,
                        x=None,
                        batch_size=None,
                        verbose=0,
                        steps=None,
                        callbacks=None):
  """Predict loop for Distribution Strategies."""
  distributed_training_utils.validate_inputs(
      x, None, model._distribution_strategy, allow_partial_batch=True)
  first_x_value = nest.flatten(x)[0]
  if isinstance(first_x_value, np.ndarray):
    steps, batch_size = distributed_training_utils.get_input_params(
        model._distribution_strategy, first_x_value, steps,
        batch_size, mode=ModeKeys.PREDICT)
  batch_size = model._validate_or_infer_batch_size(batch_size, steps, x)
  dataset = model._distribution_standardize_user_data(
      x,
      batch_size=batch_size,
      repeat=False,
      allow_partial_batch=True)
  if distributed_training_utils.is_tpu_strategy(model._distribution_strategy):
    return experimental_tpu_predict_loop(
        model, dataset, verbose=verbose, steps=steps, callbacks=callbacks)
  else:
    return training_arrays.predict_loop(
        model,
        dataset,
        batch_size=batch_size,
        verbose=verbose,
        steps=steps,
        callbacks=callbacks)
Exemplo n.º 4
0
 def predict(self,
             model,
             x,
             batch_size=None,
             verbose=0,
             steps=None,
             callbacks=None,
             **kwargs):
   """Predict loop for Distribution Strategies."""
   dist_utils.validate_inputs(x=x, y=None)
   batch_size, steps = self._process_batch_and_step_size(
       model, x, batch_size, steps, ModeKeys.PREDICT)
   batch_size = model._validate_or_infer_batch_size(batch_size, steps, x)
   dataset = model._distribution_standardize_user_data(
       x,
       batch_size=batch_size,
       allow_partial_batch=True)
   if dist_utils.is_tpu_strategy(model._distribution_strategy):
     steps = training_utils.infer_steps_for_dataset(
         dataset, steps, steps_name='steps')
     if steps is None:
       raise ValueError('Number of steps could not be infered from the data, '
                        'please pass the steps argument.')
     if not context.executing_eagerly():
       return experimental_tpu_predict_loop(
           model, dataset, verbose=verbose, steps=steps, callbacks=callbacks)
   return training_arrays.predict_loop(
       model,
       dataset,
       batch_size=batch_size,
       verbose=verbose,
       steps=steps,
       callbacks=callbacks)
Exemplo n.º 5
0
def predict_distributed(model,
                        x=None,
                        batch_size=None,
                        verbose=0,
                        steps=None,
                        callbacks=None):
  """Predict loop for Distribution Strategies."""
  distributed_training_utils.validate_inputs(
      x, None, model._distribution_strategy, allow_partial_batch=True)
  first_x_value = nest.flatten(x)[0]
  if isinstance(first_x_value, np.ndarray):
    steps, batch_size = distributed_training_utils.get_input_params(
        model._distribution_strategy, first_x_value, steps,
        batch_size, mode=ModeKeys.PREDICT)
  batch_size = model._validate_or_infer_batch_size(batch_size, steps, x)
  dataset = model._distribution_standardize_user_data(
      x,
      batch_size=batch_size,
      repeat=False,
      allow_partial_batch=True)
  if distributed_training_utils.is_tpu_strategy(model._distribution_strategy):
    return experimental_tpu_predict_loop(
        model, dataset, verbose=verbose, steps=steps, callbacks=callbacks)
  else:
    return training_arrays.predict_loop(
        model,
        dataset,
        batch_size=batch_size,
        verbose=verbose,
        steps=steps,
        callbacks=callbacks)
Exemplo n.º 6
0
 def predict(self,
             model,
             x,
             batch_size=None,
             verbose=0,
             steps=None,
             callbacks=None,
             **kwargs):
     """Predict loop for Distribution Strategies."""
     dist_utils.validate_inputs(x=x, y=None)
     batch_size, steps = self._process_batch_and_step_size(
         model, x, batch_size, steps, ModeKeys.PREDICT)
     batch_size = model._validate_or_infer_batch_size(batch_size, steps, x)
     dataset = model._distribution_standardize_user_data(
         x, batch_size=batch_size, allow_partial_batch=True)
     if dist_utils.is_tpu_strategy(model._distribution_strategy):
         return experimental_tpu_predict_loop(model,
                                              dataset,
                                              verbose=verbose,
                                              steps=steps,
                                              callbacks=callbacks)
     else:
         return training_arrays.predict_loop(model,
                                             dataset,
                                             batch_size=batch_size,
                                             verbose=verbose,
                                             steps=steps,
                                             callbacks=callbacks)