使用Tensorflow保存模型时遇到麻烦。文件过大

时间:2018-10-08 07:44:09

标签: tensorflow

2018-10-08 07:03:40.303219 Saving checkpoint of model...
Traceback (most recent call last):
  File "train_reconstruction_conv5.py", line 188, in <module>
    save_path = saver.save(sess, checkpoint_name)
  File "/home/fanghb/python35/lib/python3.5/site-packages/tensorflow/python/training/saver.py", line 1645, in save
    meta_graph_filename, strip_default_attrs=strip_default_attrs)
  File "/home/fanghb/python35/lib/python3.5/site-packages/tensorflow/python/training/saver.py", line 1683, in export_meta_graph
    graph_def=ops.get_default_graph().as_graph_def(add_shapes=True),
  File "/home/fanghb/python35/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 3005, in as_graph_def
    result, _ = self._as_graph_def(from_version, add_shapes)
  File "/home/fanghb/python35/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 2963, in _as_graph_def
    c_api.TF_GraphToGraphDef(self._c_graph, buf)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Cannot serialize protocol buffer of type tensorflow.GraphDef as the serialized size (2950754208bytes) would be larger than the limit (2147483647 bytes)

训练模型时,我提出了上述异常。此外,我发现我的元文件在检查点中非常大。

1 个答案:

答案 0 :(得分:2)

tf.data.Dataset.from_tensor_slices((features,labels))将特征和标签数组作为tf.constant()操作嵌入到TensorFlow图中。 查看更多https://www.tensorflow.org/guide/datasets#consuming_numpy_arrays