2017-06-02 12 views
1

コードを実行すると、エラープロンプトが表示されずにimage_batch, label_batch = sess.run([test_images, test_labels])という行にとどまります。それはここにとどまり、移動することはできません。1行でフリーズするPythonプログラムをデバッグする方法は?

はここに私のコードです:

# coding=utf-8 
from color_1 import read_and_decode, get_batch, get_test_batch 
import color_inference 
import cv2 
import os 
import time 
import numpy as np 
import tensorflow as tf 
import color_train 
import math 

batch_size=128 
num_examples = 10000 
crop_size=56 

def evaluate(): 
    image_holder = tf.placeholder(tf.float32, [batch_size, 56, 56, 3], name='x-input') 
    label_holder = tf.placeholder(tf.int32, [batch_size], name='y-input') 

    test_image, test_label = read_and_decode('val.tfrecords') 
    test_images, test_labels = get_test_batch(test_image, test_label, batch_size, crop_size) 
    y=color_inference.inference(image_holder) 

    num_iter = int(math.ceil(num_examples/batch_size)) 
    true_count = 0 
    total_sample_count = num_iter * batch_size 

    top_k_op = tf.nn.in_top_k(y, label_holder, 1) 
    saver = tf.train.Saver() 
    with tf.Session() as sess: 

     ckpt=tf.train.get_checkpoint_state(color_train.MODEL_SAVE_PATH) 
     if ckpt and ckpt.model_checkpoint_path: 
      ckpt_name = os.path.basename(ckpt.model_checkpoint_path) 
      global_step = ckpt.model_checkpoint_path.split('/')[-1].split('-')[-1] 
      saver.restore(sess, os.path.join(color_train.MODEL_SAVE_PATH, ckpt_name)) 
      print('Loading success, global_step is %s' % global_step) 

      image_batch, label_batch = sess.run([test_images, test_labels]) 
      predictions = sess.run([top_k_op], feed_dict={image_holder: image_batch, 
                  label_holder: label_batch}) 
      true_count += np.sum(predictions) 
      print("Count is:%g" % true_count) 
      precision = true_count * 1.0/total_sample_count 
      print("After %s training step,the prediction is :%g",global_step,precision) 
     else: 
      print('No checkpoint file found') 
      return 

def main(argv=None): 
    evaluate() 

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

私の最後の質問は、これと似ていますが、コードはこれと異なるごみで、多分あなたは最後の質問で何かを得ることができます。

答えて

0

あなたはキューランナーを起動していないか、変数を適切に初期化しているようです。私はそれを忘れたとき私のモデルと同様の動作を見てきました。 これはtfrecordsからデータをプルスレッドが開始されていないので、あなたが最も可能性の高いライン

image_batch, label_batch = sess.run([test_images, test_labels]) 

で動けなくなる場合があります。

あなたのセッションセットアップは、変数とスレッドコーディネーターを初期化するためのOPを初期化する前に、次のセッションの非常に開始時に、その後

init_op = tf.group(tf.global_variables_initializer(), tf.local_variables_initializer()) 
coord = tf.train.Coordinator() 

を、tfrecordsから任意のデータを引っ張って前にオペアンプを実行し、キューランナーを開始してください:

sess.run(init_op) 
threads = tf.train.start_queue_runners(sess=sess, coord=coord) 
# main loop goes here, like training and evaluating 
+0

ありがとうございました。私のもう一つの質問で助けてもらえますか?質問名は "Fetch argument はテンソルとして解釈できません。あなたの助けが必要です!どうもありがとうございました –

関連する問題