如何一次加载张量流模型并进行多个预测

时间:2018-12-19 03:38:13

标签: python tensorflow

有人可以帮助我修改此代码以运行多个输入吗?

`# Create network.  
net = MyModel({'data': tf.expand_dims(img, dim=0)}, is_training=False)

# Which variables to load.
restore_var = tf.global_variables()

# Predictions.
raw_output = net.layers['fc1_voc12']
raw_output_up = tf.image.resize_bilinear(raw_output, tf.shape(img)[0:2,])

# CRF.
raw_output_up = tf.nn.softmax(raw_output_up)
raw_output_up = tf.py_func(dense_crf, [raw_output_up, tf.expand_dims(img_orig, dim=0)], tf.float32)

raw_output_up = tf.argmax(raw_output_up, dimension=3)
pred = tf.expand_dims(raw_output_up, dim=3)


# Set up TF session and initialize variables. 
config = tf.ConfigProto()
config.gpu_options.allow_growth = True
sess = tf.Session(config=config)
init = tf.global_variables_initializer()

sess.run(init)

# Load weights.
loader = tf.train.Saver(var_list=restore_var)
load(loader, sess, args.model_weights)

# Perform inference.
preds = sess.run(pred)

out= decode_labels(preds)
`

此代码对单输入有效。我想一次加载模型并为多个图像做预测。该怎么做?

0 个答案:

没有答案