2017-04-17 25 views
0

我只是想加載我以前保存的模型,並進一步訓練,我的代碼工作得很好,直到恢復步驟,當我使用'sess.run'時,事情變得很奇怪。程序立即結束,不執行'sess.run'。奇怪的事情發生時,我在Tensorflow中恢復我的模型

但是,當我刪除了我的AdamOptimizer運,「SESS,運行」回來上班

爲什麼?

下面是代碼:

ckpt_state = tf.train.get_checkpoint_state(last_checkpoint_path) 
if not ckpt_state or not ckpt_state.model_checkpoint_path: 
    print('No check point files are found!') 
    return 


ckpt_files = ckpt_state.all_model_checkpoint_paths 
num_ckpt = len(ckpt_files) 

if num_ckpt < 1: 
    print('No check point files are found!') 
    return 

low_res_holder = tf.placeholder(tf.float32, shape=[BATCH_SIZE, INPUT_SIZE, INPUT_SIZE, NUM_CHENNELS]) 
high_res_holder = tf.placeholder(tf.float32, shape=[BATCH_SIZE, LABEL_SIZE, LABEL_SIZE, NUM_CHENNELS]) 

keep_prob = tf.placeholder(tf.float32) 
is_training = tf.placeholder("bool", shape=[]) 

global_step = tf.Variable(0, trainable=False, name='global_step') 

inferences = models.creat_Dense_Modelpatches(low_res_holder, 13, is_training, keep_prob) 
training_loss = models.loss(inferences, high_res_holder, name='training_loss') 

low_res_batches, high_res_batches = batch_queue_for_testing(TESTING_DATA_PATH) 

learning_rate = tf.train.inverse_time_decay(0.001, global_step, 10000, 2) 

train_step = tf.train.AdamOptimizer(learning_rate).minimize(training_loss, global_step=global_step) 

config = tf.ConfigProto() 
config.gpu_options.allow_growth = True 

sess = tf.Session(config=config) 
sess.run(tf.global_variables_initializer()) 
tf.train.start_queue_runners(sess=sess) 

saver = tf.train.Saver(tf.global_variables()) 

ckpt_file = ckpt_files[-1] 

saver.restore(sess, ckpt_file) 

low_res_images, high_res_images = sess.run([low_res_batches, high_res_batches]) 

print("thie code has ran this line...") 

當我跑這個代碼與

train_step = tf.train.AdamOptimizer(learning_rate).minimize(training_loss, global_step=global_step) 

輸出將是

I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1080, pci bus id: 0000:05:00.0) 
[email protected]:~/JP/DR/DR$ 

但當train_step運算除去輸出將是像這樣:

I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1080, pci bus id: 0000:05:00.0) 
thie code has ran this line... 
[email protected]:~/JP/DR/DR$ 

回答

0

您可能需要加入用於異步執行的所有線程。下面是從(https://www.tensorflow.org/programmers_guide/reading_data

with tf.Session() as sess: 
    # Start populating the filename queue. 
    coord = tf.train.Coordinator() 
    threads = tf.train.start_queue_runners(coord=coord) 

    for i in range(1200): 
    # Retrieve a single instance: 
    example, label = sess.run([features, col5]) 

    coord.request_stop() # <==== You are missing this 
    coord.join(threads)  # <==== And this 

如果不能解決您的問題,這將有助於提供一個最小的工作的例子,我可以在本地調試的例子片斷。

相關問題