检查冻结的张量流模型:
wget https://storage.googleapis.com/download.tensorflow.org/models/inception_v3_2016_08_28_frozen.pb.tar.gz
我看到输入大小为Tensor 'input:0', which has shape '(1, 299, 299, 3)'
,我想知道是否可以(None, 299, 299, 3)
通过batch_size> 1进行输入以使批次预测可用?
在一般情况下,可能无法执行此操作,因为可能存在依赖于第一维为1的操作(例如假设tf.squeeze
用于input:0
)。但是,您可以尝试用所需形状的占位符替换输入。您可以使用tf.graph_util.import_graph_def
。如果操作允许,则TensorFlow应该导入图以相应地调整节点形状。请参见以下示例:
import tensorflow as tf
# First graph
with tf.Graph().as_default():
x = tf.placeholder(tf.float32, [1, 10, 20], name='Input')
y = tf.square(x, name='Output')
print(y)
# Tensor("Output:0", shape=(1, 10, 20), dtype=float32)
gd = tf.get_default_graph().as_graph_def()
# Second graph
with tf.Graph().as_default():
x = tf.placeholder(tf.float32, [None, 10, 20], name='Input')
y, = tf.graph_util.import_graph_def(gd, input_map={'Input:0': x},
return_elements=['Output:0'], name='')
print(y)
# Tensor("Output:0", shape=(?, 10, 20), dtype=float32)
在第一个图中,Output:0
节点的形状(1, 10, 20)
是从Input:0
张量的形状推断的。但是,当我从第一个图形中获取图形定义并在第二个图形中加载时,将Input:0
张量替换为具有未定义第一维的占位符,则的形状将Output:0
更新为(?, 10, 20)
。如果我在第二个图中运行的操作给出的输入值的第一维大于一个维度,则它将运行正常,因为该图是正确的。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句