现在我有一个冻结的tensorflow pb文件。然后,我修改了从指定图层名称conv1/weights
获得的张量的一些值:
import tensorflow as tf
from tensorflow.core.framework import graph_pb2
from tensorflow.python.framework import tensor_util
FLAGS = tf.app.flags.FLAGS
tf.app.flags.DEFINE_string('input_frozen_graph_path',
'/tmp/model.pb', '')
graph = tf.GraphDef()
with tf.gfile.Open(FLAGS.input_frozen_graph_path, 'rb') as f:
data = f.read()
graph.ParseFromString(data)
nodes = {node.name: index for index, node in enumerate(graph.node)}
conv1_weights = tensor_util.MakeNdarray(graph.node[nodes["conv1/weights"]].attr['value'].tensor)
#modify some values in conv1_weights
但是如何将修改后的conv1_weights
值写回到graph.node的名称为conv1/weights
的节点中?
任何人都可以给一些建议?
谢谢