【问题标题】:How to compute accuracy of CNN in TensorFlow如何在 TensorFlow 中计算 CNN 的准确度
【发布时间】:2017-07-25 06:40:51
【问题描述】:

我是 TensorFlow 新手。我正在用自己的数据集进行二进制分类。但是我不知道如何计算准确性。谁能帮我做这件事?

我的分类器有 5 个卷积层,后跟 2 个全连接层。最后一个 FC 层的输出维度为 2,我使用过:

prob = tf.nn.softmax(classification_features, name="output")

【问题讨论】:

  • 您能否更具体地说明您的分类器的外观?
  • 我的分类器有 5 个卷积层,后跟 2 个全连接层。最后一个 FC 层的输出维度为 2,我使用了 prob = tf.nn.softmax(classification_features, name="output")
  • 太棒了。谢谢你:)

标签: tensorflow classification convolution


【解决方案1】:

只计算正确预测的百分比:

prediction = tf.math.argmax(prob, axis=1)
equality = tf.math.equal(prediction, correct_answer)
accuracy = tf.math.reduce_mean(tf.cast(equality, tf.float32))

【讨论】:

    【解决方案2】:

    Tensorflow 中的 Keras 更新 2020-11-23

    现在您可以在model.compilemetrics 参数中指定您想要的。

    这篇文章来自 3.6 年前,当时 tensorflow 还处于第 1 版。现在 Tensorflow.org 建议使用 Keras 调用,您可以像这样指定您想要的准确性:

    model.compile(loss='mse',optimizer='sgd',metrics=['accuracy'])
    model.fit(x,y)
    

    轰!当您运行“model.fit”时,您的报告就会准确无误。

    如果您使用的是旧版本的 tensorflow 或只是从头开始编写,@Androbin 解释得很好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-03
      • 1970-01-01
      • 1970-01-01
      • 2013-11-20
      • 2023-03-16
      • 1970-01-01
      • 2018-06-15
      相关资源
      最近更新 更多