51 lines
2.1 KiB
Python
51 lines
2.1 KiB
Python
from .common import *
|
|
from .load_config import ModelConfig
|
|
from .helper import prepare_result_folder, prepare_tmp_folder
|
|
from .img_preprocess import img2txt_bin
|
|
|
|
import os
|
|
import subprocess
|
|
|
|
def run_dynasty_fix(input_imgs: Dict, config: ModelConfig, model_file: str, hardware=520) -> str:
|
|
prepare_tmp_folder()
|
|
prepare_result_folder('simulator')
|
|
|
|
# Prepare inputs
|
|
if len(input_imgs.keys()) > 1:
|
|
logging.error("Current hardware simulator do not support more than one input.")
|
|
|
|
input_file_name = list(input_imgs.values())[0]
|
|
input_shape = list(config.input_shapes.values())[0]
|
|
img2txt_bin(input_file_name, False, RESULT_FOLDER + '/simulator',
|
|
input_shape[2], input_shape[3], config.preprocess_config["img_channel"],
|
|
config.preprocess_config["img_preprocess_method"], 'img2txt',
|
|
520, config.preprocess_config["radix"],
|
|
x_pos=config.preprocess_config["p_crop"]["crop_x"],
|
|
y_pos=config.preprocess_config["p_crop"]["crop_y"],
|
|
crop_h=config.preprocess_config["p_crop"]["crop_h"],
|
|
crop_w=config.preprocess_config["p_crop"]["crop_w"],
|
|
keep_aspect_ratio=config.preprocess_config["keep_aspect_ratio"],
|
|
enable_crop=config.enable_crop)
|
|
input_txt_path = RESULT_FOLDER + '/simulator/' + os.path.basename(input_file_name).split('.')[0] + ".txt"
|
|
|
|
# Run dynasty
|
|
logging.info('Running dynasty simulator...')
|
|
os.chdir(RESULT_FOLDER + '/simulator')
|
|
if hardware == 520:
|
|
platform = 'kl520'
|
|
elif hardware == 720:
|
|
platform = 'kl720'
|
|
else:
|
|
platform = 'unknown'
|
|
output_path = RESULT_FOLDER + "/simulator/"
|
|
subprocess.run([LIBS_FOLDER + '/dynasty/run_fix_inference',
|
|
'--model', model_file,
|
|
'--platform', platform,
|
|
'--dump', '0',
|
|
'--shapeOrder', '0',
|
|
'--output', output_path,
|
|
'--data', input_txt_path,
|
|
'--name', list(config.input_shapes.keys())[0],
|
|
'-e'], check=True)
|
|
return output_path
|