【发布时间】:2022-12-06 05:43:37
【问题描述】:
我已经完成了tensorflow网站上的图像分类教程here
本教程解释了如何将经过训练的模型作为新图像的预测器运行。
有没有办法在批处理/多个图像上运行它?代码如下:
sunflower_url = "https://storage.googleapis.com/download.tensorflow.org/example_images/592px-Red_sunflower.jpg"
sunflower_path = tf.keras.utils.get_file('Red_sunflower', origin=sunflower_url)
img = tf.keras.utils.load_img(
sunflower_path, target_size=(img_height, img_width)
)
img_array = tf.keras.utils.img_to_array(img)
img_array = tf.expand_dims(img_array, 0) # Create a batch
predictions = model.predict(img_array)
score = tf.nn.softmax(predictions[0])
print(
"This image most likely belongs to {} with a {:.2f} percent confidence."
.format(class_names[np.argmax(score)], 100 * np.max(score))
)
【问题讨论】:
-
是什么阻止您一起发送多张图片?
-
将它们堆叠在您创建的批处理线中
标签: python tensorflow