连续预测、
一、连续预测
调用模型遍历需要预测文件夹中的图片:
image_ids = open(‘VOCdevkit/VOC2007/ImageSets/Main/test.txt’).read().strip().split()
for image_id in tqdm(image_ids): # 遍历测试图像
image_path = “./VOCdevkit/VOC2007/JPEGImages/” + image_id + “.jpg” # 原图像的存储路径
try:
image = Image.open(image_path)
except:
print(‘Open Error! Try again!’)
continue
else:
r_image = ssd.detect_image(image) # 使用网络进行预测
image_results_path = “./image_results/” # 创建用于存放预测好的图像的文件夹
if not os.path.exists(image_results_path):
os.mkdir(image_results_path)
r_image.save(os.path.join(image_results_path, image_id+“.jpg”)) # 存储图像
使用项目:https://gitcode.com/LLL58/SSDPytorch