(self, features, labels, cache=None, is_export_mode=False)
Calls the model_fn with required parameters.
Calls the model_fn with required parameters.
Calls the model_fn with required parameters .
def _call_model_fn(self, features, labels, cache=None, is_export_mode=False):
    """Calls the model_fn with required parameters."""
    self._validate_model_features_and_labels(features, labels, is_export_mode)
    model_fn_args = function_utils.fn_args(self._model_fn)
    kwargs = {}

    # Makes deep copy with `config` and params` in case user mutates them.
    config = copy.deepcopy(self._config)
    params = copy.deepcopy(self._params)

    if 'labels' in model_fn_args:
      kwargs['labels'] = labels
    elif labels is not None:
      raise ValueError(
          'model_fn does not take labels, but input_fn returns labels.')
    if 'mode' in model_fn_args:
      kwargs['mode'] = self._ctx.mode
    if 'config' in model_fn_args:
      kwargs['config'] = config
    if 'params' in model_fn_args:
      kwargs['params'] = params

    if cache is not None:
      params['cache'] = cache

    if 'params' not in model_fn_args:
      raise ValueError('model_fn ({}) does not include params argument, '
                       'required by TPUEstimator to pass batch size as '
                       'params[\'batch_size\']'.format(self._model_fn))

    if is_export_mode:
      batch_size_for_model_fn = None
    else:
      batch_size_for_model_fn = self._ctx.batch_size_for_model_fn

    if batch_size_for_model_fn is not None:
      _add_item_to_params(params, _BATCH_SIZE_KEY, batch_size_for_model_fn)

    running_on_cpu = self._ctx.is_running_on_cpu(is_export_mode)
    _add_item_to_params(params, _USE_TPU_KEY, not running_on_cpu)

    if not running_on_cpu:
      user_context = tpu_context.TPUContext(
          internal_ctx=self._ctx, call_from_input_fn=False)
      _add_item_to_params(params, _CTX_KEY, user_context)

    estimator_spec = self._model_fn(features=features, **kwargs)
    if (running_on_cpu and
        isinstance(estimator_spec, model_fn_lib._TPUEstimatorSpec)):  # pylint: disable=protected-access
      # The estimator_spec will be passed to `Estimator` directly, which expects
      # type `EstimatorSpec`.
      return estimator_spec.as_estimator_spec()
    else:
      return estimator_spec
def _call_model_fn ( self , features , labels , cache = None , is_export_mode = False ) : self . _validate_model_features_and_labels ( features , labels , is_export_mode ) model_fn_args = function_utils . fn_args ( self . _model_fn ) kwargs = { } # Makes deep copy with `config` and params` in case user mutates them. config = copy . deepcopy ( self . _config ) params = copy . deepcopy ( self . _params ) if 'labels' in model_fn_args : kwargs [ 'labels' ] = labels elif labels is not None : raise ValueError ( 'model_fn does not take labels, but input_fn returns labels.' ) if 'mode' in model_fn_args : kwargs [ 'mode' ] = self . _ctx . mode if 'config' in model_fn_args : kwargs [ 'config' ] = config if 'params' in model_fn_args : kwargs [ 'params' ] = params if cache is not None : params [ 'cache' ] = cache if 'params' not in model_fn_args : raise ValueError ( 'model_fn ({}) does not include params argument, ' 'required by TPUEstimator to pass batch size as ' 'params[\'batch_size\']' . format ( self . _model_fn ) ) if is_export_mode : batch_size_for_model_fn = None else : batch_size_for_model_fn = self . _ctx . batch_size_for_model_fn if batch_size_for_model_fn is not None : _add_item_to_params ( params , _BATCH_SIZE_KEY , batch_size_for_model_fn ) running_on_cpu = self . _ctx . is_running_on_cpu ( is_export_mode ) _add_item_to_params ( params , _USE_TPU_KEY , not running_on_cpu ) if not running_on_cpu : user_context = tpu_context . TPUContext ( internal_ctx = self . _ctx , call_from_input_fn = False ) _add_item_to_params ( params , _CTX_KEY , user_context ) estimator_spec = self . _model_fn ( features = features , * * kwargs ) if ( running_on_cpu and isinstance ( estimator_spec , model_fn_lib . _TPUEstimatorSpec ) ) : # pylint: disable=protected-access # The estimator_spec will be passed to `Estimator` directly, which expects # type `EstimatorSpec`. return estimator_spec . as_estimator_spec ( ) else : return estimator_spec