Tensorflow GraphDef不能大于2GB,即使它不是

Tensorflow GraphDef不能大于2GB,即使它不是,tensorflow,Tensorflow,我在尝试保存和恢复模型时遇到了此错误 我已经尝试并改变了结构,将模型的大小减小到1.2GB,但错误依然存在: -rw-rw-r-- 1 ubuntu ubuntu 1.2G Feb 24 13:44 cnn-classifier-model-0.data-00000-of-00001 -rw-rw-r-- 1 ubuntu ubuntu 1.1K Feb 24 13:44 cnn-classifier-model-0.index -rw-rw-r-- 1 ubuntu ubuntu 102K F

我在尝试保存和恢复模型时遇到了此错误

我已经尝试并改变了结构,将模型的大小减小到1.2GB,但错误依然存在:

-rw-rw-r-- 1 ubuntu ubuntu 1.2G Feb 24 13:44 cnn-classifier-model-0.data-00000-of-00001
-rw-rw-r-- 1 ubuntu ubuntu 1.1K Feb 24 13:44 cnn-classifier-model-0.index
-rw-rw-r-- 1 ubuntu ubuntu 102K Feb 24 13:44 cnn-classifier-model-0.meta
知道为什么会发生这种情况吗

一些代码:

# In the graph
# Create a saver.
saver = tf.train.Saver()
# Remember the training_op we want to run by adding it to a collection.
tf.add_to_collection('foo', foo)

# In session
save_path = saver.save(sess, 'metafiles/cnn-classifier-model', global_step=0)    # at the end of training

# Later in a seperate Jupyter cell/new notebook
sess = tf.InteractiveSession()
new_saver = tf.train.import_meta_graph('metafiles/cnn-classifier-model-0.meta')
new_saver.restore(sess, 'metafiles/cnn-classifier-model-0')
foo = tf.get_collection('foo')[0]
sess.close()
错误跟踪:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-49-ada5c83f8e85> in <module>()
      4 sess = tf.InteractiveSession()
      5 new_saver = tf.train.import_meta_graph('metafiles/cnn-classifier-model-0.meta')
----> 6 new_saver.restore(sess, 'metafiles/cnn-classifier-model-0')
      7 predictions = tf.get_collection('predictions')[0]
      8 sess.close()

/home/ubuntu/anaconda2/lib/python2.7/site-packages/tensorflow/python/training/saver.pyc in restore(self, sess, save_path)
   1437       return
   1438     sess.run(self.saver_def.restore_op_name,
-> 1439              {self.saver_def.filename_tensor_name: save_path})
   1440 
   1441   @staticmethod

/home/ubuntu/anaconda2/lib/python2.7/site-packages/tensorflow/python/client/session.pyc in run(self, fetches, feed_dict, options, run_metadata)
    765     try:
    766       result = self._run(None, fetches, feed_dict, options_ptr,
--> 767                          run_metadata_ptr)
    768       if run_metadata:
    769         proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)

/home/ubuntu/anaconda2/lib/python2.7/site-packages/tensorflow/python/client/session.pyc in _run(self, handle, fetches, feed_dict, options, run_metadata)
    963     if final_fetches or final_targets:
    964       results = self._do_run(handle, final_targets, final_fetches,
--> 965                              feed_dict_string, options, run_metadata)
    966     else:
    967       results = []

/home/ubuntu/anaconda2/lib/python2.7/site-packages/tensorflow/python/client/session.pyc in _do_run(self, handle, target_list, fetch_list, feed_dict, options, run_metadata)
   1013     if handle is None:
   1014       return self._do_call(_run_fn, self._session, feed_dict, fetch_list,
-> 1015                            target_list, options, run_metadata)
   1016     else:
   1017       return self._do_call(_prun_fn, self._session, handle, feed_dict,

/home/ubuntu/anaconda2/lib/python2.7/site-packages/tensorflow/python/client/session.pyc in _do_call(self, fn, *args)
   1020   def _do_call(self, fn, *args):
   1021     try:
-> 1022       return fn(*args)
   1023     except errors.OpError as e:
   1024       message = compat.as_text(e.message)

/home/ubuntu/anaconda2/lib/python2.7/site-packages/tensorflow/python/client/session.pyc in _run_fn(session, feed_dict, fetch_list, target_list, options, run_metadata)
    998                 run_metadata):
    999       # Ensure any changes to the graph are reflected in the runtime.
-> 1000       self._extend_graph()
   1001       with errors.raise_exception_on_not_ok_status() as status:
   1002         return tf_session.TF_Run(session, options,

/home/ubuntu/anaconda2/lib/python2.7/site-packages/tensorflow/python/client/session.pyc in _extend_graph(self)
   1042         graph_def, self._current_version = self._graph._as_graph_def(
   1043             from_version=self._current_version,
-> 1044             add_shapes=self._add_shapes)
   1045         # pylint: enable=protected-access
   1046 

/home/ubuntu/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.pyc in _as_graph_def(self, from_version, add_shapes)
   2218           bytesize += op.node_def.ByteSize()
   2219           if bytesize >= (1 << 31) or bytesize < 0:
-> 2220             raise ValueError("GraphDef cannot be larger than 2GB.")
   2221       if self._functions:
   2222         for f in self._functions.values():

ValueError: GraphDef cannot be larger than 2GB.
---------------------------------------------------------------------------
ValueError回溯(最近一次调用上次)
在()
4 sess=tf.InteractiveSession()
5 new_saver=tf.train.import_meta_图('metafiles/cnn-classifier-model-0.meta'))
---->6新的_saver.restore(sess,'metafiles/cnn-classifier-model-0')
7预测=tf.get_集合(“预测”)[0]
8节结束()
/home/ubuntu/anaconda2/lib/python2.7/site-packages/tensorflow/python/training/saver.pyc in restore(self、sess、save_path)
1437返回
1438 sess.run(self.saver\u def.restore\u op\u name,
->1439{self.saver\u def.filename\u tensor\u name:save\u path})
1440
1441@staticmethod
/home/ubuntu/anaconda2/lib/python2.7/site-packages/tensorflow/python/client/session.pyc in run(self、fetches、feed_dict、options、run_元数据)
765试试:
766结果=self.\u运行(无、获取、馈送、选项、,
-->767运行(元数据)
768如果运行\u元数据:
769 proto_data=tf_session.tf_GetBuffer(运行元数据ptr)
/home/ubuntu/anaconda2/lib/python2.7/site-packages/tensorflow/python/client/session.pyc in\u run(self、handle、fetches、feed\u dict、options、run\u元数据)
963如果最终用户获取或最终用户目标:
964 results=self.\u do\u run(句柄、最终目标、最终获取、,
-->965提要(文本字符串、选项、运行元数据)
966其他:
967结果=[]
/home/ubuntu/anaconda2/lib/python2.7/site-packages/tensorflow/python/client/session.pyc in_do_运行(self、handle、target_列表、fetch_列表、feed_dict、options、run_元数据)
1013如果句柄为“无”:
1014返回self.\u do\u调用(\u run\u fn,self.\u会话,feed\u dict,fetch\u list,
->1015目标\u列表、选项、运行\u元数据)
1016其他:
1017返回self.\u do.\u调用(\u prun\u fn,self.\u会话,句柄,提要\u dict,
/home/ubuntu/anaconda2/lib/python2.7/site-packages/tensorflow/python/client/session.pyc in_do_call(self,fn,*args)
1020定义待命(self、fn、*args):
1021请尝试:
->1022返回fn(*args)
1023除错误外。操作错误为e:
1024 message=兼容文本(e.message)
/home/ubuntu/anaconda2/lib/python2.7/site-packages/tensorflow/python/client/session.pyc in_run_fn(会话、提要、获取列表、目标列表、选项、运行元数据)
998运行单元(元数据):
999#确保图形的任何更改都反映在运行时中。
->1000自扩展图()
1001出现错误。将\u not\u ok\u status()上的\u exception\u引发为状态:
1002返回tf_会话。tf_运行(会话、选项、,
/home/ubuntu/anaconda2/lib/python2.7/site-packages/tensorflow/python/client/session.pyc在扩展图(self)中
1042图形定义,自我。当前版本=自我。图形。作为图形定义(
1043 from_version=self._当前_版本,
->1044添加形状=自我。_添加形状)
1045#pylint:enable=受保护访问
1046
/home/ubuntu/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.pyc in_as_graph_def(self,from_version,add_shapes)
2218字节大小+=op.node_def.bytesize()
2219如果bytesize>=(1220提升值错误(“GraphDef不能大于2GB”)
2221如果自身功能:
2222对于self.\u函数中的f.values():
ValueError:GraphDef不能大于2GB。

你能不能也发布错误的完整堆栈跟踪?嗨@mrry我已经添加了我得到的跟踪,你有时间可以看一下吗?