iT邦幫忙

2025 iThome 鐵人賽

DAY 17
0
Cloud Native

新興k8s工作流flyte與MLOps。系列 第 17

Day 17 : ONNX 轉換plugin example

  • 分享至 

  • xImage
  •  

設定ONNX規定之設定、版本、輸入輸出。

def train() -> (
    Annotated[
        PyTorch2ONNX,
        PyTorch2ONNXConfig(
            args=torch.randn(1, 1, 224, 224, requires_grad=True),
            export_params=True,  # store the trained parameter weights inside
            opset_version=10,  # the ONNX version to export the model to
            do_constant_folding=True,  # whether to execute constant folding for optimization
            input_names=["input"],  # the model's input names
            output_names=["output"],  # the model's output names
            dynamic_axes={
                "input": {0: "batch_size"},
                "output": {0: "batch_size"},
            },  # variable length axes
        ),
    ]
):

return PyTorch2ONNX(model=torch_model)

與flyteFile, FlyteDirectory相同使用方法,下載s3

@task
def onnx_predict(model_file: ONNXFile) -> JPEGImageFile:
    rt_session = onnxruntime.InferenceSession(model_file.download())

上一篇
Day 16: flyte mlflow驗證
下一篇
Day 18: 撰寫範例(修改中)
系列文
新興k8s工作流flyte與MLOps。19
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言