您的功能请求是否与问题相关?请描述。
我想能够将计算机视觉模型导出到ONNX格式
描述使用场景
ONNX 是一种将要添加到torchscript的格式。它可以在许多环境中运行,包括iOS、Android、Web等。
描述您希望的解决方案
我已经编写了大部分代码。我只需要测试它并为它创建一个PR:
class LudwigWrapper(torch.nn.Module):
def __init__(self, model):
super(LudwigWrapper, self).__init__()
self.model = model
def forward(self, x):
return self.model({"image_path": x})
def _export_classifier_onnx(model_path, export_path):
ludwig_model = LudwigModel.load(model_path)
model = LudwigWrapper(ludwig_model.model) # Wrap the model
model.eval() # inference mode, is this needed.. I think onnx export does this for us
width = ludwig_model.config["input_features"][0]["preprocessing"]["width"]
height = ludwig_model.config["input_features"][0]["preprocessing"]["height"]
example_input = torch.randn(1, 3, width, height, requires_grad=True)
torch.onnx.export(
model,
example_input,
export_path,
opset_version=18,
export_params=True,
do_constant_folding=True,
input_names=["input"],
output_names=["combiner_hidden_1", "output", "combiner_hidden_2"],
)
def _quantize(path_fp32, path_int8):
from onnxruntime.quantization import quantize_dynamic
quantize_dynamic(path_fp32, path_int8) # type: ignore
描述您考虑过的替代方案
另一种选择是使用其他格式,如CoreML
附加上下文
加入我们的slack频道: #computer-vision
3条答案
按热度按时间jum4pzuy1#
如果有任何问题,我想研究并开始解决它,这对我来说很有趣。我之前曾使用过ONNX。你能提供一些指导和背景信息吗?
rwqw0loc2#
@JaynouOliver,我们正在进行一个PR:
#3761
如果您想参与我们的计算机视觉工作,请加入我们的#computer-vision slack 频道。
sqyvllje3#
当然,已经加入。