This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
工具与软件:
嗨、团队:
但我收到以下错误:
*************** EP Error *************** EP Error Unknown Provider Type: TIDLCompilationProvider when using ['TIDLCompilationProvider', 'CPUExecutionProvider'] Falling back to ['CPUExecutionProvider'] and retrying. ****************************************
检查是否设置了 TIDL_TOOLS_PATH、并确保路径具有"tidl_model_import_onnx.SO"
请帮助我修复此症状
感谢您的帮助。
[备份]
下面的代码:
import os import tqdm import cv2 import numpy as np import onnxruntime as rt import shutil from scripts.utils import imagenet_class_to_name, download_model import matplotlib.pyplot as plt from pathlib import Path from IPython.display import Markdown as md from scripts.utils import loggerWritter from scripts.utils import get_svg_path import onnx def preprocess(image_path): # read the image using openCV img = cv2.imread(image_path) # convert to RGB img = img[:,:,::-1] # Most of the onnx models are trained using # 224x224 images. The general rule of thumb # is to scale the input image while preserving # the original aspect ratio so that the # short edge is 256 pixels, and then # center-crop the scaled image to 224x224 orig_height, orig_width, _ = img.shape short_edge = min(img.shape[:2]) new_height = (orig_height * 256) // short_edge new_width = (orig_width * 256) // short_edge img = cv2.resize(img, (new_width, new_height), interpolation=cv2.INTER_CUBIC) startx = new_width//2 - (224//2) starty = new_height//2 - (224//2) img = img[starty:starty+224,startx:startx+224] # apply scaling and mean subtraction. # if your model is built with an input # normalization layer, then you might # need to skip this img = img.astype('float32') for mean, scale, ch in zip([128, 128, 128], [0.0078125, 0.0078125, 0.0078125], range(img.shape[2])): img[:,:,ch] = ((img.astype('float32')[:,:,ch] - mean) * scale) img = np.expand_dims(img,axis=0) img = np.transpose(img, (0, 3, 1, 2)) return img calib_images = [ 'sample-images/elephant.bmp', 'sample-images/bus.bmp', 'sample-images/bicycle.bmp', 'sample-images/zebra.bmp', ] output_dir = 'custom-artifacts/onnx/resnet18_opset9.onnx' onnx_model_path = 'models/public/onnx/resnet18_opset9.onnx' download_model(onnx_model_path) onnx.shape_inference.infer_shapes_path(onnx_model_path, onnx_model_path) #compilation options - knobs to tweak num_bits =8 accuracy =1 log_dir = Path("logs").mkdir(parents=True, exist_ok=True) # stdout and stderr saved to a *.log file. with loggerWritter("logs/custon-model-onnx"): # model compilation options compile_options = { 'tidl_tools_path' : os.environ['TIDL_TOOLS_PATH'], 'artifacts_folder' : output_dir, 'tensor_bits' : num_bits, 'accuracy_level' : accuracy, 'advanced_options:calibration_frames' : len(calib_images), 'advanced_options:calibration_iterations' : 3, # used if accuracy_level = 1 'advanced_options:add_data_convert_ops' : 1, 'debug_level' : 1, #'deny_list' : "MaxPool" #Comma separated string of operator types as defined by ONNX runtime, ex "MaxPool, Concat" } # create the output dir if not present # clear the directory os.makedirs(output_dir, exist_ok=True) for root, dirs, files in os.walk(output_dir, topdown=False): [os.remove(os.path.join(root, f)) for f in files] [os.rmdir(os.path.join(root, d)) for d in dirs] so = rt.SessionOptions() EP_list = ['TIDLCompilationProvider','CPUExecutionProvider'] sess = rt.InferenceSession(onnx_model_path ,providers=EP_list, provider_options=[compile_options, {}], sess_options=so) input_details = sess.get_inputs() for num in tqdm.trange(len(calib_images)): output = list(sess.run(None, {input_details[0].name : preprocess(calib_images[num])}))[0] ##optional #subgraph_link =get_svg_path(output_dir) #for sg in subgraph_link: # hl_text = os.path.join(*Path(sg).parts[4:]) # sg_rel = os.path.join('../', sg) # display(md("[{}]({})".format(hl_text,sg_rel))) # #EP_list = ['TIDLExecutionProvider','CPUExecutionProvider'] #print("[ken debug] 5 ") #sess = rt.InferenceSession(onnx_model_path ,providers=EP_list, provider_options=[compile_options, {}], sess_options=so) ##Running inference several times to get an stable performance output #for i in range(5): # output = list(sess.run(None, {input_details[0].name : preprocess('sample-images/elephant.bmp')})) # #for idx, cls in enumerate(output[0].squeeze().argsort()[-5:][::-1]): # print('[%d] %s' % (idx, '/'.join(imagenet_class_to_name(cls)))) # #from scripts.utils import plot_TI_performance_data, plot_TI_DDRBW_data, get_benchmark_output #stats = sess.get_TI_benchmark_data() #fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(10,5)) #plot_TI_performance_data(stats, axis=ax) #plt.show() #print("[ken debug] 6 ") #tt, st, rb, wb = get_benchmark_output(stats) #print(f'Statistics : \n Inferences Per Second : {1000.0/tt :7.2f} fps') #print(f' Inference Time Per Image : {tt :7.2f} ms \n DDR BW Per Image : {rb+ wb : 7.2f} MB')
您好、请检查两件事。
1.确保您的 /tidl_tools/是否存在、并且具有以下版本。
tidl_tools$ ls -1
device_config.cfg
ignore.log
itidl_rt.h
itvm_rt.h
libtidl_onnxrt_ep.so
libtidl_TFL_Delegate.so
libvx_tidl_rt.so
libvx_tidl_rt.SO.1.0
nc_infofile.txt
netbufinfo.bin
osrt_deps
PC_DSP_TEST_dl_algo.out
ti_cnnperfsim.out
tidl_graphVisualizer.out
tidl_graphVisualizer_runtimes.out
tidl_model_import_onnx.so
tidl_model_import.out
tidl_model_import_relay.so
tidl_model_import.so
tidl_model_import_tflite.so
tidl_model_secure.out
version.txt
如果没有、请将 SOC 设置到您的器件、并从 edgeai-tidl-tools/目录中运行"source ./setup.sh"(这会需要一些时间)。
2.如果 存在 edgeai-tidl-tools/tidl_tools 并且该文件具有上述文件、则设置 tidl_tools_path=/ /edgeai-tidl-tools/tidl_tools.
Chris、您好:
我检查下面的 tidl_tools 文件、该文件正确(SOC = am67a)
并且已将 TIDL_TOOLS_PATH 设置为 tidl_tools 的完整路径
我的 TIDL 版本是10.00.04.00、可在 PC (Ubuntu 22.04)上运行
请帮助我检查、
感谢您的帮助。
请尝试以下操作:
更改:
从 scripts.utils 导入 loggerWritter log_dir = Path ("logs").mkdir (parents=True、exists_ok=True) # stdout 和 stderr 保存到*。log 文件。 通过 loggerWritter ("logs/custon-model-onnx"): #模型编译选项
以粗体添加行:
从 scripts.utils 导入 loggerWritter log_dir = Path ("logs").mkdir (parents=True、exist_ok=True) 打印(os.environon['tidl_tools_path'])
# stdout 和 stderr 已保存到*。log 文件中。
通过 loggerWritter ("logs/custon-model-onnx"):
#模型编译选项
确保输出的值 os.environ['tidl_tools_path'] 匹配您的 tidl_tools/目录 . 应该是这样
指向 edgeai-tidl-tools/tidl_tools/目录。
否则、您可能在设置变量之前启动了"jupyter 笔记本"。
或者、如果您想要更多控制 jupyter 笔记本、您可以从运行模型
edgeai-tidl-tools/example/osrt_python/ort/中的命令行方式:
python3 ./onnxrt_ep.py -m cl-ort-resnet18-v1 -c (首先编译模型)
python3 ./ onnxrt_ep.py -m cl-ort-resnet18-v1 -d (在 x86处理器上运行模型)
python3 ./onnxrt_ep.py -m cl-ort-resnet18-v1 (使用 C7x 仿真在 PC 上运行模型)
Chris、您好:
我打印 os.environ['tidl_tools_path']、 路径似乎正确。
感谢您的帮助。
Chris、您好!
我尝试运行命令 python3 ./onnxrt_ep.py -m cl-ort-resnet18-v1 -c
并遇到以下错误:
AttributeError: 'InferenceSession' object has no attribute 'get_TI_benchmark_data'
。
这可能是因为TIDLCompilationProvider
未使用?
感谢您的帮助。
您正在运行哪个版本的 TIDL? 我会推荐10.0变体。 看起来您是从 Docker 容器运行此程序的;正确吗? 您是否可以从容器外部运行它来消除一些差异?
我确定这 可以正常工作、因此我唯一能想到的是重新安装 tidl_tools。 要执行此操作、请移动/删除 tidl_tools (重新安装时不应存在该目录)。 确保已设置 SOC 并从 edgeai-tidl-tools 目录运行"source ./setup.sh"。
Chris、您好:
我运行 TIDL 版本10.00.04.00。
是的、我从 Docker 容器运行此文件。
非常感谢您的建议。 我将尝试直接在 Ubuntu 系统上运行它、而不使用容器。 此外、我是否可以确认 SOC 是否应设置为"am67a"?
感谢您的帮助。
尊敬的 Ken:
am67a 正确。
Chris、您好:
我想仔细检查我遵循的步骤、以确保它们正确无误:
[ENV]
不带容器
第二百零四章
TIDL:10.00.04.00
[步骤]
请确认这些步骤是否正确吗?
此外、我想问一下输出文件是否位于custom-artifacts/onnx/
笔记本中指定的目录中?
感谢您的帮助!
此致、
Ken
尊敬的 Ken:
我运行了你的所有步骤,但我对你如何运行 jupyter ipynb 文件感到困惑。 我使用的是 Ubuntu 22.04、而 exec 不起作用。 您是如何运行它的? 我听说过使用 papermill 从命令行运行笔记本、但 exec 没有任何作用。
Chris
Chris、您好:
我将 Jupyter Notebook 文件中的代码复制到一个.py
文件并使用 Python 3执行。
感谢您的帮助!
此致、
Ken
Chris、您好:
我尝试在没有容器的情况下运行 TIDL、onnx 转换工具可以起作用、
但我从获得了新问题
和
感谢您的帮助。
请为此使用其他主题帖。 我将关闭该主题帖。