0

我有一个 FasterRCNN 模型在 Linux 上的 PyTorch 中训练(pytorch 1.9.0,torchvision 0.10.0)并使用以下方法写入磁盘:

model = torchvision.models.detection.faster_rcnn.FasterRCNN(....)
#training, etc. here
torch.save(frcnnModel, "frcnn.pt")

之后,我想得到一个 torchscript 版本,这样我就可以在 C++ libtorch 中加载它,所以我编写了一个最小的脚本来加载它,调用 torch.jit.script 并保存它:

frcnnModel = torch.jit.script("frcnn.pt")
frcnnModel.eval()
frcnnModelScripted = torch.jit.script(frcnnModel)
frcnnModelScripted.save("frcnn.torchscript")

但是,当我运行此后处理脚本时,出现此错误:

RuntimeError: 
Module 'GeneralizedRCNNTransform' has no attribute 'image_mean' (This attribute exists on the Python module, but we failed to convert Python type: 'numpy.ndarray' to a TorchScript type. Only tensors and (possibly nested) tuples of tensors, lists, or dictsare supported as inputs or outputs of traced functions, but instead got value of type ndarray.. Its type was inferred; try adding a type annotation for the attribute.)

我做了很多阅读问答,看到很多关于 Torchscript 不支持 FasterRCNN 的讨论,但这些讨论似乎(相对)过时了,我所看到的似乎暗示它现在应该可以工作了。所以我想知道我是否误解了关于现在支持它的讨论,或者我做错了什么。任何见解将不胜感激。

4

0 回答 0