Tensorflow:Cifar-10模型中的输出节点名称是什么? [英] Tensorflow: What is the output node name in Cifar-10 model?

查看:302
本文介绍了Tensorflow:Cifar-10模型中的输出节点名称是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解Tensorflow,并且看到了一个官方示例Cifar-10模型.

I'm trying to understand Tensorflow and I'm seeing one of the official examples, the Cifar-10 model.

cifar10.py 中,在inference()中,您可以看到以下几行:

In cifar10.py, in inference(), you can see the following lines:

with tf.variable_scope('softmax_linear') as scope:
    weights = _variable_with_weight_decay('weights', [192, NUM_CLASSES],
                                      stddev=1/192.0, wd=0.0)
    biases = _variable_on_cpu('biases', [NUM_CLASSES],
                          tf.constant_initializer(0.0))
    softmax_linear = tf.add(tf.matmul(local4, weights), biases, name=scope.name)
    _activation_summary(softmax_linear)

scope.name应该是softmax_linear,并且应该是节点的名称.我用以下几行(与教程不同)保存了图形原型:

scope.name should be softmax_linear, and that should be the node's name. I saved the graph proto with the following lines (it differs from the tutorial):

with tf.Graph().as_default():
    global_step = tf.Variable(0, trainable=False)

    # Get images and labels
    images, labels = cifar10.distorted_inputs()


    # Build a Graph that computes the logits predictions from the
    # inference model.
    logits = cifar10.inference(images)

    # Calculate loss.
    loss = cifar10.loss(logits, labels)

    # Build a Graph that trains the model with one batch of examples and
    # updates the model parameters.
    train_op = cifar10.train(loss, global_step)

    # Create a saver.
    saver = tf.train.Saver(tf.global_variables())

    # Build the summary operation based on the TF collection of Summaries.
    summary_op = tf.summary.merge_all()

    # Build an initialization operation to run below.
    init = tf.global_variables_initializer()

    # Start running operations on the Graph.
    sess = tf.Session(config=tf.ConfigProto(
        log_device_placement=FLAGS.log_device_placement))
    sess.run(init)

    # save the graph
    tf.train.write_graph(sess.graph_def, FLAGS.train_dir, 'model.pbtxt')  

    ....

但是在model.pbtxt中看不到名为softmax_linear的节点.我究竟做错了什么?我只想要输出节点的名称来导出图形.

But I can't see a node called softmax_linear in model.pbtxt. What am I doing wrong? I just want the name of the output node to export the graph.

推荐答案

运算符名称将不是"softmax_linear". tf.name_scope()在运算符的名称之前加上其名称,并用/分隔.每个运算符都有其自己的名称.例如,如果您写

The operator name won't be "softmax_linear". The tf.name_scope() prefixes names of operators with its name, separated by a /. Each operator has its own name. For example, if you write

with tf.name_scope("foo"):
   a = tf.constant(1, name="bar")

然后常量将被命名为"foo/bar".

希望有帮助!

这篇关于Tensorflow:Cifar-10模型中的输出节点名称是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆