Tensorflow模型未正确加载(Tensorflow Model is not loading correctly)

编程入门 行业动态 更新时间:2024-10-24 06:31:21
Tensorflow模型未正确加载(Tensorflow Model is not loading correctly)

我目前正在尝试为我的公司培训word2vec模型。 为此,我使用了https://github.com/tensorflow/models上的代码,特别是https://github.com/tensorflow/models/blob/master/tutorials/embedding/word2vec.py 。

我下载了德语维基百科转储并从中提取了文本信息。 任务是使用此数据训练模型。

我在使用Ubuntu 16.04并访问Tesla M60的虚拟机上工作。 在周末,我训练了模型并将检查点保存在一个单独的文件夹中。 在周末结束时,该模型能够回答我给他的36%的评估问题(德语问题类似于例子“questions-word.txt”)。 训练后我想加载模型并再次运行评估任务。 为此,我更改了以下行中的代码(路径更改除外):我添加了

with tf.Graph().as_default(), tf.Session() as session: saver = tf.train.import_meta_graph(opts.save_path + "/model.ckpt-288720426.meta") saver.restore(session, tf.train.latest_checkpoint('./results')) print("Model restored.") with tf.device("/cpu:0"): model = Word2Vec(opts, session) model.read_analogies() # Read analogy questions for _ in xrange(opts.epochs_to_train): #model.train() # Process one epoch model.eval() # Eval analogies.

我添加了两行来加载模型(saver = ...)并注释掉训练线。 查看元和最新检查点文件和tensorboard显示训练有素的模型,但是当我运行代码时,评估结果为0.1%正确答案,在我看来,模型重新启动时未经训练的模型。 我预计结果将再次达到36%

有人能告诉我我在代码中犯的错误,甚至可能在我的想法中吗?

I currently try to train a word2vec model for my company. For this I made use of the code on https://github.com/tensorflow/models, specifically https://github.com/tensorflow/models/blob/master/tutorials/embedding/word2vec.py.

I downloaded the german wikipedia dump and extracted the text information out of it. The task is to train a model with this data.

I work on a virtual Machine that has Ubuntu 16.04 and access to a Tesla M60. For the weekend I trained the model and saved the checkpoints in a seperate folder. At the end of the weekend the model was able to answer 36% of the evaluation questions I gave to him (german questions similar to the example "questions-word.txt"). After training I want to load the model and run the evaluation task again. For this I changed the code in following lines (except for path changes): I added

with tf.Graph().as_default(), tf.Session() as session: saver = tf.train.import_meta_graph(opts.save_path + "/model.ckpt-288720426.meta") saver.restore(session, tf.train.latest_checkpoint('./results')) print("Model restored.") with tf.device("/cpu:0"): model = Word2Vec(opts, session) model.read_analogies() # Read analogy questions for _ in xrange(opts.epochs_to_train): #model.train() # Process one epoch model.eval() # Eval analogies.

I added the two lines for loading the model (saver = ...) and commented out the training line. Looking at the meta and latest checkpoint files and tensorboard shows a trained model, but when I run the code, the evaluation results in 0.1% correct answers, which seems to me like the model restarts with an untrained model. I expected the result to be again 36%.

Can somebody tell me the error I made in the code, or maybe even in my thinking?

最满意答案

恢复模型后,您可能正在tf.global_variables_initializer().run()调用tf.global_variables_initializer().run() 。 所以你基本上加载权重,然后用初始化值覆盖它们,你的网络从头开始。

我使用命令行选项为使用拉丁语的小项目实现了恢复检查点,您可以在这里查看代码: https : //github.com/CarstenIsert/LatinLearner/blob/master/word2vec.py

You are probably calling tf.global_variables_initializer().run() in build_graph after you restored the model. So you basically load the weights and then overwrite them with the initialisation values and your network starts from scratch.

I implemented restoring the checkpoints with command line options for a small project working with Latin and you can have a look at the code here: https://github.com/CarstenIsert/LatinLearner/blob/master/word2vec.py

更多推荐

本文发布于:2023-08-07 03:41:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1460021.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模型   加载   正确   Tensorflow   loading

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!