# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- # vim: set filetype=python: # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distibuted with this # file, You can obtain one at http://mozilla.org/MPL/2.0/.
import glob import json import os import pathlib import shutil import tempfile from typing import Annotated
# Create the new model in a temporary directory and copy all it's content back to save_path # Doing this because if save_path is same as model_path & we directly write to model_path # onnx will append to the external data path which would make it grow more than expected. with tempfile.TemporaryDirectory() as tmp_dir:
tmp_model_path = os.path.join(tmp_dir, os.path.basename(model_path))
file_names = os.listdir(tmp_dir)
target_dir = str(pathlib.Path(save_path).parent)
os.makedirs(target_dir, exist_ok=True) for file_name in file_names:
shutil.copy2(os.path.join(tmp_dir, file_name), target_dir)
def main(base_path: Annotated[str, typer.Option()]): """
This will convert recursively all onnx models in that directory to one with external data format. """ # Convert all for model_path in glob.glob(
os.path.join(base_path, "**/*.onnx"),
recursive=True,
):
print("Converting", model_path)
convert(model_path, model_path)
# Find all config.json and enable use_external_data_format for config_path in glob.glob(
os.path.join(base_path, "**/config.json"),
recursive=True,
):
print("Modifying", config_path) # Load the JSON file with open(config_path, "r") as infile:
config_data = json.load(infile)
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.