【问题标题】:Given checkpoint files, how do I generate the output node name of my model给定检查点文件,如何生成模型的输出节点名称
【发布时间】:2018-02-28 14:32:49
【问题描述】:

我正在使用检查点文件和模型,其中包含未明确命名的输出/张量。

我了解命名的工作原理:

Tensorflow: What is the output node name in Cifar-10 model? && How does TensorFlow name tensors?

但我不确定如何从现有检查点文件生成名称(没有生成 pb,我需要这个才能得到它):

model.ckpt.data-00000-of-00001
model.ckpt.index
model.ckpt.meta

有问题的 CNN 是 fast-neural-style

【问题讨论】:

    标签: tensorflow


    【解决方案1】:

    因此,使用当前模型,我发现在evaluate.py 中,您可以访问恢复的图形并简单地打印以找出名称。

    with g.as_default(), g.device(device_t), \
                tf.Session(config=soft_config) as sess:
            batch_shape = (batch_size,) + img_shape
            img_placeholder = tf.placeholder(tf.float32, shape=batch_shape,
                                             name='img_placeholder')
    
            preds = transform.net(img_placeholder)
            print(preds)
    

    输出:

    Tensor("add_37:0", shape=(1, 720, 884, 3), dtype=float32, device=/device:GPU:0)

    在这种情况下,操作是添加,因此 tensorflow 将其命名为:add_37

    【讨论】:

      【解决方案2】:

      来自KeyError : The tensor variable , Refer to the tensor which does not exists

      这会打印出所有张量名称,您可以尝试找出您需要哪个。

      model_path = "my_model.ckpt"
      
      sess = tf.Session()
      
      saver = tf.train.import_meta_graph(model_path + ".meta")
      saver.restore(sess, model_path)
      graph = tf.get_default_graph()
      
      for op in graph.get_operations():
          print(op.name)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-06
        • 2017-02-23
        • 1970-01-01
        • 2018-09-05
        相关资源
        最近更新 更多