MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / __call__

Method __call__

tensorflow/python/keras/backend.py:3438–3488  ·  view source on GitHub ↗
(self, inputs)

Source from the content-addressed store, hash-verified

3436 return tensor
3437
3438 def __call__(self, inputs):
3439 inputs = nest.flatten(inputs, expand_composites=True)
3440
3441 session = get_session(inputs)
3442 feed_arrays = []
3443 array_vals = []
3444 feed_symbols = []
3445 symbol_vals = []
3446 for tensor, value in zip(self.inputs, inputs):
3447 if value is None:
3448 continue
3449
3450 if tensor_util.is_tensor(value):
3451 # Case: feeding symbolic tensor.
3452 feed_symbols.append(tensor)
3453 symbol_vals.append(value)
3454 else:
3455 # Case: feeding Numpy array.
3456 feed_arrays.append(tensor)
3457 # We need to do array conversion and type casting at this level, since
3458 # `callable_fn` only supports exact matches.
3459 tensor_type = dtypes_module.as_dtype(tensor.dtype)
3460 array_vals.append(np.asarray(value,
3461 dtype=tensor_type.as_numpy_dtype))
3462
3463 if self.feed_dict:
3464 for key in sorted(self.feed_dict.keys()):
3465 array_vals.append(
3466 np.asarray(self.feed_dict[key], dtype=key.dtype.base_dtype.name))
3467
3468 # Refresh callable if anything has changed.
3469 if (self._callable_fn is None or feed_arrays != self._feed_arrays or
3470 symbol_vals != self._symbol_vals or
3471 feed_symbols != self._feed_symbols or self.fetches != self._fetches or
3472 session != self._session):
3473 self._make_callable(feed_arrays, feed_symbols, symbol_vals, session)
3474
3475 fetched = self._callable_fn(*array_vals,
3476 run_metadata=self.run_metadata)
3477 self._call_fetch_callbacks(fetched[-len(self._fetches):])
3478 output_structure = nest.pack_sequence_as(
3479 self._outputs_structure,
3480 fetched[:len(self.outputs)],
3481 expand_composites=True)
3482 # We need to evaluate any composite tensor objects that have been
3483 # reconstructed in 'pack_sequence_as', since otherwise they'll be output as
3484 # actual CompositeTensor objects instead of the value(s) contained in the
3485 # CompositeTensors. E.g., if output_structure contains a SparseTensor, then
3486 # this ensures that we return its value as a SparseTensorValue rather than
3487 # a SparseTensor.
3488 return nest.map_structure(self._eval_if_composite, output_structure)
3489
3490
3491class EagerExecutionFunction(object):

Callers

nothing calls this directly

Calls 7

_make_callableMethod · 0.95
_call_fetch_callbacksMethod · 0.95
is_tensorMethod · 0.80
get_sessionFunction · 0.70
flattenMethod · 0.45
appendMethod · 0.45
keysMethod · 0.45

Tested by

no test coverage detected