我有一个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脚本中完成的,但是我是不是遗漏了什么呢?
我可以提供我的推理代码:
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])
发布于 2022-06-26 04:43:15
您的input_image应该是32的倍数。因此,您需要调整输入img的大小吗?
所以你需要:
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
https://stackoverflow.com/questions/60731073
复制