List of tensor names in graph in Tensorflow

后端 未结 6 1129
死守一世寂寞
死守一世寂寞 2020-11-28 21:04

The graph object in Tensorflow has a method called \"get_tensor_by_name(name)\". Is there anyway to get a list of valid tensor names?

If not, does anyone know the va

6条回答
  •  执念已碎
    2020-11-28 21:18

    As a nested list comprehension:

    tensor_names = [t.name for op in tf.get_default_graph().get_operations() for t in op.values()]
    

    Function to get names of Tensors in a graph (defaults to default graph):

    def get_names(graph=tf.get_default_graph()):
        return [t.name for op in graph.get_operations() for t in op.values()]
    

    Function to get Tensors in a graph (defaults to default graph):

    def get_tensors(graph=tf.get_default_graph()):
        return [t for op in graph.get_operations() for t in op.values()]
    

提交回复
热议问题