python - Tensorflow:Cifar-10 模型中的输出节点名称是什么?

标签 python machine-learning tensorflow neural-network

我正在尝试了解 Tensorflow,并且看到了官方示例之一,即 Cifar-10 模型。

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

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,并且应该是节点的名称。我用以下几行保存了图形原型(prototype)(它与教程不同):

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 的节点。我究竟做错了什么?我只想要输出节点的名称来导出图形。

最佳答案

运算符名称不会是“softmax_linear”tf.name_scope() 在运算符名称前加上其名称作为前缀,并用 / 分隔。每个运算符(operator)都有自己的名称。例如,如果你写

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

那么常量的名称将是“foo/bar”

希望有帮助!

关于python - Tensorflow:Cifar-10 模型中的输出节点名称是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43906093/

相关文章:

python - 使用 elasticsearch-dsl-py 索引和渗透文档

r - R 中的模型学习时间

python - 如何检查数组是否是多维的

matlab - 关于如何解决稀疏 OLS - 如何在 Matlab 中应用 `l1` 最小化(教育目的)

python - 调整 MLPRegressor 超参数

python - 分布式 Tensorflow 重新加载模型失败

python - 在每个训练周期后评估测试集上的模型

tensorflow - Kreas错误TypeError : __init__() missing 1 required positional argument: 'units'

python - 有没有办法计算两个数据框中每个连续点的斜率,存储斜率的所有值然后绘制它?

Python 为初学者读取二进制的 .jpg 文件