[英]Loading SavedModel is a lot slower than loading a tf.train.Saver checkpoint
I changed from tf.train.Saver
to the SavedModel format which surprisingly means loading my model from disk is a lot slower (instead of a couple of seconds it takes minutes). 我从
tf.train.Saver
更改为SavedModel格式,这意味着从磁盘加载我的模型要慢得多(而不是几秒钟它需要几分钟)。 Why is this and what can I do to load the model faster? 为什么这样做以及如何更快地加载模型?
I used to do this: 我曾经这样做过:
# Save model
saver = tf.train.Saver()
save_path = saver.save(session, model_path)
# Load model
saver = tf.train.import_meta_graph(model_path + '.meta')
saver.restore(session, model_path)
But now I do this: 但现在我这样做:
# Save model
builder = tf.saved_model.builder.SavedModelBuilder(model_path)
builder.add_meta_graph_and_variables(session, [tf.saved_model.tag_constants.TRAINING])
builder.save()
# Load model
tf.saved_model.loader.load(session, [tf.saved_model.tag_constants.TRAINING], model_path)
I am by no ways an expert in Tensorflow, but if I had to take a guess as to why this is happening, I would say that: 我绝不是Tensorflow的专家,但如果我不得不猜测为什么会发生这种情况,我会说:
Depending on the size of your graph, recreating everything that it contained might take some time. 根据图表的大小,重新创建其中包含的所有内容可能需要一些时间。
Concerning the second question, as @JH said, if there are no reasons for you to use one strategy over the other, and time is of the essence, then just go with the fastest one. 关于第二个问题,正如@JH所说,如果没有理由让你使用一种策略而不是另一种策略,时间是至关重要的,那么就选择最快的。
what can I do to load the model faster?
我该怎么做才能更快地加载模型?
Switch back to tf.train.Saver
, as your question shows no motivations for using SavedModelBuilder, and makes it clear that elapsed time matters to you. 切换回
tf.train.Saver
,因为您的问题没有显示使用SavedModelBuilder的动机,并明确表示已用时间对您很重要。 Alternatively, an MCVE that reproduced the timing issue would allow others to collaborate with you on profiling, diagnosing, and fixing any perceived performance issue. 或者,再现时间问题的MCVE将允许其他人与您合作进行分析,诊断和修复任何感知性能问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.