<jupyter_start><jupyter_text>Setup<jupyter_code>%pip install onnxruntime
%pip install tflite2onnx
!wget https://github.com/google/mediapipe/raw/master/mediapipe/modules/palm_detection/palm_detection.tflite
!wget https://i.imgur.com/fYsTA9m.png
!wget https://i.imgur.com/NPlc2z8.png
!wget https://i.imgur.com/BfpQ0FF.png
!tflite2onnx palm_detection.tflite palm_detection.onnx<jupyter_output>ONNX model path (palm_detection.onnx) existed!
Empty tensor used, please double confirm your code path!
Empty tensor used, please double confirm your code path!<jupyter_text>Inference<jupyter_code>import cv2
img = cv2.imread('fYsTA9m.png')
#img = cv2.imread('NPlc2z8.png')
#img = cv2.imread('BfpQ0FF.png')
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
tensor = (img / 127.5 - 1.0).reshape((1, 128, 128, 3)).transpose(0, 3, 1, 2)
import numpy as np
import onnxruntime as rt
sess = rt.InferenceSession('palm_detection.onnx')
pred = sess.run(None, {'input': tensor.astype(np.float32)})<jupyter_output><empty_output><jupyter_text>Visualization<jupyter_code>def sigmoid(x):
  return 1 / (1 + np.exp(-x))

def draw_patch(regressor, classificator, stride, anchor_count, column, row, anchor, offset, color):
  index = (int(row * 128 / stride) + column) * anchor_count + anchor + offset

  score = sigmoid(regressor[index][0])
  if score < 0.5: return

  x, y, w, h = classificator[index][:4]

  x += (column + 0.5) * stride - w / 2
  y += (row    + 0.5) * stride - h / 2

  rect = patches.Rectangle((x, y), w, h, color = color, fill = None)
  ax.add_patch(rect)

  for key in range(7):
    x = classificator[index][4 + key * 2]
    y = classificator[index][5 + key * 2]
    
    x += (column + 0.5) * stride
    y += (row    + 0.5) * stride
    
    rect = patches.Rectangle((x, y), 1, 1, facecolor = color)
    ax.add_patch(rect)
import matplotlib.pyplot as plt
import matplotlib.patches as patches

fig, ax = plt.subplots(1, figsize=(10, 10))
ax.imshow(img)

for y in range(16):
  for x in range(16):
    for a in range(2):
      draw_patch(pred[1][0], pred[0][0], 8, 2, x, y, a, 0, 'r')

for y in range(8):
  for x in range(8):
    for a in range(6):
      draw_patch(pred[1][0], pred[0][0], 16, 6, x, y, a, 512, 'b')

plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1575189647478804, 'fraction_numerical': 0.041499330655957165, 'mean_word_length': 4.2018561484918795, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 12, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '546942', 'license': 'MIT', 'n_tokens_mistral': 964, 'n_tokens_neox': 903, 'n_words': 214, 'path': 'BlazePalm_ONNX_Inference_Test.ipynb', 'repo_name': 'JayDown/3d-converter', 'size': '2241'}