Hi, i have trained a yolov8m-seg model and converted it to tflite.I want to run it on mobile device. i read this thread and it partially helping me understanding the output of the model but still im not able to draw bounding box nor extract mask from the output.
below are the input and output details
Input details:
[{'name': 'inputs_0', 'index': 0, 'shape': array([ 1, 640, 640, 3], dtype=int32), 'shape_signature': array([ 1, 640, 640, 3], dtype=int32), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}]
Output details:
[{'name': 'Identity', 'index': 583, 'shape': array([ 1, 37, 8400], dtype=int32), 'shape_signature': array([ 1, 37, 8400], dtype=int32), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}, {'name': 'Identity_1', 'index': 436, 'shape': array([ 1, 160, 160, 32], dtype=int32), 'shape_signature': array([ 1, 160, 160, 32], dtype=int32), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}]
following code is to draw bounding box on image.
# Load the TFLite model
interpreter = tf.lite.Interpreter(model_path='best_float32.tflite')
interpreter.allocate_tensors()
# Get input and output tensors.
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
image = cv2.imread("21.png")
image = cv2.resize(image, (640,640))
cv2_imshow(image)
image = np.array(image).astype('float32') / 255.0
# Set input tensor
input_shape = input_details[0]['shape']
input_data = np.array(image.reshape(input_shape), dtype=np.float32)
interpreter.set_tensor(input_details[0]['index'], input_data)
# Run inference
interpreter.invoke()
# # Get the output tensor values
output_data1 = interpreter.get_tensor(output_details[0]['index'])
output_data2 = interpreter.get_tensor(output_details[1]['index'])
output_tensor = output_data1.reshape(8400,37) # Reshape the tensor based on the output shape
H = image.shape[0]
W = image.shape[1]
for i in range(len(output_tensor)):
xPos,yPos,w,h=output_tensor[i][0:4]
scores=output_tensor[i][4:5]
if scores>0 and scores<1:
xmin = int(max(1, xPos - w / 2))
ymin = int(max(1, yPos - h / 2))
xmax = int(min(H, xPos + w / 2))
ymax = int(min(W,yPos + h / 2))
cv2.rectangle(image, (xmin,ymin), (xmax,ymax), (0, 255, 0), 2)
cv2_imshow(image)
output image:
