Attempting to use uninitialized value entity_emb_matrix

找了一个tensorflow模型,复现,train的时候没有问题,在把模型保存以后,加载的过程中出现了问题。

完整报错如下:

FailedPreconditionError (see above for traceback): Attempting to use uninitialized value entity_emb_matrix
     [[node entity_emb_matrix/read (defined at D:\指示图谱推荐系统\MKR\MKR-master\MKR-master\src\model.py:62)  = Identity[T=DT_FLOAT, _class=["loc:@embedding_lookup_2"], _device="/job:localhost/replica:0/task:0/device:CPU:0"](entity_emb_matrix)]]

我的错误代码:

    with tf.Session() as sess:
        saver=tf.train.import_meta_graph('model/MKRmodel.ckpt.meta')
        saver.restore(sess,"model/MKRmodel.ckpt")
        result=recomment(sess, model, userid, useridrecord, item_set)
        print(result)

查找各个博客,最有有一个办法解决了我的问题:

在restore后面加两行代码就可以啦!

sess.run(tf.global_variables_initializer())
sess.run(tf.local_variables_initializer())

原文链接:https://www.cnblogs.com/lliuye/p/10501744.html

猜你喜欢

转载自blog.csdn.net/dlz_yhn/article/details/129546758