2017-07-14 39 views
0

我使用的例子: https://github.com/tensorflow/tensorflow/blob/r1.2/tensorflow/examples/tutorials/input_fn/boston.pyTensorflow給NaN的直方圖誤差在第一隱藏層

使用完全相同的骨架做一個測試腳本,除了我以前從UCI庫中的數據集: https://archive.ics.uci.edu/ml/datasets/Airfoil+Self-Noise

但是我一直運行到NaN的直方圖錯誤:

InvalidArgumentError (see above for traceback): Nan in summary histogram 
for: dnn/dnn/hiddenlayer_0_activation 
[[Node: dnn/dnn/hiddenlayer_0_activation = HistogramSummary[T=DT_FLOAT, 
_device="/job:localhost/replica:0/task:0/cpu:0"](dnn/dnn 
/hiddenlayer_0_activation/tag, dnn/hiddenlayer_0/hiddenlayer_0/Relu)]] 

這是代碼:

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

import itertools 

import pandas as pd 
import tensorflow as tf 
import numpy 
#import feature_column as fc 

tf.logging.set_verbosity(tf.logging.INFO) 

COLUMNS = ["freq", "angle", "chord", "velocity", "thic", "snd"] 
FEATURES = ["freq", "angle", "chord", "velocity", "thic"] 
LABEL = "snd" 


def input_fn(data_set): 
    feature_cols = {k: tf.constant(data_set[k].values) for k in FEATURES} 
    labels = tf.constant(data_set[LABEL].values) 
    return feature_cols, labels 


def main(unused_argv): 
    # Load datasets 
    training_set = pd.read_csv("C:\\Users\\Aida\\Documents\\Visual Studio 2017\\Projects\\airfoil_train.csv", skipinitialspace=True, 
          skiprows=1, names=COLUMNS) 
    test_set = pd.read_csv("C:\\Users\\Aida\\Documents\\Visual Studio 2017\\Projects\\airfoil_test.csv", skipinitialspace=True, 
         skiprows=1, names=COLUMNS) 

    # prediction set 
    prediction_set = pd.read_csv("C:\\Users\\Aida\\Documents\\Visual Studio 2017\\Projects\\airfoil_predict.csv", skipinitialspace=True, 
           skiprows=1, names=COLUMNS) 

    # Feature cols 
    feature_cols = [tf.contrib.layers.real_valued_column(k) 
        for k in FEATURES] 

    # clip the gradients using gloal norms 
    #list1 = 
    #global_norm1 = tf.global_norm(list1) 
    #clipper = tf.clip_by_global_norm(list1, 1, global_norm1, name=None) 

    # Build 3 layer DNN with dropout 
    regressor = tf.contrib.learn.DNNRegressor(feature_columns=feature_cols, 
              hidden_units=[10, 10], 
              model_dir="/tmp/airfoil_model", 
              optimizer=tf.train.ProximalAdagradOptimizer(learning_rate=0.1, l1_regularization_strength=0.001) 
              ) 

    # Fit 
    regressor.fit(input_fn=lambda: input_fn(training_set), steps=3000) 

    # Score accuracy 
    ev = regressor.evaluate(input_fn=lambda: input_fn(test_set), steps=1) 
    loss_score = ev["loss"] 
    print("Loss: {0:f}".format(loss_score)) 

    # Print out predictions 
    y = regressor.predict_scores(input_fn=lambda: input_fn(prediction_set)) 

    # .predict() returns an iterator; convert to a list and print predictions 
    predictions = list(itertools.islice(y, 10)) 
    print("Predictions: {}".format(str(predictions))) 

if __name__ == "__main__": 
    tf.app.run() 

我試圖改變優化器的學習率,你可以看到,我也試過漸變剪裁,但是這讓我陷入了一個全新的混亂。我甚至使用不同的數據創建了另一個完整的骨架,但它給了我同樣的錯誤。這可能是我對數據集進行格式化的方式,但我幾乎完全遵循了教程格式。 (我可以發佈CSV文件格式的圖像,如果需要的話,我現在沒有足夠的分數來放置多個鏈接)

我試過原始的教程腳本,它工作得很好。我想知道錯誤在說什麼(用通俗的話來說)以及它爲什麼會發生。

編輯:通過刪除CSV文件中的功能名稱行,這是第一行解決了問題,但這仍然涉及如何我不能將 與功能名稱一行而不會導致讀取錯誤。

知識的緣故,我還是想知道爲什麼這可能是發生什麼原來的錯誤意味着

回答

0

你爲什麼要命名的列?如果你需要做一些特別的專欄,你不能只使用索引?

+0

是不是FEATURES列基本上索引文件?根據我的理解,通過對FEATURE列表中的每個唯一名稱進行計數併爲每個元組創建一個元素,可創建名爲「feature cols」的元組。 –