2016-09-28 110 views
0

我開始使用張貼的教程開始使用TensorFlow。tf.contrib.learn快速入門:修正float64警告

我有在Fedora 23(二十三)上運行的Linux CPU python2.7版本0.10.0。

我想按照下面的代碼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_with_header()'替換'load_csv()'會產生正確的預測。但float64警告仍然存在。

我試着爲training_set,test_set和new_samples明確列出dtype(np.int32; np.float32; tf.int32; tf.float32)。

我也試過「鑄造」 feature_columns爲:

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

與float64已知發展問題的問題,但我不知道是否有一些解決方法嗎?

回答

0

我通過Git-hub從開發團隊處收到答覆。

嗨@qweelar,float64警告是由於load_csv_with_header函數在提交b6813bd中已修復的錯誤。此修復程序不在TensorFlow發行版0.10中,但應在下一個發行版中。

與此同時,出於tf.contrib.learn快速入門的目的,您可以安全地忽略float64警告。

(旁註:在其他棄用警告而言,我將更新教程代碼中使用load_csv_with_header,和當那是在地方會更新這個問題。)