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

Class Transformer

tensorflow/contrib/graph_editor/transform.py:372–588  ·  view source on GitHub ↗

Transform a subgraph into another one. By default, the constructor create a transform which copy a subgraph and replaces inputs with placeholders. This behavior can be modified by changing the handlers.

Source from the content-addressed store, hash-verified

370
371
372class Transformer(object):
373 """Transform a subgraph into another one.
374
375 By default, the constructor create a transform which copy a subgraph and
376 replaces inputs with placeholders. This behavior can be modified by changing
377 the handlers.
378 """
379
380 def __init__(self):
381 """Transformer constructor.
382
383 The following members can be modified:
384 transform_op_handler: handle the transformation of a `tf.Operation`.
385 This handler defaults to a simple copy.
386 assign_collections_handler: handle the assignment of collections.
387 This handler defaults to assigning new collections created under the
388 given name-scope.
389 transform_external_input_handler: handle the transform of the inputs to
390 the given subgraph. This handler defaults to creating placeholders
391 instead of the ops just before the input tensors of the subgraph.
392 transform_external_hidden_input_handler: handle the transform of the
393 hidden inputs of the subgraph, that is, the inputs which are not listed
394 in sgv.inputs. This handler defaults to a transform which keep the same
395 input if the source and destination graphs are the same, otherwise
396 use placeholders.
397 transform_original_op_handler: handle the transform of original_op. This
398 handler defaults to transforming original_op only if they are in the
399 subgraph, otherwise they are ignored.
400 """
401
402 # handlers
403 self.transform_op_handler = copy_op_handler
404 self.transform_control_input_handler = transform_op_if_inside_handler
405 self.assign_collections_handler = assign_renamed_collections_handler
406 self.transform_external_input_handler = replace_t_with_placeholder_handler
407 self.transform_external_hidden_input_handler = keep_t_if_possible_handler
408 self.transform_original_op_handler = transform_op_if_inside_handler
409
410 def __call__(self,
411 sgv,
412 dst_graph,
413 dst_scope,
414 src_scope="",
415 reuse_dst_scope=False):
416 """Execute the transformation.
417
418 Args:
419 sgv: the source subgraph-view.
420 dst_graph: the destination graph.
421 dst_scope: the destination scope.
422 src_scope: the source scope, which specify the path from which the
423 relative path of the transformed nodes are computed. For instance, if
424 src_scope is a/ and dst_scoped is b/, then the node a/x/y will have a
425 relative path of x/y and will be transformed into b/x/y.
426 reuse_dst_scope: if True the dst_scope is re-used if it already exists.
427 Otherwise, the scope is given a unique name based on the one given
428 by appending an underscore followed by a digit (default).
429 Returns:

Callers 2

copyFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected