I would like to modify/change operations using a frozen graph. For example, as below, modify ops from "upsample2D whose resizing method is ResizeNearestNeighbor" to 'upsample2D whose resizing method is 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')
Actually, the above code is not working; I think it's due to unhashable type in nodedef; also, decoding error google.protobuf.message.DecodeError: Error parsing message when importing modified graph
I think the following methods may work, but any help for this?
graph_replace = tf.contrib.graph_editor.graph_replace
graph_replace(node, {node.xx: new_node.xx })
or,
tf.import_graph_def(graph_def, input_map={node: a new node})
Thanks