當前位置: 首頁>>代碼示例>>Python>>正文


Python graph_editor.get_backward_walk_ops方法代碼示例

本文整理匯總了Python中tensorflow.contrib.graph_editor.get_backward_walk_ops方法的典型用法代碼示例。如果您正苦於以下問題:Python graph_editor.get_backward_walk_ops方法的具體用法?Python graph_editor.get_backward_walk_ops怎麽用?Python graph_editor.get_backward_walk_ops使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tensorflow.contrib.graph_editor的用法示例。


在下文中一共展示了graph_editor.get_backward_walk_ops方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: dependency_of_targets

# 需要導入模塊: from tensorflow.contrib import graph_editor [as 別名]
# 或者: from tensorflow.contrib.graph_editor import get_backward_walk_ops [as 別名]
def dependency_of_targets(targets, op):
    """
    Check that op is in the subgraph induced by the dependencies of targets.
    The result is memoized.

    This is useful if some SessionRunHooks should be run only together with certain ops.

    Args:
        targets: a tuple of ops or tensors. The targets to find dependencies of.
        op (tf.Operation or tf.Tensor):

    Returns:
        bool
    """
    # TODO tensorarray? sparsetensor?
    if isinstance(op, tf.Tensor):
        op = op.op
    assert isinstance(op, tf.Operation), op

    from tensorflow.contrib.graph_editor import get_backward_walk_ops
    # alternative implementation can use graph_util.extract_sub_graph
    dependent_ops = get_backward_walk_ops(targets, control_inputs=True)
    return op in dependent_ops 
開發者ID:microsoft,項目名稱:petridishnn,代碼行數:25,代碼來源:dependency.py

示例2: fast_backward_ops

# 需要導入模塊: from tensorflow.contrib import graph_editor [as 別名]
# 或者: from tensorflow.contrib.graph_editor import get_backward_walk_ops [as 別名]
def fast_backward_ops(within_ops, seed_ops, stop_at_ts):
    bwd_ops = set(ge.get_backward_walk_ops(seed_ops, stop_at_ts=stop_at_ts))
    ops = bwd_ops.intersection(within_ops).difference(
        [t.op for t in stop_at_ts])
    return list(ops) 
開發者ID:openai,項目名稱:glow,代碼行數:7,代碼來源:memory_saving_gradients.py

示例3: fast_backward_ops

# 需要導入模塊: from tensorflow.contrib import graph_editor [as 別名]
# 或者: from tensorflow.contrib.graph_editor import get_backward_walk_ops [as 別名]
def fast_backward_ops(within_ops, seed_ops, stop_at_ts):
    bwd_ops = set(ge.get_backward_walk_ops(seed_ops, stop_at_ts=stop_at_ts))
    ops = bwd_ops.intersection(within_ops).difference([t.op for t in stop_at_ts])
    return list(ops) 
開發者ID:cybertronai,項目名稱:gradient-checkpointing,代碼行數:6,代碼來源:memory_saving_gradients.py

示例4: export_subgraph

# 需要導入模塊: from tensorflow.contrib import graph_editor [as 別名]
# 或者: from tensorflow.contrib.graph_editor import get_backward_walk_ops [as 別名]
def export_subgraph(checkpoint, output_tensors, saveto):
    """
    For the current graph, export the subgraph connected to output_tensors to a new graph_def file
    :param checkpoint: path to checkpoint
    :param output_tensors: output tensor names
    :param saveto: path to save graph_def file to
    :return:
    """
    saver = tf.train.import_meta_graph(checkpoint + '.meta', clear_devices=True)
    graph = tf.get_default_graph()
    if isinstance(output_tensors, str):
        output_tensors = [graph.get_tensor_by_name(output_tensors)]
    else:
        assert all([isinstance(out, str) for out in output_tensors])
        output_tensors = [graph.get_tensor_by_name(out) for out in output_tensors]

    def _var_ops(var_op):  # get operations one step ahead of variable ops: read/assign/etc.
        return [var_op.name] + [op.name for t in var_op.outputs for op in t.consumers()]

    keep_op_names = [out.op.name for out in output_tensors]
    var_ops = list({op for out in output_tensors for op in ge.get_backward_walk_ops(out) if op.type == 'VariableV2'})
    keep_op_names += [opname for op in var_ops for opname in _var_ops(op)]
    keep_op_names = [opname for opname in keep_op_names if 'save/' not in opname and 'save_' not in opname]
    graph_def = tf.graph_util.extract_sub_graph(graph.as_graph_def(), keep_op_names)

    with tf.Session() as sess:
        saver.restore(sess, checkpoint)
        new_graph_def = tf.graph_util.convert_variables_to_constants(
            sess, graph_def, [out.op.name for out in output_tensors])
    tf.reset_default_graph()
    tf.train.export_meta_graph(saveto, graph_def=new_graph_def, clear_devices=True) 
開發者ID:gruberto,項目名稱:Gated2Depth,代碼行數:33,代碼來源:export.py

示例5: create_session

# 需要導入模塊: from tensorflow.contrib import graph_editor [as 別名]
# 或者: from tensorflow.contrib.graph_editor import get_backward_walk_ops [as 別名]
def create_session(self):
        sess = tf.Session(target=self.target, config=self.config)

        def blocking_op(x):
            """
            Whether an op is possibly blocking.
            """
            if x.op_def is not None and not x.op_def.is_stateful:
                return False
            if "Dequeue" in x.type or "Enqueue" in x.type:
                return True
            if "Unstage" in x.type:
                return True
            if x.type in ["ZMQPull"]:
                return True
            return False

        def run(op):
            if not is_tfv2():
                from tensorflow.contrib.graph_editor import get_backward_walk_ops

                deps = get_backward_walk_ops(op, control_inputs=True)
                for dep_op in deps:
                    if blocking_op(dep_op):
                        logger.warn(
                            "Initializer '{}' depends on a blocking op '{}'. "
                            "This initializer is likely to hang!".format(
                                op.name, dep_op.name))
            sess.run(op)

        run(tf.global_variables_initializer())
        run(tf.local_variables_initializer())
        run(tf.tables_initializer())
        return sess 
開發者ID:microsoft,項目名稱:petridishnn,代碼行數:36,代碼來源:sesscreate.py


注:本文中的tensorflow.contrib.graph_editor.get_backward_walk_ops方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。