【问题标题】:tf.contrib.learn Quickstart: Fix float64 Warningtf.contrib.learn 快速入门:修复 float64 警告
【发布时间】:2016-09-28 21:04:41
【问题描述】:

我通过阅读发布的教程开始使用 TensorFlow。

我的 Linux CPU python2.7 版本 0.10.0 在 Fedora 23(23)上运行。

我正在按照以下代码尝试 tf.contrib.learn 快速入门教程。

https://www.tensorflow.org/versions/r0.10/tutorials/tflearn/index.html#tf-contrib-learn-quickstart

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import tensorflow as tf
import numpy as np

# Data sets
IRIS_TRAINING = "IRIS_data/iris_training.csv"
IRIS_TEST = "IRIS_data/iris_test.csv"

# Load datasets.
training_set = tf.contrib.learn.datasets.base.load_csv(filename=IRIS_TRAINING,
                                                   target_dtype=np.int)
test_set = tf.contrib.learn.datasets.base.load_csv(filename=IRIS_TEST,
                                               target_dtype=np.int)

# Specify that all features have real-value data
feature_columns = [tf.contrib.layers.real_valued_column("", dimension=4)]

# Build 3 layer DNN with 10, 20, 10 units respectively.
classifier = tf.contrib.learn.DNNClassifier(feature_columns=feature_columns,
                                        hidden_units=[10, 20, 10],
                                        n_classes=3,
                                        model_dir="/tmp/iris_model")

# Fit model.
classifier.fit(x=training_set.data, 
           y=training_set.target, 
           steps=2000)

# Evaluate accuracy.
accuracy_score = classifier.evaluate(x=test_set.data,
                                 y=test_set.target)["accuracy"]
print('Accuracy: {0:f}'.format(accuracy_score))

# Classify two new flower samples.
new_samples = np.array(
[[6.4, 3.2, 4.5, 1.5], [5.8, 3.1, 5.0, 1.7]], dtype=float)
y = classifier.predict(new_samples)
print('Predictions: {}'.format(str(y)))

代码执行,但给出 float64 警告。像这样:

$ python confErr.py
WARNING:tensorflow:load_csv (from tensorflow.contrib.learn.python.learn.datasets.base) is deprecated and will be removed after 2016-09-15.
Instructions for updating:
Please use load_csv_{with|without}_header instead.
WARNING:tensorflow:load_csv (from tensorflow.contrib.learn.python.learn.datasets.base) is deprecated and will be removed after 2016-09-15.
Instructions for updating:
Please use load_csv_{with|without}_header instead.
WARNING:tensorflow:Using default config.
WARNING:tensorflow:float64 is not supported by many models, consider casting to float32.
WARNING:tensorflow:Setting feature info to TensorSignature(dtype=tf.float64, shape=TensorShape([Dimension(None), Dimension(4)]), is_sparse=False)
WARNING:tensorflow:Setting targets info to TensorSignature(dtype=tf.int64, shape=TensorShape([Dimension(None)]), is_sparse=False)
WARNING:tensorflow:float64 is not supported by many models, consider casting to float32.
WARNING:tensorflow:Given features: Tensor("input:0", shape=(?, 4), dtype=float64), required signatures: TensorSignature(dtype=tf.float64, shape=TensorShape([Dimension(None), Dimension(4)]), is_sparse=False).
WARNING:tensorflow:Given targets: Tensor("output:0", shape=(?,), dtype=int64), required signatures: TensorSignature(dtype=tf.int64, shape=TensorShape([Dimension(None)]), is_sparse=False).
Accuracy: 0.966667
WARNING:tensorflow:float64 is not supported by many models, consider casting to float32.
Predictions: [1 1]

注意:将 'load_csv()' 替换为 'load_csv_with_header()' 会产生正确的预测。但 float64 警告仍然存在。

我已尝试明确列出 training_set、test_set 和 new_samples 的 dtype (np.int32 ; np.float32; tf.int32; tf.float32)。

我还尝试将 feature_columns 'casting' 为:

feature_columns = tf.cast(feature_columns, tf.float32)

float64 的问题是已知的开发问题,但我想知道是否有一些解决方法?

【问题讨论】:

    标签: python python-2.7 tensorflow


    【解决方案1】:

    我通过 Git-hub 从开发团队收到了这个答案。

    嗨@qweelar,float64 警告是由于在提交 b6813bd 中修复的 load_csv_with_header 函数的错误。此修复不在 TensorFlow 0.10 版中,但应该在下一个版本中。

    同时,出于 tf.contrib.learn 快速入门的目的,您可以放心地忽略 float64 警告。

    (旁注:就其他弃用警告而言,我将更新教程代码以使用 load_csv_with_header,并在到位时更新此问题。)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-02-13
      • 2014-11-12
      • 1970-01-01
      • 1970-01-01
      • 2019-03-09
      • 2012-03-19
      • 1970-01-01
      相关资源
      最近更新 更多