我有一个张量流模型作为冻结图,它接受一个图像张量作为输入。但是,我想向该图中添加一个新的输入图像解码器节点,以便模型也接受 jpg 图像的编码字节字符串,并最终自行解码图像。到目前为止,我已经尝试过这种方法:
model = './frozen_graph.pb'
with tf.gfile.FastGFile(model, 'rb') as f:
# read graph
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
tf.import_graph_def(graph_def, name="")
g = tf.get_default_graph()
# fetch old input
old_input = g.get_tensor_by_name('image_tensor:0')
# define new input
new_input = graph_def.node.add()
new_input.name = 'encoded_image_string_tensor'
new_input.op = 'Substr'
# add new input attr
image = tf.image.decode_image(new_input, channels=3)
# link new input to old input
old_input.input = 'encoded_image_string_tensor' # must match with the name above
上面的代码返回这个异常:
Expected string passed to parameter 'input' of op 'Substr', got name: "encoded_image_string_tensor" op: "Substr" of type 'NodeDef' instead.
我不太确定我是否可以tf.image.decode_image在图表中使用 ,所以也许有另一种方法可以解决这个问题。有人有提示吗?
守着星空守着你
相关分类