2026-01-28 06:16:04 +00:00

50 lines
1.6 KiB
Python

import sys
from typing import List
import numpy as np
import os
import glob
from .utils import clean_up
sys.path.insert(0, "/workspace/E2E_Simulator/python_flow")
import kneron_inference as e2e
def get_radix(inputs: List) -> int:
"""Get the radix value from the given inputs.
Args:
inputs (List): a list of numpy array which should be the inputs of the target model.
Raises:
ValueError: raise if the input values are out of range
Returns:
int: the radix value
"""
min_value = 0
max_value = 0
for image in inputs:
min_value = min(min_value, image.min())
max_value = max(max_value, image.max())
max_value = max(abs(min_value), abs(max_value))
radix = 7 - np.ceil(np.log2(max_value))
return int(radix)
def kneron_inference(*args, **kwargs):
"""Run Kneron inference.
"""
res = e2e.kneron_inference(*args, **kwargs)
files_to_delete = []
dirs_to_remove = []
if "bie_file" in kwargs:
dirs_to_remove.append(os.path.dirname(kwargs["bie_file"]) + "/out")
elif "nef_file" in kwargs:
dirs_to_remove.append(os.path.dirname(kwargs["nef_file"]) + "/out")
files_to_delete.append(os.path.dirname(kwargs["nef_file"]) + "/fw_info.bin")
files_to_delete.append(os.path.dirname(kwargs["nef_file"]) + "/all_models.bin")
files_to_delete.extend(glob.glob(os.path.dirname(kwargs["nef_file"]) + "/model_*.bin"))
elif "onnx_file" in kwargs:
dirs_to_remove.append(os.path.dirname(kwargs["onnx_file"]) + "/out")
if "dump" not in kwargs:
clean_up("/", files_to_delete, dirs_to_remove)
return res