Skip to content

Commit da60e32

Browse files
committed
add yolo-world APP and optimize apps' ret button size
1 parent f70a927 commit da60e32

File tree

28 files changed

+614
-81
lines changed

28 files changed

+614
-81
lines changed

projects/app_benchmark/benchmarks/benchmark_npu.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,22 @@ def benchmark_forward_img(self, items):
7373
test_items = []
7474
path_11n = "/root/models/yolo11n.mud"
7575
path_11s = "/root/models/yolo11s.mud"
76+
path_11n_640 = "/root/models/yolo11n_640.mud"
77+
path_11s_640 = "/root/models/yolo11s_640.mud"
78+
path_11l_640 = "/root/models/yolo11l_640.mud"
7679
path_5s = "/root/models/yolov5s.mud"
7780
path_mbn = "/root/models/mobilenetv2.mud"
7881
detect_img = "/maixapp/share/picture/2024.1.1/test_coco_640.jpg"
7982
clssify_img = "/maixapp/share/picture/2024.1.1/cat.jpg"
8083
test_items.append((path_11n, detect_img))
8184
if os.path.exists(path_11s):
8285
test_items.append((path_11s, detect_img))
86+
if os.path.exists(path_11n_640):
87+
test_items.append((path_11n_640, detect_img))
88+
if os.path.exists(path_11s_640):
89+
test_items.append((path_11s_640, detect_img))
90+
if os.path.exists(path_11l_640):
91+
test_items.append((path_11l_640, detect_img))
8392
test_items.append((path_5s, detect_img))
8493
test_items.append((path_mbn, clssify_img))
8594

projects/app_benchmark/benchmarks/benchmark_stress.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,10 @@ def run(self):
105105
def update_res_vars():
106106
if self.cam.height() > 480:
107107
self.font_scale = 2.2
108+
self.font_thickness = 2
108109
else:
109110
self.font_scale = 1.4
111+
self.font_thickness = 1
110112
self.font_size = image.string_size("aA!~?/", scale = self.font_scale)
111113
self.ai_isp_on = app.get_sys_config_kv("npu", "ai_isp", "0")
112114
self.font_margin = self.font_size.height() // 2
@@ -123,7 +125,6 @@ def update_res_vars():
123125
back_rect = [0, 0, self.img_back.width() + self.button_padding_2x, self.img_back.height() + self.button_padding_2x]
124126
self.back_rect_disp = image.resize_map_pos(self.cam.width(), self.cam.height(), self.disp.width(), self.disp.height(), image.Fit.FIT_CONTAIN, back_rect[0], back_rect[1], back_rect[2], back_rect[3])
125127
self.string_cam_res_rect_disp = image.resize_map_pos(self.cam.width(), self.cam.height(), self.disp.width(), self.disp.height(), image.Fit.FIT_CONTAIN, self.string_cam_res_rect[0], self.string_cam_res_rect[1], self.string_cam_res_rect[2], self.string_cam_res_rect[3])
126-
print(back_rect, self.back_rect_disp, self.cam.width(), self.cam.height(), self.disp.width(), self.disp.height())
127128
update_res_vars()
128129
touch_pressed = False
129130
cam_res_curr_idx = 0
@@ -187,6 +188,9 @@ def update_res_vars():
187188
last = (x, y)
188189
last_fps = (x, y2)
189190
x += padding
191+
msg = f"{cpu_temp:3.1f} C"
192+
msg_size = image.string_size(msg, scale=self.font_scale)
193+
img.draw_string(last[0] - msg_size.width() - 2, last[1] - msg_size.height() - 2, msg, image.COLOR_RED, scale=self.font_scale, thickness=2)
190194

191195
img.draw_image(0, 0, self.img_back)
192196
img.draw_rect(self.string_cam_res_rect[0], self.string_cam_res_rect[1], self.string_cam_res_rect[2], self.string_cam_res_rect[3], image.COLOR_WHITE)

projects/app_benchmark/main.py

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,23 +104,34 @@ def run(self):
104104
print("run item", self.runing_case_obj.name)
105105
show, img = self.runing_case_obj.run()
106106
print(f"run item {self.runing_case_obj.name} end")
107-
del self.runing_case_obj
108-
self.runing_case_obj = None
109-
gc.collect()
110107
# show result
111108
if show:
112109
print("show result, press any key to exit")
113110
self.showing_result = True
114-
self.disp.show(img)
115-
while self.showing_result:
116-
x, y, preesed = ts.read()
117-
if preesed:
118-
touch_pressed = True
119-
elif touch_pressed:
120-
touch_pressed = False
121-
self.showing_result = False
122-
break
123-
time.sleep_ms(50)
111+
idx = -1
112+
if isinstance(img, (list, tuple)):
113+
idx = 0
114+
while self.showing_result and not app.need_exit():
115+
img0 = img[idx] if idx>=0 else img
116+
self.disp.show(img0)
117+
save_path = f"/root/benchmark_result_{self.runing_case_obj.name}_{max(0, idx)}.png"
118+
print(f"save to {save_path}")
119+
img0.save(save_path)
120+
while self.showing_result:
121+
x, y, preesed = ts.read()
122+
if preesed:
123+
touch_pressed = True
124+
elif touch_pressed:
125+
touch_pressed = False
126+
if idx >= 0 and idx < len(img):
127+
idx += 1
128+
continue
129+
self.showing_result = False
130+
break
131+
time.sleep_ms(50)
132+
del self.runing_case_obj
133+
self.runing_case_obj = None
134+
gc.collect()
124135

125136
program = Program(disp)
126137
try:

projects/app_face_emotion/main.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@
1111
def is_in_button(x, y, btn_pos):
1212
return x > btn_pos[0] and x < btn_pos[0] + btn_pos[2] and y > btn_pos[1] and y < btn_pos[1] + btn_pos[3]
1313

14+
def get_back_btn_img(width):
15+
ret_width = int(width * 0.1)
16+
img_back = image.load("/maixapp/share/icon/ret.png")
17+
w, h = (ret_width, img_back.height() * ret_width // img_back.width())
18+
if w % 2 != 0:
19+
w += 1
20+
if h % 2 != 0:
21+
h += 1
22+
img_back = img_back.resize(w, h)
23+
return img_back
24+
1425
def main(disp):
1526
global curr_model
1627

@@ -28,19 +39,25 @@ def main(disp):
2839
classifier = nn.Classifier(model=models[models_keys[curr_model]], dual_buff=False)
2940
cam = camera.Camera(detector.input_width(), detector.input_height(), detector.input_format())
3041

42+
font_scale = 2 if cam.height() >= 480 else 1.2
43+
font_thickness = 2 if cam.height() >= 480 else 1
44+
str_size = image.string_size("A", scale=font_scale, thickness=font_thickness)
45+
str_w = str_size.width()
46+
str_h = str_size.height()
47+
3148
mode_pressed = False
3249
ts = touchscreen.TouchScreen()
33-
img_back = image.load("/maixapp/share/icon/ret.png")
34-
back_rect = [0, 0, 32, 32]
35-
mode_rect = [0, cam.height() - 26, image.string_size(models_keys[curr_model]).width() + 6, 30]
50+
img_back = get_back_btn_img(cam.width())
51+
back_rect = [0, 0, img_back.width(), img_back.height()]
52+
mode_rect = [0, cam.height() - int(str_h * 2), image.string_size(models_keys[curr_model], scale=font_scale, thickness=font_thickness).width() + 6, int(str_h * 2)]
3653
back_rect_disp = image.resize_map_pos(cam.width(), cam.height(), disp.width(), disp.height(), image.Fit.FIT_CONTAIN, back_rect[0], back_rect[1], back_rect[2], back_rect[3])
3754
mode_rect_disp = image.resize_map_pos(cam.width(), cam.height(), disp.width(), disp.height(), image.Fit.FIT_CONTAIN, mode_rect[0], mode_rect[1], mode_rect[2], mode_rect[3])
3855

3956

4057
# for draw result info
4158
max_labels_length = 0
4259
for label in classifier.labels:
43-
size = image.string_size(label)
60+
size = image.string_size(label, scale=font_scale, thickness=font_thickness)
4461
if size.width() > max_labels_length:
4562
max_labels_length = size.width()
4663

@@ -73,18 +90,18 @@ def main(disp):
7390
for j in range(len(classifier.labels)):
7491
idx = res[j][0]
7592
score = res[j][1]
76-
img.draw_string(0, img_std_first.height() + idx * 16, classifier.labels[idx], image.COLOR_WHITE)
77-
img.draw_rect(max_labels_length, int(img_std_first.height() + idx * 16), int(score * max_score_length), 8, image.COLOR_GREEN if score >= emotion_conf_th else image.COLOR_RED, -1)
78-
img.draw_string(int(max_labels_length + score * max_score_length + 2), int(img_std_first.height() + idx * 16), f"{score:.1f}", image.COLOR_RED)
93+
img.draw_string(0, img_std_first.height() + idx * str_h, classifier.labels[idx], image.COLOR_WHITE, font_scale, font_thickness)
94+
img.draw_rect(max_labels_length, int(img_std_first.height() + idx * str_h), int(score * max_score_length), 8, image.COLOR_GREEN if score >= emotion_conf_th else image.COLOR_RED, -font_thickness)
95+
img.draw_string(int(max_labels_length + score * max_score_length + 2), int(img_std_first.height() + idx * str_h), f"{score:.1f}", image.COLOR_RED, font_scale, font_thickness)
7996
# draw on all face
8097
color = image.COLOR_GREEN if res[0][1] >= emotion_conf_th else image.COLOR_RED
8198
obj = objs[idxes[i]]
8299
img.draw_rect(obj.x, obj.y, obj.w, obj.h, color, 1)
83-
img.draw_string(obj.x, obj.y, f"{classifier.labels[res[0][0]]}: {res[0][1]:.1f}", color)
100+
img.draw_string(obj.x, obj.y, f"{classifier.labels[res[0][0]]}: {res[0][1]:.1f}", color, font_scale, font_thickness)
84101

85102
img.draw_image(0, 0, img_back)
86103
img.draw_rect(mode_rect[0], mode_rect[1], mode_rect[2], mode_rect[3], image.COLOR_WHITE)
87-
img.draw_string(4, img.height() - 20, f"{models_keys[curr_model]}")
104+
img.draw_string(4, img.height() - str_h - str_h // 2, f"{models_keys[curr_model]}", scale=font_scale, thickness=font_thickness)
88105
disp.show(img)
89106
x, y, preesed = ts.read()
90107
if preesed:
@@ -97,8 +114,8 @@ def main(disp):
97114
curr_model = (curr_model + 1) % len(models_keys)
98115
msg = "switching model ..."
99116
size = image.string_size(msg, scale=1.3)
100-
img.draw_string((img.width() - size.width()) // 2, (img.height() - size.height())//2, msg, image.COLOR_RED, scale=1.3, thickness=-3)
101-
img.draw_string((img.width() - size.width()) // 2, (img.height() - size.height())//2, msg, image.COLOR_WHITE, scale=1.3)
117+
img.draw_string((img.width() - size.width()) // 2, (img.height() - size.height())//2, msg, image.COLOR_RED, font_scale, int(font_thickness*2))
118+
img.draw_string((img.width() - size.width()) // 2, (img.height() - size.height())//2, msg, image.COLOR_WHITE, font_scale, font_thickness)
102119
disp.show(img)
103120
del detector
104121
del landmarks_detector
@@ -111,6 +128,7 @@ def main(disp):
111128
except Exception:
112129
import traceback
113130
msg = traceback.format_exc()
131+
print(msg)
114132
img = image.Image(disp.width(), disp.height())
115133
img.draw_string(0, 0, msg, image.COLOR_WHITE)
116134
disp.show(img)

projects/app_face_landmarks/main.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ def get_sub_landmarks(points, points_z, idxes):
3737
def is_in_button(x, y, btn_pos):
3838
return x > btn_pos[0] and x < btn_pos[0] + btn_pos[2] and y > btn_pos[1] and y < btn_pos[1] + btn_pos[3]
3939

40+
def get_back_btn_img(width):
41+
ret_width = int(width * 0.1)
42+
img_back = image.load("/maixapp/share/icon/ret.png")
43+
w, h = (ret_width, img_back.height() * ret_width // img_back.width())
44+
if w % 2 != 0:
45+
w += 1
46+
if h % 2 != 0:
47+
h += 1
48+
img_back = img_back.resize(w, h)
49+
return img_back
50+
4051
def main(disp):
4152
global curr_sub
4253

@@ -57,8 +68,8 @@ def main(disp):
5768
cam = camera.Camera(detector.input_width(), detector.input_height(), detector.input_format())
5869

5970
ts = touchscreen.TouchScreen()
60-
img_back = image.load("/maixapp/share/icon/ret.png")
61-
back_rect = [0, 0, 32, 32]
71+
img_back = get_back_btn_img(cam.width())
72+
back_rect = [0, 0, img_back.width(), img_back.height()]
6273
mode_rect = [0, cam.height() - 26, 100, 30]
6374
back_rect_disp = image.resize_map_pos(cam.width(), cam.height(), disp.width(), disp.height(), image.Fit.FIT_CONTAIN, back_rect[0], back_rect[1], back_rect[2], back_rect[3])
6475
mode_rect_disp = image.resize_map_pos(cam.width(), cam.height(), disp.width(), disp.height(), image.Fit.FIT_CONTAIN, mode_rect[0], mode_rect[1], mode_rect[2], mode_rect[3])
@@ -102,6 +113,7 @@ def main(disp):
102113
except Exception:
103114
import traceback
104115
msg = traceback.format_exc()
116+
print(msg)
105117
img = image.Image(disp.width(), disp.height())
106118
img.draw_string(0, 0, msg, image.COLOR_WHITE)
107119
disp.show(img)

projects/app_face_recognizer/main.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@
44
pressed_flag = [False, False, False]
55
learn_id = 0
66

7+
def get_back_btn_img(width):
8+
ret_width = int(width * 0.1)
9+
img_back = image.load("/maixapp/share/icon/ret.png")
10+
w, h = (ret_width, img_back.height() * ret_width // img_back.width())
11+
if w % 2 != 0:
12+
w += 1
13+
if h % 2 != 0:
14+
h += 1
15+
img_back = img_back.resize(w, h)
16+
return img_back
17+
718
def main(disp):
819
global pressed_flag, learn_id
920
img = image.Image(disp.width(), disp.height())
@@ -115,6 +126,7 @@ def on_touch(x, y, pressed):
115126
except Exception:
116127
import traceback
117128
msg = traceback.format_exc()
129+
print(msg)
118130
img = image.Image(disp.width(), disp.height())
119131
img.draw_string(0, 0, msg, image.COLOR_WHITE)
120132
disp.show(img)

projects/app_face_tracking/main.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,21 @@ def __init__(self, out_range:float, ignore_limit:float, path:str):
2222
self.roll = 0
2323
self.out_range = out_range
2424
self.ignore = ignore_limit
25-
25+
2626
### Self.w and self.h must be initialized.
2727
self.detector = nn.Retinaface(model=path)
2828
self.w = self.detector.input_width()
2929
self.h = self.detector.input_height()
3030
self.cam = camera.Camera(self.w, self.h)
3131
self.disp = display.Display()
32-
32+
3333
### The following section is used as an opt-out and normally you do not need to modify it.
3434
self.ts = touchscreen.TouchScreen()
3535
self.img_exit = image.load("./assets/exit.jpg").resize(40, 40)
3636
self.img_exit_touch = image.load("./assets/exit_touch.jpg").resize(40, 40)
3737
self.box = [0, 0, self.img_exit.width(), self.img_exit.height()]
3838
self.need_exit = False
39-
39+
4040
def __check_touch_box(self, t, box, oft = 0):
4141
"""This method is used for exiting and you normally do not need to modify or call it.
4242
You usually don't need to modify it.
@@ -45,7 +45,7 @@ def __check_touch_box(self, t, box, oft = 0):
4545
return True
4646
else:
4747
return False
48-
48+
4949
def __exit_listener(self, img):
5050
"""Exit case detection methods.
5151
It also draws the Exit button in the upper left corner.
@@ -60,7 +60,7 @@ def __exit_listener(self, img):
6060
self.need_exit = True
6161
else:
6262
img.draw_image(self.box[0], self.box[1], self.img_exit)
63-
63+
6464
def is_need_exit(self):
6565
"""Queries whether the exit button has been pressed.
6666
You usually don't need to modify it.
@@ -69,14 +69,14 @@ def is_need_exit(self):
6969
bool: Returns true if the exit button has been pressed, false otherwise.
7070
"""
7171
return self.need_exit
72-
72+
7373
def __get_target(self):
7474
"""Get the coordinate value of the target.
7575
The behavior of this function needs to be customized.
7676
Returns:
7777
int, int: If no target is found, return -1,-1.
7878
If the target is found, return the coordinate values x,y of the center point of the target.
79-
"""
79+
"""
8080
ltime = time.ticks_ms()
8181
img = self.cam.read() # Reads an image frame.
8282
objs = self.detector.detect(img, conf_th = 0.4, iou_th = 0.45) # Recognition.
@@ -111,25 +111,25 @@ def get_target_err(self):
111111
if abs(self.roll) < self.out_range*self.ignore:
112112
self.roll = 0
113113
return self.pitch, self.roll
114-
114+
115115

116116
if __name__ == '__main__':
117-
ROLL_PWM_PIN_NAME = "A17"
117+
ROLL_PWM_PIN_NAME = "A17"
118118
PITCH_PWM_PIN_NAME = "A16"
119119
init_pitch = 80 # init position, value: [0, 100], means minimum angle to maxmum angle of servo
120120
init_roll = 50 # 50 means middle
121121
PITCH_DUTY_MIN = 3.5 # The minimum duty cycle corresponding to the range of motion of the y-axis servo.
122122
PITCH_DUTY_MAX = 9.5 # Maximum duty cycle corresponding to the y-axis servo motion range.
123123
ROLL_DUTY_MIN = 2.5 # Minimum duty cycle for x-axis servos.
124124
ROLL_DUTY_MAX = 12.5 # Maxmum duty cycle for x-axis servos.
125-
125+
126126
pitch_pid = [0.3, 0.0001, 0.0018, 0] # [P I D I_max]
127127
roll_pid = [0.3, 0.0001, 0.0018, 0] # [P I D I_max]
128128
target_err_range = 10 # target error output range, default [0, 10]
129129
target_ignore_limit = 0.08 # when target error < target_err_range*target_ignore_limit , set target error to 0
130130
pitch_reverse = False # reverse out value direction
131131
roll_reverse = True # reverse out value direction
132-
132+
133133
target = Target(target_err_range, target_ignore_limit, MODEL)
134134
try:
135135
roll = servos.Servos(ROLL_PWM_PIN_NAME, init_roll, ROLL_DUTY_MIN, ROLL_DUTY_MAX)
@@ -145,17 +145,17 @@ def get_target_err(self):
145145
time.sleep(1)
146146
wait_time_s -= 1
147147
exit(-1)
148-
148+
149149
pid_pitch = servos.PID(p=pitch_pid[0], i=pitch_pid[1], d=pitch_pid[2], imax=pitch_pid[3])
150150
pid_roll = servos.PID(p=roll_pid[0], i=roll_pid[1], d=roll_pid[2], imax=roll_pid[3])
151151
gimbal = servos.Gimbal(pitch, pid_pitch, roll, pid_roll)
152-
152+
153153
total_uesd_time = 0
154154
total_fps = 0
155155
t0 = time.ticks_ms()
156156
while not target.is_need_exit():
157157
ltime = time.ticks_ms()
158-
158+
159159
# get target error
160160
err_pitch, err_roll = target.get_target_err()
161161
# interval limit to >= 10ms
125 Bytes
Loading

projects/app_hand_landmarks/app.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
id: hand_landmarks
22
name: Hand Landmarks
33
name[zh]: 手关键点
4-
version: 1.0.1
4+
version: 1.0.2
55
author: Neucrack@Sipeed
66
icon: icon.png
77
desc: Hand Landmarks detect hand keypoints

0 commit comments

Comments
 (0)