我想使用预训练模型热烈启动另一个模型,但有一点区别。简单地说,我创建一个新模型,并使用预训练模型权重为变量赋予相同的名称。但是,保存模型时发生错误。Tensorflow:“GraphDef不能大于2GB”。在分配变量后保存模型时发生错误
Traceback (most recent call last): File "tf_test.py", line 23, in <module> save_path = saver.save(sess, "./model.ckpt") File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 1308, in save self.export_meta_graph(meta_graph_filename) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 1331, in export_meta_graph graph_def=ops.get_default_graph().as_graph_def(add_shapes=True), File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2268, in as_graph_def result, _ = self._as_graph_def(from_version, add_shapes) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2231, in _as_graph_def raise ValueError("GraphDef cannot be larger than 2GB.") ValueError: GraphDef cannot be larger than 2GB.
的示例代码如下:
import tensorflow as tf
import numpy as np
v1 = tf.get_variable("L_enc", [400000, 1024])
v2 = tf.get_variable("L_dec", [400000, 1024])
init_op = tf.initialize_all_variables()
saver = tf.train.Saver(tf.all_variables())
with tf.Session() as sess:
sess.run(init_op)
for v in tf.trainable_variables():
embedding = np.random.uniform(-1, 1, (400000, 1024))
sess.run(v.assign(embedding))
# Save the variables to disk.
save_path = saver.save(sess, "./model.ckpt")
print("Model saved in file: %s" % save_path)
占位符把戏在我的情况下工作,但可惜的是业绩下滑悬崖 - 上解除该限制的计划吗? –