2016-07-17 16 views
7

मैं beginner's tutorial के समान तरीके से टेन्सफोर्लो (संस्करण 0.9.0) का उपयोग करके एक साधारण बाइनरी लॉजिस्टिक रेग्रेशन क्लासिफायर को प्रशिक्षित करने की कोशिश कर रहा हूं और सामना कर रहा हूं निम्न त्रुटि जब मॉडल फिटिंग:टेन्सफोर्लो त्रुटि: "टेंसर टेंसर के समान ग्राफ से होना चाहिए ..."

import tempfile 
import tensorflow as tf 
import pandas as pd 

# Customized training data parsing 
train_data = read_train_data() 
feature_names = get_feature_names(train_data) 
labels = get_labels(train_data) 

# Construct dataframe from training data features 
x_train = pd.DataFrame(train_data , columns=feature_names) 
x_train["label"] = labels 

y_train = tf.constant(labels) 

# Create SparseColumn for each feature (assume all feature values are integers and either 0 or 1) 
feature_cols = [ tf.contrib.layers.sparse_column_with_integerized_feature(f,2) for f in feature_names ] 

# Create SparseTensor for each feature based on data 
categorical_cols = { f: tf.SparseTensor(indices=[[i,0] for i in range(x_train[f].size)], 
       values=x_train[f].values, 
       shape=[x_train[f].size,1]) for f in feature_names } 

# Initialize logistic regression model 
model_dir = tempfile.mkdtemp() 
model = tf.contrib.learn.LinearClassifier(feature_columns=feature_cols, model_dir=model_dir) 

def eval_input_fun(): 
    return categorical_cols, y_train 

# Fit the model - similarly to the tutorial 
model.fit(input_fn=eval_input_fun, steps=200) 

मुझे लगता है कि मैं कुछ महत्वपूर्ण ... शायद कुछ है कि ट्यूटोरियल में मान लिया गया था लेकिन wasn 'याद कर रहा हूँ:

ValueError: Tensor("centered_bias_weight:0", shape=(1,), dtype=float32_ref) must be from the same graph as Tensor("linear_14/BiasAdd:0", shape=(?, 1), dtype=float32). 

यहाँ मेरी कोड है टी स्पष्ट रूप से उल्लेख किया?

इसके अलावा, मैं हर बार जब मैं फिट (कॉल) चेतावनी निम्नलिखित मिलती है:

WARNING:tensorflow:create_partitioned_variables is deprecated. Use tf.get_variable with a partitioner set, or tf.get_partitioned_variable_list, instead. 
+0

आप उल्लेख करें कि आप 0.9 का उपयोग कर रहे हैं, लेकिन ट्यूटोरियल आप लिंक गुरु से है अंदर सभी ऑप्स परिभाषाओं (और उनके निर्भरता) चलते हैं। क्या यह संभव है कि परिवर्तन हुए? आप यहां ट्यूटोरियल के 0.9 संस्करण की जांच कर सकते हैं: https://www.tensorflow.org/versions/r0.9/tutorials/wide/index.html –

उत्तर

5

जब आप निष्पादित model.fit, LinearClassifiercreating a separate tf.Graph ऑप्स अपने eval_input_fun समारोह में निहित पर आधारित है। लेकिन, इस ग्राफ के निर्माण के दौरान, लीनियर क्लासिफायर को categorical_cols और y_train की परिभाषाओं तक पहुंच नहीं है जो आपने वैश्विक रूप से सहेजा है।

समाधान: eval_input_fun

+0

दुर्भाग्य से स्रोत का लिंक टूटा हुआ है –

संबंधित मुद्दे