I am having trouble with the Jupyter Notebook when I try to follow Tutorial-of-AI-Kit-with-Raspberry-Pi-From-Zero-to-Hero/articles/Chapter 5 - Developing and Deploying a Custom Model

I am proceeding with Jupyter Notebook by referring to Tutorial-of-AI-Kit-with-Raspberry-Pi-From-Zero-to-Hero/articles/Chapter 5 - Developing and Deploying a Custom Model.--------------------------------------------------------------------------------------------- !pip install /home/pi/Downloads/hailo_dataflow_compiler-3.28.0-py3-none-linux_x86_64.whl

Define the model name and onnx model path

onnx_model_name = “yolov11n”
onnx_path = “/home/pi/best20241109.onnx”

AI kit chip is hailo8l, so we choose hailo8l as hardware arch

chosen_hw_arch = “hailo8”

runner = ClientRunner(hw_arch=chosen_hw_arch)
hn, npz = runner.translate_onnx_model(
onnx_path,
onnx_model_name,
start_node_names=[“/model.0/conv/Conv”], # the name of input node
end_node_names=[“/model.23/cv2.0/cv2.0.2/Conv”, “/model.23/cv3.0/cv3.0.2/Conv”,
“/model.23/cv2.1/cv2.1.2/Conv”, “/model.23/cv3.1/cv3.1.2/Conv”,
“/model.23/cv2.2/cv2.2.2/Conv”, “/model.23/cv3.2/cv3.2.2/Conv”], # the name of output node
net_input_shapes={“/model.0/conv/Conv”: [1, 3, 640, 640]}, # input shape
)

Save to har model

hailo_model_har_name = f"/home/pi/{onnx_model_name}_hailo_model.har"
runner.save_har(hailo_model_har_name)

Use hailo command to parse the model *yolov11n.svg 파일생성

!hailo visualizer /home/pi/{onnx_model_name}_hailo_model.har

#최적화

General imports used throughout the tutorial

file operations

import json
import os

import numpy as np
import tensorflow as tf
from IPython.display import SVG
from matplotlib import patches
from matplotlib import pyplot as plt
from PIL import Image
from tensorflow.python.eager.context import eager_mode

import the hailo sdk client relevant classes

from hailo_sdk_client import ClientRunner, InferenceContext

%matplotlib inline

IMAGES_TO_VISUALIZE = 5

#2

The folder of images

image_dir = ‘/home/pi/images’
image_files = [f for f in os.listdir(image_dir) if f.endswith((‘.png’, ‘.jpg’, ‘.jpeg’))]

Init the list

images =

Load every images

for image_file in image_files:
img_path = os.path.join(image_dir, image_file)
img = Image.open(img_path).convert(‘RGB’) # Transform to RGB format
img_array = np.array(img, dtype=object ) # Transform to NumPy format
images.append(img_array)

Transform images to NumPy array

images_array = np.array(images)

#3

Load our parsed HAR model

assert os.path.isfile(hailo_model_har_name), “Please provide valid path for HAR file”
runner = ClientRunner(har=hailo_model_har_name, hw_arch=chosen_hw_arch)

By default it uses the hw_arch that is saved on the HAR. For overriding, use the hw_arch flag.

##4

Call Optimize to perform the optimization process

runner.optimize(images_array)

Save the result state to a Quantized HAR file

quantized_model_har_path = f"/home/pi/{onnx_model_name}_quantized_model.har"

runner.save_har(quantized_model_har_path)

I’ve been running the above codes one by one in the Jupyter notebook. # Save the result state to a Quantized HAR file
quantized_model_har_path = f"/home/pi/{onnx_model_name}_quantized_model.har"
runner.save_har(quantized_model_har_path) When I run this code, the Jupyter notebook freezes. The cause is unknown.Please tell me how to solve the problem.