首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何利用detectron2和DefaultPredictor对多幅图像进行推理

如何利用detectron2和DefaultPredictor对多幅图像进行推理
EN

Stack Overflow用户
提问于 2022-04-08 20:46:02
回答 1查看 597关注 0票数 1

我已经训练了模型,现在我想用它来检测很多图像中的物体。我看到默认预测器允许您只在图像上检测,我能做什么?

我对这个世界真的很陌生。我尝试的方法是使用for循环,但它不起作用。还有其他方法吗?

代码语言:javascript
复制
%cd /kaggle/working/detectron2
import glob
cfg.MODEL.WEIGHTS = os.path.join("/kaggle/working/detectron2/output", "model_final.pth") # path to the model we trained
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.0001 # set a testing threshold
pred = DefaultPredictor(cfg)
os.chdir("/kaggle/working/detectron2/images")
for img in glob.glob('.jpg'):
    inputs = cv2.imread(img)
    outputs = pred(inputs)
    print(outputs)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-04-09 09:45:48

好吧,我用这样的方法解决了:

代码语言:javascript
复制
%cd /kaggle/working/detectron2
import glob
cfg.MODEL.WEIGHTS = os.path.join("/kaggle/working/detectron2/output", "model_final.pth")   # path to the model we trained
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.0001   # set a testing threshold
pred = DefaultPredictor(cfg)
for img in glob.glob('/kaggle/working/detectron2/images/*.jpg'):
    inputs = cv2.imread(img)
    outputs = pred(inputs)
    print(outputs)

我删除了os.chdir()

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71802972

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档