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

Method __init__

tensorflow/python/keras/backend.py:3315–3369  ·  view source on GitHub ↗
(self, inputs, outputs, updates=None, name=None,
               **session_kwargs)

Source from the content-addressed store, hash-verified

3313 """
3314
3315 def __init__(self, inputs, outputs, updates=None, name=None,
3316 **session_kwargs):
3317 updates = updates or []
3318 if not isinstance(updates, (list, tuple)):
3319 raise TypeError('`updates` in a Keras backend function '
3320 'should be a list or tuple.')
3321
3322 self._inputs_structure = inputs
3323 self.inputs = nest.flatten(inputs, expand_composites=True)
3324 self._outputs_structure = outputs
3325 self.outputs = cast_variables_to_tensor(
3326 nest.flatten(outputs, expand_composites=True))
3327 # TODO(b/127668432): Consider using autograph to generate these
3328 # dependencies in call.
3329 # Index 0 = total loss or model output for `predict`.
3330 with ops.control_dependencies([self.outputs[0]]):
3331 updates_ops = []
3332 for update in updates:
3333 if isinstance(update, tuple):
3334 p, new_p = update
3335 updates_ops.append(state_ops.assign(p, new_p))
3336 else:
3337 # assumed already an op
3338 updates_ops.append(update)
3339 self.updates_op = control_flow_ops.group(*updates_ops)
3340 self.name = name
3341 # additional tensor substitutions
3342 self.feed_dict = session_kwargs.pop('feed_dict', None)
3343 # additional operations
3344 self.fetches = session_kwargs.pop('fetches', [])
3345 if not isinstance(self.fetches, list):
3346 self.fetches = [self.fetches]
3347 self.run_options = session_kwargs.pop('options', None)
3348 self.run_metadata = session_kwargs.pop('run_metadata', None)
3349 # The main use case of `fetches` being passed to a model is the ability
3350 # to run custom updates
3351 # This requires us to wrap fetches in `identity` ops.
3352 self.fetches = [array_ops.identity(x) for x in self.fetches]
3353 self.session_kwargs = session_kwargs
3354 # This mapping keeps track of the function that should receive the
3355 # output from a fetch in `fetches`: { fetch: function(fetch_output) }
3356 # A Callback can use this to register a function with access to the
3357 # output values for a fetch it added.
3358 self.fetch_callbacks = {}
3359
3360 if session_kwargs:
3361 raise ValueError('Some keys in session_kwargs are not supported at this '
3362 'time: %s' % (session_kwargs.keys(),))
3363
3364 self._callable_fn = None
3365 self._feed_arrays = None
3366 self._feed_symbols = None
3367 self._symbol_vals = None
3368 self._fetches = None
3369 self._session = None
3370
3371 def _make_callable(self, feed_arrays, feed_symbols, symbol_vals, session):
3372 """Generates a callable that runs the graph.

Callers

nothing calls this directly

Calls 9

cast_variables_to_tensorFunction · 0.85
flattenMethod · 0.45
control_dependenciesMethod · 0.45
appendMethod · 0.45
assignMethod · 0.45
groupMethod · 0.45
popMethod · 0.45
identityMethod · 0.45
keysMethod · 0.45

Tested by

no test coverage detected