Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Tensorflow 还原模型未初始化(初始V3/转移学习)_Tensorflow - Fatal编程技术网

Tensorflow 还原模型未初始化(初始V3/转移学习)

Tensorflow 还原模型未初始化(初始V3/转移学习),tensorflow,Tensorflow,我使用的是Inception 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_de

我使用的是Inception 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"]()]]

因此,我猜我的还原过程中有些不对劲…

因为您正在使用
self.logits,self.end\u points=inception.inception\u v3
创建图,默认图已经包含该图的所有变量

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

将`saver=tf.train.import_meta_图形(meta_路径)`替换为`saver=tf.train.saver()`将有效。thx!想知道答案吗?当然!我会把它作为答案贴出来。