2017-05-11 30 views
6

मैंने आपूर्ति किए गए अबालोन उदाहरण को लिया है और सुनिश्चित किया है कि मैंने इसे समझा है .... अच्छा मुझे लगता है कि मैं करता हूं। लेकिन एक अन्य अनुमानक परियोजना के रूप में मैं काम कर रहा हूं, कुल कचरा उत्पादन कर रहा है - मैंने टेंसर बोर्ड जोड़ने की कोशिश की है, इसलिए मैं समझ सकता हूं कि क्या हो रहा है।टेंसरफ़्लो अनुमानक प्रक्रिया में टेंसरबोर्ड जोड़ने के लिए कैसे करें

बेस कोड https://www.tensorflow.org/extend/estimators

मैं एक सत्र और एक लेखक

# Set model params 
    model_params = {"learning_rate": 0.01} 
    with tf.Session() as sess: 
     # Instantiate Estimator 
     nn = tf.contrib.learn.Estimator(model_fn=model_fn, params=model_params) 
     writer = tf.summary.FileWriter ('/tmp/ab_tf' , sess.graph) 
     nn.fit(x=training_set.data, y=training_set.target, steps=5000) 
     # Score accuracy 
     ev = nn.evaluate(x=test_set.data, y=test_set.target, steps=1) 


And added 1 line in the model_fn function so it looks like this... 


def model_fn(features, targets, mode, params): 
    """Model function for Estimator.""" 

    # Connect the first hidden layer to input layer 
    # (features) with relu activation 
    first_hidden_layer = tf.contrib.layers.relu(features, 49) 

    # Connect the second hidden layer to first hidden layer with relu 
    second_hidden_layer = tf.contrib.layers.relu(first_hidden_layer, 49) 

    # Connect the output layer to second hidden layer (no activation fn) 
    output_layer = tf.contrib.layers.linear(second_hidden_layer, 1) 

    # Reshape output layer to 1-dim Tensor to return predictions 
    predictions = tf.reshape(output_layer, [-1]) 
    predictions_dict = {"ages": predictions} 

    # Calculate loss using mean squared error 
    loss = tf.losses.mean_squared_error(targets, predictions) 

    # Calculate root mean squared error as additional eval metric 
    eval_metric_ops = { 
     "rmse": tf.metrics.root_mean_squared_error(
      tf.cast(targets, tf.float64), predictions) 
    } 

    train_op = tf.contrib.layers.optimize_loss(
     loss=loss, 
     global_step=tf.contrib.framework.get_global_step(), 
     learning_rate=params["learning_rate"], 
     optimizer="SGD") 


    tf.summary.scalar('Loss',loss) 

    return model_fn_lib.ModelFnOps(
     mode=mode, 
     predictions=predictions_dict, 
     loss=loss, 
     train_op=train_op, 
     eval_metric_ops=eval_metric_ops) 

अंत में जोड़ा एक

writer.close() 

जब मैं कोड को चलाने ... मैं एक डेटा प्राप्त जोड़ा था है/tmp/ab_tf में फ़ाइल, यह फ़ाइल शून्य नहीं है। लेकिन यह आकार में केवल 13 9 बाइट्स है ... जिसका तात्पर्य है कि कुछ भी लिखा नहीं जा रहा है ....

जब मैं इसे टेंसर बोर्ड के साथ खोलता हूं - वहां कोई डेटा नहीं है।

मैं क्या गलत कर रहा हूं?

किसी भी इनपुट की सराहना ...

उत्तर

0

आप वास्तव में अपने सारांश आपरेशन कॉल और फ़ाइल पर लिखने की जरूरत है। सभी सारांश से एक सारांश आपरेशन है कि आप को परिभाषित किया है बनाने के लिए एक पंक्ति जोड़ें:

merged = tf.summary.merge_all() # easiest way to do it when you have lots of summaries 

और फिर आप जब आप अपने मॉडल को चलाने इस merged सेशन मूल्यांकन करने की जरूरत:

summary, _ = sess.run([merged, nn.train_op], feed_dict=...) 

और अंत में अपने लेखक का उपयोग करके सेशन द्वारा लौटाए गए सारांश डेटा को लिखें:

writer.add_summary(summary, tf.train.get_global_step()) 

मैं सकारात्मक नहीं हूं कि अतिरिक्त कैसे पास किया जाए एल ऑपरेटर nn.fit और nn.evaluate पर, लेकिन ऐसा करने का एक तरीका होना चाहिए। अन्यथा बस कॉल करें:

summary = sess.run(merged, feed_dict=...) 

अलग से और फिर सारांश डेटा लिखें।

2

दरअसल, आपको अनुमानक के लिए सारांश लेखक सेट करने की आवश्यकता नहीं है। सारांश लॉग अनुमानक के model_dir पर लिखा जाएगा।

मान लीजिए कि आकलनकर्ता के लिए अपने model_dir './tmp/model' है आप tensorboard का उपयोग करके सारांश देख सकते हैं करते हैं, --logdir =।/Tmp/मॉडल

+1

आप जो लिखते हैं सही है, मैं कोई समस्या नहीं Tensorboard चल रहा है।मैं आउटपुट में किसी भी चर नहीं देख सकता !! –

3

मैं बिल्कुल वही बात करने के लिए कोशिश कर रहा था जैसे तुम। मैं अंत में पता लगा है कि आप model_dir इस तरह वर्ग निर्माता को पैरामीटर के रूप में उत्तीर्ण होना:

का दृष्टांत अनुमानक

nn = tf.contrib.learn.Estimator (model_fn = model_fn, पैरामीटर = model_params, model_dir = FLAGS.log_dir)

आप इस यहाँ TensorFlow एपीआई में दस्तावेज देख सकते हैं: https://www.tensorflow.org/api_docs/python/tf/contrib/learn/Estimator

+0

सहायता के लिए धन्यवाद, मैं एक एपीआई परत के रूप में केरास का उपयोग करने के लिए चला गया, जो काम करने के लिए बहुत आसान है, और टेंसरबोर्ड जोड़ना भी आसान और काम कर रहा है। –

+0

पहली बार मुझे एहसास हुआ है कि model_dir log_dir जैसा ही है। धन्यवाद! –

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