Part Number: SK-TDA4VM
Hello,
I wrote this script to run optimized inferences with a custom TFLite model after succesfully compiling the artifacts:
import tflite_runtime.interpreter as tflite
import argparse
import numpy as np
from PIL import Image, ImageDraw
import time
import os
import cv2
import subprocess
import sys
import csv
import signal
import utils.common as common
import utils.detect as detect
from utils.dataset import read_label_file
fileExtension = '.jpg' # '.jpg' '.png'
IMG_PATH = "/opt/luca-TI/input_data/images/"
IMG_OUT = "./data_out/od/"
MODELS_FOLDER = "/opt/model_zoo/"
LABELS_PATH = MODELS_FOLDER
floating_model = False
input_mean = 127.5
input_std = 127.5
scale = (1.0, 1.0)
required_options = {
"tidl_tools_path":"/opt/edgeai-tidl-tools/tidl-tools",
"artifacts_folder":"/artifacts"
}
confidence_threshold = 0.25
def draw_objects(draw, objs, labels):
"""Draws the bounding box and label for each object."""
for obj in objs:
bbox = obj.bbox
draw.rectangle([(bbox.xmin, bbox.ymin), (bbox.xmax, bbox.ymax)],
outline='red')
draw.text((bbox.xmin + 10, bbox.ymin + 10),
'%s\n%.2f' % (labels.get(obj.id, obj.id), obj.score),
fill='red')
def run(args):
delegate_options = {}
delegate_options.update(required_options)
delegate_options['artifacts_folder'] = MODELS_FOLDER + args.mdl + delegate_options['artifacts_folder']
# delegate_options.update({'debug_level':2})
tidl_delegate = [tflite.load_delegate('libtidl_tfl_delegate.so', delegate_options)]
model_path = MODELS_FOLDER + "/" + args.mdl + "/model/" + args.mdl + ".tflite"
labels = read_label_file(LABELS_PATH)
interpreter = tflite.Interpreter(model_path=model_path, experimental_delegates=tidl_delegate)
# interpreter = tflite.Interpreter(model_path=model_path, num_threads=2)
interpreter.allocate_tensors()
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
# pre-Process input
height = input_details[0]['shape'][1]
width = input_details[0]['shape'][2]
inDir = os.listdir(IMG_PATH)
# loop through all images
for index, file in enumerate(inDir):
if index == 5:
break
try:
if(fileExtension in file):
print("Inference at image: " + str(index) + " named " + file)
file_path = os.path.join(IMG_PATH, file)
img = Image.open(file_path).resize((width, height))
input_data = np.expand_dims(img, axis=0)
if floating_model:
input_data = (input_data - input_mean) / input_std
input_data = input_data.astype(np.uint8)
interpreter.set_tensor(input_details[0]['index'], input_data)
# run inference session
interpreter.invoke()
# post process result
# output_data = interpreter.get_tensor(output_details[0]['index'])
# results = np.squeeze(output_data)
objs = detect.get_objects(interpreter, confidence_threshold, scale)
for obj in objs:
if obj.score >= confidence_threshold:
print(labels.get(obj.id, obj.id))
print(' id: ', obj.id)
print(' score: ', obj.score)
# image = image.convert('RGB')
# draw_objects(ImageDraw.Draw(image), objs, labels)
# # save every image with the name of the model that made the inderence
# output_path = IMG_OUT + '_IMG' + str(index) + '.bmp'
# image.save(output_path)
except Exception as e:
print(e)
def argument_parser(cli = None):
args = argparse.ArgumentParser()
args.add_argument("--mdl", help = "model_path")
if cli is None:
return args.parse_args()
else:
return args.parse_args(cli)
if __name__ == "__main__":
args = argument_parser()
# set labels_file, input and output data paths according to the model
IMG_PATH += "small_subset_COCO17_test"
LABELS_PATH += args.mdl + "/" + "coco_labels.txt"
IMG_OUT += args.mdl
run(args)
However, when running the code I get this error:
root@tda4vm-sk:/opt/luca-TI/my_workfolder# python3 my_tflite_object_detection.py --mdl tf2_ssd_mobilenet_v2_coco17_ptq Number of subgraphs:1 , 102 nodes delegated out of 102 nodes APP: Init ... !!! MEM: Init ... !!! MEM: Initialized DMA HEAP (fd=5) !!! MEM: Init ... Done !!! IPC: Init ... !!! IPC: Init ... Done !!! REMOTE_SERVICE: Init ... !!! REMOTE_SERVICE: Init ... Done !!! 426335.170425 s: GTC Frequency = 200 MHz APP: Init ... Done !!! 426335.170491 s: VX_ZONE_INIT:Enabled 426335.170500 s: VX_ZONE_ERROR:Enabled 426335.170509 s: VX_ZONE_WARNING:Enabled 426335.176348 s: VX_ZONE_INIT:[tivxInitLocal:130] Initialization Done !!! 426335.177419 s: VX_ZONE_INIT:[tivxHostInitLocal:86] Initialization Done for HOST !!! 426335.204276 s: VX_ZONE_ERROR:[ownContextSendCmd:814] Command ack message returned failure cmd_status: -1 426335.204303 s: VX_ZONE_ERROR:[ownContextSendCmd:850] tivxEventWait() failed. 426335.204331 s: VX_ZONE_ERROR:[ownNodeKernelInit:538] Target kernel, TIVX_CMD_NODE_CREATE failed for node TIDLNode 426335.204349 s: VX_ZONE_ERROR:[ownNodeKernelInit:539] Please be sure the target callbacks have been registered for this core 426335.204366 s: VX_ZONE_ERROR:[ownNodeKernelInit:540] If the target callbacks have been registered, please ensure no errors are occurring within the create callback of this kernel 426335.204385 s: VX_ZONE_ERROR:[ownGraphNodeKernelInit:583] kernel init for node 0, kernel com.ti.tidl:1:4 ... failed !!! 426335.204406 s: VX_ZONE_ERROR:[vxVerifyGraph:2055] Node kernel init failed 426335.204424 s: VX_ZONE_ERROR:[vxVerifyGraph:2109] Graph verify failed TIDL_RT_OVX: ERROR: Verifying TIDL graph ... Failed !!! TIDL_RT_OVX: ERROR: Verify OpenVX graph failed Inference at image: 0 named 000000002797.jpg 426335.260163 s: VX_ZONE_ERROR:[ownContextSendCmd:814] Command ack message returned failure cmd_status: -1 426335.260190 s: VX_ZONE_ERROR:[ownContextSendCmd:850] tivxEventWait() failed. 426335.260204 s: VX_ZONE_ERROR:[ownNodeKernelInit:538] Target kernel, TIVX_CMD_NODE_CREATE failed for node TIDLNode 426335.260213 s: VX_ZONE_ERROR:[ownNodeKernelInit:539] Please be sure the target callbacks have been registered for this core 426335.260222 s: VX_ZONE_ERROR:[ownNodeKernelInit:540] If the target callbacks have been registered, please ensure no errors are occurring within the create callback of this kernel 426335.260232 s: VX_ZONE_ERROR:[ownGraphNodeKernelInit:583] kernel init for node 0, kernel com.ti.tidl:1:4 ... failed !!! 426335.260243 s: VX_ZONE_ERROR:[vxVerifyGraph:2055] Node kernel init failed 426335.260253 s: VX_ZONE_ERROR:[vxVerifyGraph:2109] Graph verify failed 426335.260358 s: VX_ZONE_ERROR:[ownGraphScheduleGraphWrapper:820] graph is not in a state required to be scheduled 426335.260368 s: VX_ZONE_ERROR:[vxProcessGraph:755] schedule graph failed 426335.260373 s: VX_ZONE_ERROR:[vxProcessGraph:760] wait graph failed ERROR: Running TIDL graph ... Failed !!! Inference at image: 1 named 000000001439.jpg 426335.284875 s: VX_ZONE_ERROR:[ownContextSendCmd:814] Command ack message returned failure cmd_status: -1 426335.284904 s: VX_ZONE_ERROR:[ownContextSendCmd:850] tivxEventWait() failed. 426335.284916 s: VX_ZONE_ERROR:[ownNodeKernelInit:538] Target kernel, TIVX_CMD_NODE_CREATE failed for node TIDLNode 426335.284925 s: VX_ZONE_ERROR:[ownNodeKernelInit:539] Please be sure the target callbacks have been registered for this core 426335.284933 s: VX_ZONE_ERROR:[ownNodeKernelInit:540] If the target callbacks have been registered, please ensure no errors are occurring within the create callback of this kernel 426335.284943 s: VX_ZONE_ERROR:[ownGraphNodeKernelInit:583] kernel init for node 0, kernel com.ti.tidl:1:4 ... failed !!! 426335.284955 s: VX_ZONE_ERROR:[vxVerifyGraph:2055] Node kernel init failed 426335.284964 s: VX_ZONE_ERROR:[vxVerifyGraph:2109] Graph verify failed 426335.285070 s: VX_ZONE_ERROR:[ownGraphScheduleGraphWrapper:820] graph is not in a state required to be scheduled 426335.285080 s: VX_ZONE_ERROR:[vxProcessGraph:755] schedule graph failed 426335.285113 s: VX_ZONE_ERROR:[vxProcessGraph:760] wait graph failed ERROR: Running TIDL graph ... Failed !!! Inference at image: 2 named 000000000552.jpg 426335.313281 s: VX_ZONE_ERROR:[ownContextSendCmd:814] Command ack message returned failure cmd_status: -1 426335.313309 s: VX_ZONE_ERROR:[ownContextSendCmd:850] tivxEventWait() failed. 426335.313323 s: VX_ZONE_ERROR:[ownNodeKernelInit:538] Target kernel, TIVX_CMD_NODE_CREATE failed for node TIDLNode 426335.313331 s: VX_ZONE_ERROR:[ownNodeKernelInit:539] Please be sure the target callbacks have been registered for this core 426335.313339 s: VX_ZONE_ERROR:[ownNodeKernelInit:540] If the target callbacks have been registered, please ensure no errors are occurring within the create callback of this kernel 426335.313350 s: VX_ZONE_ERROR:[ownGraphNodeKernelInit:583] kernel init for node 0, kernel com.ti.tidl:1:4 ... failed !!! 426335.313361 s: VX_ZONE_ERROR:[vxVerifyGraph:2055] Node kernel init failed 426335.313370 s: VX_ZONE_ERROR:[vxVerifyGraph:2109] Graph verify failed 426335.313473 s: VX_ZONE_ERROR:[ownGraphScheduleGraphWrapper:820] graph is not in a state required to be scheduled 426335.313501 s: VX_ZONE_ERROR:[vxProcessGraph:755] schedule graph failed 426335.313510 s: VX_ZONE_ERROR:[vxProcessGraph:760] wait graph failed ERROR: Running TIDL graph ... Failed !!! Inference at image: 3 named 000000001172.jpg 426335.343777 s: VX_ZONE_ERROR:[ownContextSendCmd:814] Command ack message returned failure cmd_status: -1 426335.343807 s: VX_ZONE_ERROR:[ownContextSendCmd:850] tivxEventWait() failed. 426335.343832 s: VX_ZONE_ERROR:[ownNodeKernelInit:538] Target kernel, TIVX_CMD_NODE_CREATE failed for node TIDLNode 426335.343851 s: VX_ZONE_ERROR:[ownNodeKernelInit:539] Please be sure the target callbacks have been registered for this core 426335.343869 s: VX_ZONE_ERROR:[ownNodeKernelInit:540] If the target callbacks have been registered, please ensure no errors are occurring within the create callback of this kernel 426335.343889 s: VX_ZONE_ERROR:[ownGraphNodeKernelInit:583] kernel init for node 0, kernel com.ti.tidl:1:4 ... failed !!! 426335.343909 s: VX_ZONE_ERROR:[vxVerifyGraph:2055] Node kernel init failed 426335.343926 s: VX_ZONE_ERROR:[vxVerifyGraph:2109] Graph verify failed 426335.344042 s: VX_ZONE_ERROR:[ownGraphScheduleGraphWrapper:820] graph is not in a state required to be scheduled 426335.344052 s: VX_ZONE_ERROR:[vxProcessGraph:755] schedule graph failed 426335.344062 s: VX_ZONE_ERROR:[vxProcessGraph:760] wait graph failed ERROR: Running TIDL graph ... Failed !!! Inference at image: 4 named 000000000535.jpg 426335.377127 s: VX_ZONE_ERROR:[ownContextSendCmd:814] Command ack message returned failure cmd_status: -1 426335.377156 s: VX_ZONE_ERROR:[ownContextSendCmd:850] tivxEventWait() failed. 426335.377168 s: VX_ZONE_ERROR:[ownNodeKernelInit:538] Target kernel, TIVX_CMD_NODE_CREATE failed for node TIDLNode 426335.377178 s: VX_ZONE_ERROR:[ownNodeKernelInit:539] Please be sure the target callbacks have been registered for this core 426335.377186 s: VX_ZONE_ERROR:[ownNodeKernelInit:540] If the target callbacks have been registered, please ensure no errors are occurring within the create callback of this kernel 426335.377196 s: VX_ZONE_ERROR:[ownGraphNodeKernelInit:583] kernel init for node 0, kernel com.ti.tidl:1:4 ... failed !!! 426335.377209 s: VX_ZONE_ERROR:[vxVerifyGraph:2055] Node kernel init failed 426335.377217 s: VX_ZONE_ERROR:[vxVerifyGraph:2109] Graph verify failed 426335.377321 s: VX_ZONE_ERROR:[ownGraphScheduleGraphWrapper:820] graph is not in a state required to be scheduled 426335.377329 s: VX_ZONE_ERROR:[vxProcessGraph:755] schedule graph failed 426335.377339 s: VX_ZONE_ERROR:[vxProcessGraph:760] wait graph failed ERROR: Running TIDL graph ... Failed !!! 426335.378329 s: VX_ZONE_INIT:[tivxHostDeInitLocal:100] De-Initialization Done for HOST !!! 426335.382697 s: VX_ZONE_INIT:[tivxDeInitLocal:193] De-Initialization Done !!! APP: Deinit ... !!! REMOTE_SERVICE: Deinit ... !!! REMOTE_SERVICE: Deinit ... Done !!! IPC: Deinit ... !!! IPC: DeInit ... Done !!! MEM: Deinit ... !!! DDR_SHARED_MEM: Alloc's: 10 alloc's of 7705304 bytes DDR_SHARED_MEM: Free's : 10 free's of 7705304 bytes DDR_SHARED_MEM: Open's : 0 allocs of 0 bytes DDR_SHARED_MEM: Total size: 536870912 bytes MEM: Deinit ... Done !!! APP: Deinit ... Done !!! root@tda4vm-sk:/opt/luca-TI/my_workfolder#
Do you have any idea of why it happens?