Other Parts Discussed in Thread: AM67A
Tool/software:
Hi team:
I try to run example code to convert model by https://github.com/TexasInstruments/edgeai-tidl-tools/blob/master/examples/jupyter_notebooks/custom-model-onnx.ipynb
but I get error below:
*************** EP Error *************** EP Error Unknown Provider Type: TIDLCompilationProvider when using ['TIDLCompilationProvider', 'CPUExecutionProvider'] Falling back to ['CPUExecutionProvider'] and retrying. ****************************************
I check the TIDL_TOOLS_PATH is set, and make sure the path has "tidl_model_import_onnx.so"
Please help me to fix this symptom
Thanks for your kindly help.
[backup]
code below:
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')