deep-learning - 在多个图像上运行保存的训练模型
问题描述
我在 tensorflow 中有一个深度学习 CNN 分类器,我已经对其进行了训练并保存到了磁盘中。
目前,我一次只在一张图像上运行模型。但是,我想将其自动化以对一批 100 多张(如果不是 1000 张)图像进行分类。
有没有办法做到这一点并记录输出?下面是我目前实现这一目标的代码块。
非常感激。
# since we are using Jupyter Notebooks we can replace our argument
# parsing code with *hard coded* arguments and values
args = {
"model": "pokedex.model",
"labelbin": "lb.pickle",
"image": "examples/Roxy.jpg"
}
# load the image
image = cv2.imread(args["image"])
output = image.copy()
# pre-process the image for classification
image = cv2.resize(image, (96, 96))
image = image.astype("float") / 255.0
image = img_to_array(image)
image = np.expand_dims(image, axis=0)
# load the trained convolutional neural network and the label
# binarizer
print("[INFO] loading network...")
model = load_model(args["model"])
lb = pickle.loads(open(args["labelbin"], "rb").read())
# classify the input image
print("[INFO] classifying image...")
proba = model.predict(image)[0]
idx = np.argmax(proba)
label = lb.classes_[idx]
# we'll mark our prediction as "correct" of the input image filename
# contains the predicted label text (obviously this makes the
# assumption that you have named your testing image files this way)
filename = args["image"][args["image"].rfind(os.path.sep) + 1:]
correct = "correct" if filename.rfind(label) != -1 else "none_detected"
# build the label and draw the label on the image
label = "{}: {:.2f}% ({})".format(label, proba[idx] * 100, correct)
output = imutils.resize(output, width=400)
cv2.putText(output, label, (10, 25), cv2.FONT_HERSHEY_SIMPLEX,
0.7, (0, 255, 0), 2)
# show the output image
print("[INFO] {}".format(label))
plt_imshow("Output", output)
解决方案
推荐阅读
- javascript - 尝试将实时 sql 服务器与节点 js 连接
- avx - AVX 中的平均值数组
- bootstrap-5 - 如何在断点后更改列的顺序?
- reactjs - 使用自定义组件时,Emotion Styled 组件不会触发 dragEnd 事件
- shell - 在while循环中正确更改makefile中的变量
- reactjs - REACT JS AWS congnito 使用社交媒体登录
- javascript - 如何获取复选框值?
- kubernetes - 资源版本太旧:
- excel - 打开工作簿下的 VBA 代码慢速 Excel
- html - 带有 ngFor 的 tbody 不可见