我正在尝试在tfv2发行版上加载在tf v1中创建的.pb文件,我的问题是,版本2确实与较旧的pb兼容吗?
我已经尝试了一些方法,但是没有一个起作用。尝试直接通过以下方式加载pb文件:
with tf.compat.v1.gfile.GFile("./saved_model.pb","rb") as f:
graph_def = tf.compat.v1.GraphDef()
graph_def.ParseFromString(f.read())
with tf.Graph().as_default() as graph:
tf.import_graph_def(graph_def,name="")
当我运行上面的代码时,结果是:
Traceback (most recent call last):
File "read_tfv1_pb.py",line 7,in <module>
graph_def.ParseFromString(f.read())
File "D:\Anaconda3\envs\tf2\lib\site-packages\google\protobuf\message.py",line 187,in ParseFromString
return self.MergeFromString(serialized)
File "D:\Anaconda3\envs\tf2\lib\site-packages\google\protobuf\internal\python_message.py",line 1128,in MergeFromString
if self._InternalParse(serialized,length) != length:
File "D:\Anaconda3\envs\tf2\lib\site-packages\google\protobuf\internal\python_message.py",line 1193,in InternalParse
pos = field_decoder(buffer,new_pos,end,self,field_dict)
File "D:\Anaconda3\envs\tf2\lib\site-packages\google\protobuf\internal\decoder.py",line 968,in _SkipFixed32
raise _DecodeError('Truncated message.')
google.protobuf.message.DecodeError: Truncated message.
如果没有,我是否可以保存旧的pb的权重并将其放置在tensorflow v2上的新模型实例中以应用转移学习/以新的模型结构保存?