【问题标题】:How to run a convolutional neural network on new data如何在新数据上运行卷积神经网络
【发布时间】:2017-12-10 21:17:25
【问题描述】:

我正在查看 this tutorial 使用 Tensorflow 创建卷积神经网络。

在神经网络构建和训练后,在教程中,它是这样测试的:

eval_results = mnist_classifier.evaluate(
    x=eval_data, y=eval_labels, metrics=metrics)
print(eval_results)

但是,我没有测试集的标签,所以我想只使用训练示例来运行它,如下所示:

eval_results = mnist_classifier.evaluate(x=test_data, metrics=metrics)

但是,如果我这样做,我会收到此警告,然后执行停止:

WARNING:tensorflow:From ../src/script.py:169: calling BaseEstimator.evaluate (from tensorflow.contrib.learn.python.learn.estimators.estimator) with x is deprecated and will be removed after 2016-12-01.
Instructions for updating:
Estimator is decoupled from Scikit Learn interface by moving into
separate class SKCompat. Arguments x, y and batch_size are only
available in the SKCompat class, Estimator will only accept input_fn.
Example conversion:
  est = Estimator(...) -> est = SKCompat(Estimator(...))
Traceback (most recent call last):
  File "../src/script.py", line 172, in <module>
    main()
  File "../src/script.py", line 169, in main
    eval_results = mnist_classifier.evaluate(x=test_data, metrics=metrics)
  File "/opt/conda/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py", line 289, in new_func
    return func(*args, **kwargs)
  File "/opt/conda/lib/python3.6/site-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 530, in evaluate
102.5s
7
    return SKCompat(self).score(x, y, batch_size, steps, metrics)
  File "/opt/conda/lib/python3.6/site-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 1365, in score
    name='score')
  File "/opt/conda/lib/python3.6/site-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 816, in _evaluate_model
    % self._model_dir)
tensorflow.contrib.learn.python.learn.estimators._sklearn.NotFittedError: Couldn't find trained model at /tmp/mnist_convnet_model.

【问题讨论】:

    标签: python tensorflow


    【解决方案1】:

    您可以在没有 y 参数的情况下使用 mnist_classifier.evaluate,因为您没有要评估的内容。

    相反,使用y = mnist_classifier.predict(x=x) 来获取结果,并自己查看它们以了解它们是否正确。

    但是,对网络已经训练过的数据执行此操作是一个非常糟糕的主意,因为它可能会导致无法反映网络如何处理新信息的良好结果。

    除此之外,您收到的警告很正常,因为 xy 参数无论如何都已弃用,但您仍然可以使用它们。如果您想让警告本身消失,则应在导入 tf 后添加 tf.logging.set_verbosity(tf.logging.ERROR)

    编辑:另外,当我想到它时,为什么你有训练集的标签而不是测试集的标签?您应该始终拆分训练数据和标签,以便对其进行大部分训练,但其中一些会完全保留,以便您可以在 evaluate

    中使用它

    【讨论】:

    • 因为我在 Kaggle 上做一个练习,这里没有测试集的标签。
    • 那么我强烈建议将训练数据拆分为 90% 的训练数据和 10% 的未训练数据以在 evaluate 中使用(百分比取决于您实际拥有的数据量)。仅在 predict 中使用该测试数据并解析返回的结果。
    猜你喜欢
    • 1970-01-01
    • 2017-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-20
    • 2020-11-01
    相关资源
    最近更新 更多