Skip to content

Commit d22ec33

Browse files
authored
Merge branch 'main' into main
2 parents 1fd38ad + 6519ac5 commit d22ec33

24 files changed

Lines changed: 260 additions & 6 deletions

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ This course is designed to teach you how to harness the power of AI on the Raspb
5454
### For AIoT objects
5555

5656

57-
| Raspberry Pi AI Kit | reComputer R1000 |
57+
| Raspberry Pi AI Kit | reComputer R1100 |
5858
| :----------------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------: |
59-
| ![Raspberry Pi AI Kit](https://media-cdn.seeedstudio.com/media/catalog/product/cache/bb49d3ec4ee05b6f018e93f896b8a25d/2/-/2-113060086-raspberry-pi-ai-kit-all.jpg) | ![reComputer R1000](https://media-cdn.seeedstudio.com/media/catalog/product/cache/bb49d3ec4ee05b6f018e93f896b8a25d/1/1/113991314-2_1.jpeg) |
60-
| [**Purchase Now**](https://www.seeedstudio.com/Raspberry-Pi-AI-Kit-p-5900.html?utm_source=PiAICourse&utm_medium=github&utm_campaign=Course) | [**Purchase Now**](https://www.seeedstudio.com/reComputer-R1035-10-p-5925.html?utm_source=PiAICourse&utm_medium=github&utm_campaign=Course) |
59+
| ![Raspberry Pi AI Kit](https://media-cdn.seeedstudio.com/media/catalog/product/cache/bb49d3ec4ee05b6f018e93f896b8a25d/a/i/ai_hat.jpg) | ![reComputer R1100](https://media-cdn.seeedstudio.com/media/catalog/product/cache/bb49d3ec4ee05b6f018e93f896b8a25d/1/-/1-113991334.jpg) |
60+
| [**Purchase Now**](https://www.seeedstudio.com/Raspberry-Pi-Al-HAT-26-TOPS-p-6243.html?utm_source=PiAICourse&utm_medium=github&utm_campaign=Course) | [**Purchase Now**](https://www.seeedstudio.com/reComputer-R1125-10-p-6256.html?utm_source=PiAICourse&utm_medium=github&utm_campaign=Course) |
6161

6262
## 📚 Recommended Reading
6363

articles/Chapter_5-Custom_Model_Development_and_Deployment/Convert_Your_Model.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"source": [
2222
"# Step 1: Prepare your environment on your host computer\n",
2323
"\n",
24-
"**Note: This part of code run on your host computer**\n",
24+
"**📌 Note:This part of code run on your linux host computer with python3.10**\n",
2525
"\n",
2626
"The Jupyter Notebook right up have a button like ![select kernel](../../pictures/Chapter5/select_kernel.png), then you choose ```Select Another Kernel```, and choose ```Python Environments```, then choose ```Creat Python Environment``` and choose ```Venv```, then choose ```python3.10```."
2727
]
@@ -82,7 +82,7 @@
8282
"source": [
8383
"# Download hailo model zoo to convert onnx model\n",
8484
"try:\n",
85-
" ! git clone https://github.com/hailo-ai/hailo_model_zoo.git\n",
85+
" ! git clone https://github.com/LJ-Hao/hailo_model_zoo.git\n",
8686
"except Exception as e:\n",
8787
" print(f'install error: {e}')"
8888
]

articles/Chapter_5-Custom_Model_Development_and_Deployment/Deploy_Your_Model.ipynb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,13 @@
395395
"# Step 3: Run your model\n"
396396
]
397397
},
398+
{
399+
"cell_type": "markdown",
400+
"metadata": {},
401+
"source": [
402+
"📌 Note: If you meet error like `max_desc_page_size given 16384 is bigger than hw max desc page size 4096` please check this [link](https://community.hailo.ai/t/hailort-error-check-failed-max-desc-page-size-given-16384-is-bigger-than-hw-max-desc-page-size-4096/3690)"
403+
]
404+
},
398405
{
399406
"cell_type": "code",
400407
"execution_count": 7,
Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
# Hailo-Powered Car Park Management with ThingsBoard
2+
3+
This project delivers a custom model for detecting parking possibilities in a car park. The system identifies three classes: available slots, parked slots, and improper parking.
4+
5+
The model was trained using the YOLOv8n framework and deployed on a Raspberry Pi with a Hailo-8L accelerator. The modified code enables real-time parking slot counting and sends MQTT messages to the ThingsBoard IoT platform.
6+
7+
ThingsBoard provides an intuitive interface for data visualization and analysis, making it easy to monitor parking conditions and optimize management.
8+
9+
## Step 1: Data Collection and Labeling
10+
11+
We created a small prototype of a car park to demonstrate the working phenomenon. Using a webcam connected to a Raspberry Pi, we collected images of the parking area. These images were then uploaded to a Roboflow repository for further processing.
12+
13+
The images were labeled into three distinct classes:
14+
15+
- Available
16+
- Parked
17+
- Improper
18+
19+
20+
21+
![license](../../pictures/Chapter6/labeling.PNG)
22+
23+
You can view the project here: [Car Park - Roboflow Repository](https://app.roboflow.com/kasun-thushara-fxbng/car-park-cq0uw/1)
24+
25+
## Step 2: Model Training
26+
27+
We trained a YOLOv8n model using a custom dataset. Roboflow provides a downloadable link for the dataset, which can be used to train the model with YOLOv8n.
28+
29+
![license](../../pictures/Chapter6/roboflowapi.PNG)
30+
31+
After training, the model must be exported to the ONNX format for deployment.
32+
33+
Detailed instructions on model labeling and training can be found in Chapter 5
34+
35+
[How to training the model](https://seeed-projects.github.io/Tutorial-of-AI-Kit-with-Raspberry-Pi-From-Zero-to-Hero/docs/Chapter_5-Custom_Model_Development_and_Deployment/Training_Your_Model)
36+
37+
[How to convert ONNX model to HEF](https://seeed-projects.github.io/Tutorial-of-AI-Kit-with-Raspberry-Pi-From-Zero-to-Hero/docs/Chapter_5-Custom_Model_Development_and_Deployment/Convert_Your_Model)
38+
39+
## Step 3: Deploy the Model
40+
41+
On the Raspberry Pi, after installing Hailo tools, you can test if the detection is working correctly. For MQTT connection, ensure you install the required dependencies in the same virtual environment:
42+
43+
```bash
44+
sudo apt update
45+
sudo apt install -y mosquitto mosquitto-clients
46+
pip install paho-mqtt
47+
```
48+
We modified the detection_pipeline.py script and renamed it as park_object_detection.py. Below is the modified code:
49+
50+
```bash
51+
import gi
52+
gi.require_version('Gst', '1.0')
53+
from gi.repository import Gst, GLib
54+
import os
55+
import numpy as np
56+
import cv2
57+
import hailo
58+
import paho.mqtt.client as mqtt
59+
import json
60+
from hailo_rpi_common import (
61+
get_caps_from_pad,
62+
get_numpy_from_buffer,
63+
app_callback_class,
64+
)
65+
from detection_pipeline import GStreamerDetectionApp
66+
67+
# -----------------------------------------------------------------------------------------------
68+
# User-defined class to be used in the callback function
69+
# -----------------------------------------------------------------------------------------------
70+
class user_app_callback_class(app_callback_class):
71+
def __init__(self):
72+
super().__init__()
73+
self.detection_counts = {
74+
"available": 0,
75+
"parked": 0,
76+
"improper": 0
77+
}
78+
79+
def reset_counts(self):
80+
self.detection_counts = {key: 0 for key in self.detection_counts}
81+
82+
# -----------------------------------------------------------------------------------------------
83+
# MQTT Setup
84+
# -----------------------------------------------------------------------------------------------
85+
BROKER = "192.168.8.195" # ThingsBoard Host-Name
86+
CLIENT_ID = "Car_Park" # The Client ID which you give in the Thingsboard End
87+
PORT = 1883
88+
TOPIC = "v1/devices/me/telemetry" # Topic For Sending data to ThingsBoard
89+
90+
mqtt_client = mqtt.Client(CLIENT_ID)
91+
92+
def setup_mqtt():
93+
mqtt_client.connect(BROKER, PORT, 60)
94+
mqtt_client.loop_start()
95+
96+
def publish_counts(detection_counts):
97+
payload = json.dumps(detection_counts) # Convert counts to JSON format
98+
mqtt_client.publish(TOPIC, payload, qos=1)
99+
print(f"Published: {payload} to topic {TOPIC}")
100+
101+
# -----------------------------------------------------------------------------------------------
102+
# User-defined callback function
103+
# -----------------------------------------------------------------------------------------------
104+
def app_callback(pad, info, user_data):
105+
buffer = info.get_buffer()
106+
if buffer is None:
107+
return Gst.PadProbeReturn.OK
108+
109+
user_data.reset_counts()
110+
roi = hailo.get_roi_from_buffer(buffer)
111+
detections = roi.get_objects_typed(hailo.HAILO_DETECTION)
112+
113+
for detection in detections:
114+
label = detection.get_label()
115+
if label in user_data.detection_counts:
116+
user_data.detection_counts[label] += 1
117+
118+
publish_counts(user_data.detection_counts)
119+
print(f"Detection Counts: {user_data.detection_counts}")
120+
121+
return Gst.PadProbeReturn.OK
122+
123+
# -----------------------------------------------------------------------------------------------
124+
# Main
125+
# -----------------------------------------------------------------------------------------------
126+
if __name__ == "__main__":
127+
setup_mqtt()
128+
user_data = user_app_callback_class()
129+
app = GStreamerDetectionApp(app_callback, user_data)
130+
131+
try:
132+
app.run()
133+
except KeyboardInterrupt:
134+
print("Shutting down...")
135+
finally:
136+
mqtt_client.loop_stop()
137+
mqtt_client.disconnect()
138+
139+
```
140+
141+
## Step 4: Install ThingsBoard and Add a Device
142+
143+
[ThingsBoard](https://thingsboard.io/) is an open-source IoT platform designed for device management, data collection, processing, and visualization. It supports various communication protocols such as **MQTT, CoAP, and HTTP**, making it versatile for integrating IoT devices and systems. The platform enables users to **create interactive dashboards, monitor devices in real-time, and analyze data through advanced visualization tools. With its rule engine, ThingsBoard automates workflows and event processing**, simplifying the implementation of IoT use cases across industries. Its scalability and flexibility make it suitable for projects of any size, from small prototypes to large-scale deployments.Additionally, you can use their [cloud solution](https://thingsboard.io/products/paas/) for easier deployment and management.
144+
145+
146+
147+
We have provided instructions on [installing the ThingsBoard Community Edition](https://wiki.seeedstudio.com/recomputer_r1000_thingsboard_ce/) and the Edge version. You can refer to this wiki lesson for guidance.
148+
149+
150+
## Step 5: Provision a Device
151+
152+
1. Navigate to the **Devices** page under the **Entities** section.
153+
154+
![tb1](../../pictures/Chapter6/tb1.png)
155+
156+
2. Click the **'+'** icon in the top right corner of the table and select **'Add new device'** from the drop-down menu.
157+
158+
![tb2](../../pictures/Chapter6/tb2.png)
159+
160+
3. Enter the **device name**, **Client ID**, **Password**, and **Username**.
161+
Since this is a demo, we have not added a username or password when creating the device.
162+
163+
4. Click **Add**.
164+
165+
![tb3](../../pictures/Chapter6/tb3.png)
166+
167+
5. As you add more devices, they will appear at the top of the table. The table automatically sorts devices by creation time, with the newest ones listed first.
168+
169+
![tb5](../../pictures/Chapter6/tb5.png)
170+
171+
172+
## Step 6: Connect the Device
173+
174+
1. Click on your device and then click the **Check connectivity** button in the **Device details** window.
175+
![tb6](../../pictures/Chapter6/tb6.png)
176+
177+
2. In the opened window, select the messaging protocol and your operating system:
178+
- **Operating System:** Linux
179+
- **Protocol:** MQTT
180+
181+
![tb7](../../pictures/Chapter6/tb7.png)
182+
183+
3. Make sure to install the required client tools.
184+
4. Execute the copied command. Once the temperature readings are published successfully, the device state will change from **"Inactive"** to **"Active"**. You will also see the published temperature readings.
185+
186+
![tb8](../../pictures/Chapter6/tb8.png)
187+
188+
## Step 7: Run the Detection Code
189+
190+
```bash
191+
cd hailo-rpi5-examples
192+
193+
source setup_env.sh
194+
195+
cd basic_pipelines
196+
197+
python park_object_detection.py --labels-json /home/pi/Desktop/hailo-custom/config.json --hef-path /home/pi/Desktop/hailo-custom/yolov8n_renamed_carpark.hef -i /dev/video0
198+
```
199+
200+
## Step 8: Create a Dashboard
201+
### Create an Empty Dashboard
202+
1. Navigate to the Dashboards page from the main menu on the left side of the screen.
203+
204+
205+
2. Click the `+` sign in the upper right corner of the screen and select 'Create new dashboard' from the drop-down menu.
206+
![tb9](../../pictures/Chapter6/tb9.png)
207+
3. In the dialog box, enter a title for the dashboard (the description is optional).
208+
209+
4. Click Add.
210+
![tb10](../../pictures/Chapter6/tb10.png)
211+
5. After creating the dashboard, it will open automatically, and you can start adding widgets.
212+
6. To save the dashboard, click the Save button in the upper right corner.
213+
![tb11](../../pictures/Chapter6/tb11.png)
214+
215+
7. Your first dashboard is now created. As you add more dashboards, they will appear at the top of the list, sorted by the creation timestamp.
216+
217+
![tb12](../../pictures/Chapter6/tb12.png)
218+
219+
220+
221+
### Add a Chart Widget
222+
1. Enter edit mode and click the `Add new widget` button at the top of the screen.
223+
![tb13](../../pictures/Chapter6/tb13.png)
224+
![tb14](../../pictures/Chapter6/tb14.png)
225+
226+
2. Find the `Charts` widget bundle and click on it.
227+
![tb15](../../pictures/Chapter6/tb15.png)
228+
229+
3. Select the `Time series chart` widget.
230+
![tb16](../../pictures/Chapter6/tb16.png)
231+
232+
4. In the `Device` field, specify the device you created earlier as the data source.
233+
5. In the `Series` section, enter the data key `Available`,`Park`,`Improper` to monitor the car park related values of a device.
234+
![tb16](../../pictures/Chapter6/tb_chart.png)
235+
236+
6. Resize the widget and apply the changes.
237+
7. Click Add.
238+
239+
You can explore additional [dashboard widgets](https://thingsboard.io/docs/user-guide/dashboards/) in the system.
240+
241+
242+
243+
## Demo
244+
245+
![demo](../../pictures/Chapter6/demo-thingsboard.gif)
246+
247+

articles/Chapter_6-RaspberryPi_and_AIoT/Smart_Retail_with_reComputerR11_and_AIkit.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,4 @@ And then, import flows like below:
117117

118118
We use the Raspberry Pi to accelerate EfficientNet for intrusion detection in storage rooms through object recognition. Meanwhile, the AI Kit is used to accelerate the YOLOv8 model for object detection to determine the quantity of goods on the shelves.
119119

120-
<iframe width="1273" height="716" src="https://www.youtube.com/embed/Sd5J5k863Vs" title="Making Next Gadget: Master AI with Raspberry Pi, Power Smart Retail Solutions" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
120+
<iframe width="800" height="400" src="https://www.youtube.com/embed/Sd5J5k863Vs" title="Making Next Gadget: Master AI with Raspberry Pi, Power Smart Retail Solutions" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
25 MB
Loading

pictures/Chapter6/labeling.PNG

764 KB
Loading

pictures/Chapter6/roboflowapi.PNG

41 KB
Loading

pictures/Chapter6/tb1.png

132 KB
Loading

pictures/Chapter6/tb10.png

54.6 KB
Loading

0 commit comments

Comments
 (0)