2017-08-26 90 views
1

我正在使用Inception v3模型並應用了轉移學習。培訓和評估很好。恢復的模型未初始化(初始V3 /轉移學習)

現在我嘗試實際使用(保存的)模型。 我訓練

print("Saving model...") 
saver = tf.train.Saver() 
save_path = saver.save(sess, self.MODEL_SAV_PATH) 
print("...Saved @ ", save_path) 

在剛保存的模型,並嘗試將其與

def load_model(self):  
    tf.reset_default_graph() 
    self.input_shape = tf.placeholder(tf.float32, shape=[None, pipeline.height, pipeline.width, pipeline.channels]) 
    with slim.arg_scope(inception.inception_v3_arg_scope()): 
     self.logits, self.end_points = inception.inception_v3(self.input_shape, num_classes=1001, is_training=False) 

    self.predictions = self.end_points['Predictions'] 

    self.sess = tf.Session() 
    saver = tf.train.import_meta_graph(META_PATH) 
    saver.restore(self.sess, train.latest_checkpoint(CHECKPOINT_PATH)) 

恢復...

,並最終用它

prediction = self.sess.run(self.predictions, feed_dict={self.input_shape: converted_images}).argmax() 

但sess.run會拋出以下錯誤

FailedPreconditionError (see above for traceback): Attempting to use uninitialized value InceptionV3/Conv2d_1a_3x3/weights 
[[Node: InceptionV3/Conv2d_1a_3x3/weights/read = Identity[T=DT_FLOAT, _class=["loc:@InceptionV3/Conv2d_1a_3x3/weights"], _device="/job:localhost/replica:0/task:0/gpu:0"](InceptionV3/Conv2d_1a_3x3/weights)]] 
[[Node: InceptionV3/Predictions/Reshape_1/_795 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/gpu:0", send_device_incarnation=1, tensor_name="edge_2278_InceptionV3/Predictions/Reshape_1", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"]()]] 

,所以我想自己是不是就在我的恢復過程......

+0

用'saver = tf.train.Saver()'替換'saver = tf.train.import_meta_graph(META_PATH)'就行了。 –

+0

thx!想讓它成爲答案嗎? – Marco

+0

當然!將它作爲答案發布。 –

回答

1

因爲要創建使用self.logits, self.end_points = inception.inception_v3,默認的圖形已經持有該圖中所有變量的曲線圖。

# replacing this one 
saver = tf.train.import_meta_graph(META_PATH) 
# with this saver would work 
saver = tf.train.Saver()