ThanatosShinji / onnx-tool

A parser, editor and profiler tool for ONNX models.
https://pypi.org/project/onnx-tool/
MIT License
383 stars 51 forks source link

Allow pathlib.Path values as input to Model construction #54

Closed ashay closed 11 months ago

ashay commented 11 months ago

Prior to this patch, only string values could be used to specify the path to the input ONNX file. However, several Python programs use values of type pathlib.Path, which causes the model creation to silently fail in onnx-tool. This patch fixes the problem by allowing both string paths or pathlib.Path paths.

Credit to @xich for discovering the problem!

ashay commented 11 months ago

Here is a script to reproduce the error:

import onnx_tool
from pathlib import Path

model = onnx_tool.Model(Path("/tmp/model.onnx"))
print(model.graph)  # AttributeError: 'Model' object has no attribute 'graph'