【发布时间】:2020-01-31 23:27:30
【问题描述】:
我想使用冻结图修改/更改操作。 例如,如下,将ops从"upsample2D,其大小调整方法为ResizeNearestNeighbor"修改为'upsample2D,其调整大小方法为ResizeBilinear"
with tf.device('/gpu:0'):
with tf.gfile.GFile(filename, 'rb') as file:
serialized_graph = file.read()
graph_def.ParseFromString(serialized_graph)
tf.import_graph_def(graph_def, name='')
graph_replace = tf.contrib.graph_editor.graph_replace
nodes = graph_def.node
for node in nodes:
if "ResizeNearestNeighbor" in node.name :
print ("===========> ", node.name)
node.op ="ResizeBilinear"
# also need to change node name
nodes = graph_def.node
for node in nodes:
print (node.name)
tf.train.write_graph(graph_def, "./", name='modified.pb')
其实上面的代码是不行的;我认为这是由于 nodedef 中的不可散列类型;另外,解码错误 google.protobuf.message.DecodeError: Error parsing message when importing modified graph
我认为以下方法可能有效,但对此有何帮助?
graph_replace = tf.contrib.graph_editor.graph_replace
graph_replace(node, {node.xx: new_node.xx })
或者,
tf.import_graph_def(graph_def, input_map={node: a new node})
谢谢
【问题讨论】:
-
貌似 tf.train.write_graph(graph_def, "./", name='modified.pb') 工作,但是pb解析失败,文件大小比原来大很多大小。
标签: tensorflow graph edit operation