forked from chaiNNer-org/chaiNNer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsave_model.py
More file actions
31 lines (25 loc) · 898 Bytes
/
save_model.py
File metadata and controls
31 lines (25 loc) · 898 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from __future__ import annotations
from pathlib import Path
from sanic.log import logger
from nodes.impl.onnx.model import OnnxModel
from nodes.properties.inputs import DirectoryInput, OnnxModelInput, RelativePathInput
from .. import io_group
@io_group.register(
schema_id="chainner:onnx:save_model",
name="Save Model",
description="""Save ONNX model to file (.onnx).""",
icon="MdSave",
inputs=[
OnnxModelInput(),
DirectoryInput(must_exist=False),
RelativePathInput("Model Name"),
],
outputs=[],
side_effects=True,
)
def save_model_node(model: OnnxModel, directory: Path, model_name: str) -> None:
full_path = (directory / f"{model_name}.onnx").resolve()
logger.debug(f"Writing file to path: {full_path}")
full_path.parent.mkdir(parents=True, exist_ok=True)
with open(full_path, "wb") as f:
f.write(model.bytes)