首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Detectron2中运行Caffe2推理

在Detectron2中运行Caffe2推理
EN

Stack Overflow用户
提问于 2020-03-17 22:24:19
回答 1查看 835关注 0票数 4

我有一个Detectron2 .pth模型,通过位于这里的Detectron2工具功能成功地转换成Caffe2 .pb:https://github.com/facebookresearch/detectron2/blob/master/tools/caffe2_converter.py

正如建议的那样,在转换时使用--run标志来确认结果,并且结果非常类似于原始的detectron2结果。

若要使用生成的model.pb和model_init.pb文件对新映像运行推断,请使用以下功能:https://github.com/facebookresearch/detectron2/blob/master/detectron2/export/api.py (主要是) https://github.com/facebookresearch/detectron2/blob/master/detectron2/export/caffe2_inference.py

然而,推理结果甚至并不接近。有人能提出可能发生这种情况的原因吗?Detectron2回购说所有的预处理都是在caffe2脚本中完成的,但是我是不是遗漏了什么呢?

我可以提供我的推理代码:

代码语言:javascript
复制
caffe2_model = Caffe2Model.load_protobuf(input_directory)
img = cv2.imread(input_image)
image = torch.as_tensor(img.astype("float32").transpose(2, 0, 1))
data = {'image': image, 'height': image.shape[1], 'width': image.shape[2]}
output = caffe2_model([data])
EN

回答 1

Stack Overflow用户

发布于 2022-06-26 12:43:15

您的input_image应该是32的倍数。因此,您需要调整输入img的大小吗?

所以你需要:

代码语言:javascript
复制
caffe2_model = Caffe2Model.load_protobuf(input_directory)
img = cv2.imread(input_image)
img = cv2.resize(img, (64, 64))  
image = torch.as_tensor(img.astype("float32").transpose(2, 0, 1))
data = {'image': image, 'height': image.shape[1], 'width': image.shape[2]}
output = caffe2_model([data])

请参阅链接中的类: classdetectron2.export.Caffe2Tracer:https://detectron2.readthedocs.io/en/latest/modules/export.html#detectron2.export.Caffe2Tracer

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

https://stackoverflow.com/questions/60731073

复制
相关文章

相似问题

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