lili24 commited on
Commit
a78cd5c
·
verified ·
1 Parent(s): e9b6c4c

Upload folder using huggingface_hub

Browse files
check_size.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+
3
+ # 你的文件路径(注意:WSL 用 /mnt/d/...)
4
+ jpg_path = "/mnt/d/mysite/SamVG/Dataset/rico/2/unique_uis/combined/54.jpg"
5
+ png_path = "/mnt/d/mysite/SamVG/Dataset/rico/2/rico_dataset_v0.1_semantic_annotations/semantic_annotations/54.png"
6
+
7
+ def print_size(path):
8
+ img = cv2.imread(path)
9
+ if img is None:
10
+ print(f"❌ Cannot read image: {path}")
11
+ return
12
+ h, w = img.shape[:2]
13
+ print(f"{path} ---> {w} × {h}")
14
+
15
+ print("\n--- Image Sizes ---")
16
+ print_size(jpg_path)
17
+ print_size(png_path)
get_yolo_dataset.py ADDED
@@ -0,0 +1,221 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import json
3
+ from typing import Dict, Any, List
4
+
5
+ import cv2
6
+ from tqdm import tqdm
7
+
8
+
9
+ # ---------- 路径配置:按你当前工程来的 ----------
10
+ # 原始 UI screenshot(combined)
11
+ SCREENSHOT_DIR = "/mnt/d/mysite/SamVG/Dataset/rico/2/unique_uis/combined"
12
+
13
+ # semantic annotation 路径(含 *.json 和 *.png)
14
+ SEM_DIR = "/mnt/d/mysite/SamVG/Dataset/rico/2/rico_dataset_v0.1_semantic_annotations/semantic_annotations"
15
+
16
+ # YOLO 输出根目录(最终训练数据集就在这里)
17
+ OUT_ROOT = "/mnt/d/mysite/SamVG/Dataset/rico/yolo_icon_full"
18
+
19
+ OUT_IMAGES = os.path.join(OUT_ROOT, "images")
20
+ OUT_LABELS = os.path.join(OUT_ROOT, "labels")
21
+ OUT_VIS = os.path.join(OUT_ROOT, "vis")
22
+
23
+
24
+ def ensure_dirs():
25
+ os.makedirs(OUT_IMAGES, exist_ok=True)
26
+ os.makedirs(OUT_LABELS, exist_ok=True)
27
+ os.makedirs(OUT_VIS, exist_ok=True)
28
+
29
+
30
+ def collect_icon_nodes(node: Dict[str, Any]) -> List[Dict[str, Any]]:
31
+ """
32
+ 递归收集所有 componentLabel == 'Icon' 的节点
33
+ 这里直接使用 semantic json 的结构
34
+ """
35
+ icons = []
36
+ if isinstance(node, dict):
37
+ if node.get("componentLabel") == "Icon":
38
+ icons.append(node)
39
+ for ch in node.get("children", []):
40
+ icons.extend(collect_icon_nodes(ch))
41
+ return icons
42
+
43
+
44
+ def visualize_icons(image, icons, save_path):
45
+ """
46
+ 可视化函数:仅用于人工抽查,
47
+ 在 image 上画出 icon 的框和简单文字
48
+ """
49
+ vis = image.copy()
50
+ font = cv2.FONT_HERSHEY_SIMPLEX
51
+ color = (0, 0, 255)
52
+
53
+ h, w = vis.shape[:2]
54
+
55
+ for node in icons:
56
+ bounds = node.get("bounds")
57
+ if not bounds or len(bounds) != 4:
58
+ continue
59
+ x1, y1, x2, y2 = bounds
60
+
61
+ # 转 int + 简单裁剪,防止越界
62
+ x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2)
63
+ x1 = max(0, min(x1, w - 1))
64
+ x2 = max(0, min(x2, w - 1))
65
+ y1 = max(0, min(y1, h - 1))
66
+ y2 = max(0, min(y2, h - 1))
67
+
68
+ icon_cls = node.get("iconClass") or "icon"
69
+ label = f"Icon({icon_cls})"
70
+
71
+ cv2.rectangle(vis, (x1, y1), (x2, y2), color, 2)
72
+ (tw, th), _ = cv2.getTextSize(label, font, 0.6, 2)
73
+ top_left = (x1, max(0, y1 - th - 4))
74
+ bottom_right = (x1 + tw + 4, y1)
75
+ cv2.rectangle(vis, top_left, bottom_right, color, -1)
76
+ cv2.putText(vis, label, (x1 + 2, y1 - 4), font, 0.6, (255, 255, 255), 2)
77
+
78
+ cv2.imwrite(save_path, vis)
79
+ print(f"[vis] {save_path}")
80
+
81
+
82
+ def main():
83
+ ensure_dirs()
84
+
85
+ # 列出所有 semantic json,按数字排序
86
+ json_files = [f for f in os.listdir(SEM_DIR) if f.lower().endswith(".json")]
87
+
88
+ def get_id(name: str) -> int:
89
+ base = os.path.splitext(name)[0]
90
+ try:
91
+ return int(base)
92
+ except ValueError:
93
+ # 如果有不是纯数字的文件名,就排在后面
94
+ return 10 ** 9
95
+
96
+ json_files.sort(key=get_id)
97
+
98
+ total_sem = len(json_files)
99
+ selected = 0
100
+ no_icon = 0
101
+ no_screenshot = 0
102
+ errors = 0
103
+
104
+ # tqdm 显示进度
105
+ for fname in tqdm(json_files, desc="Building YOLO icon dataset"):
106
+ ui_id = os.path.splitext(fname)[0]
107
+ sem_json_path = os.path.join(SEM_DIR, fname)
108
+
109
+ try:
110
+ # 读取 semantic json
111
+ with open(sem_json_path, "r", encoding="utf-8") as f:
112
+ data = json.load(f)
113
+
114
+ # 收集所有 icon 节点
115
+ icons = collect_icon_nodes(data)
116
+ if not icons:
117
+ no_icon += 1
118
+ continue
119
+
120
+ # 读取 semantic png(用来获取原始坐标所在的分辨率)
121
+ sem_png_path = os.path.join(SEM_DIR, f"{ui_id}.png")
122
+ sem_img = cv2.imread(sem_png_path)
123
+ if sem_img is None:
124
+ print(f"[!] semantic png not found or unreadable: {sem_png_path}")
125
+ errors += 1
126
+ continue
127
+
128
+ sem_h, sem_w = sem_img.shape[:2]
129
+
130
+ # 读取 screenshot,并 resize 到 semantic 的尺寸
131
+ screenshot_path = os.path.join(SCREENSHOT_DIR, f"{ui_id}.jpg")
132
+ if not os.path.isfile(screenshot_path):
133
+ no_screenshot += 1
134
+ continue
135
+
136
+ scr = cv2.imread(screenshot_path)
137
+ if scr is None:
138
+ print(f"[!] cannot read screenshot: {screenshot_path}")
139
+ errors += 1
140
+ continue
141
+
142
+ # ★ 核心:把 screenshot 拉伸到 semantic 的大小(例如 540x960 -> 1440x2560)
143
+ img_resized = cv2.resize(scr, (sem_w, sem_h), interpolation=cv2.INTER_LINEAR)
144
+
145
+ # 生成 YOLO label(单类 icon -> class_id = 0)
146
+ label_lines = []
147
+ for node in icons:
148
+ bounds = node.get("bounds")
149
+ if not bounds or len(bounds) != 4:
150
+ continue
151
+
152
+ x1, y1, x2, y2 = bounds
153
+ x1, y1, x2, y2 = float(x1), float(y1), float(x2), float(y2)
154
+
155
+ # 简单裁剪,确保在图像内
156
+ x1 = max(0.0, min(x1, sem_w - 1.0))
157
+ x2 = max(0.0, min(x2, sem_w - 1.0))
158
+ y1 = max(0.0, min(y1, sem_h - 1.0))
159
+ y2 = max(0.0, min(y2, sem_h - 1.0))
160
+
161
+ box_w = x2 - x1
162
+ box_h = y2 - y1
163
+ if box_w <= 1 or box_h <= 1:
164
+ continue
165
+
166
+ x_center = x1 + box_w / 2.0
167
+ y_center = y1 + box_h / 2.0
168
+
169
+ x_center_n = x_center / sem_w
170
+ y_center_n = y_center / sem_h
171
+ w_n = box_w / sem_w
172
+ h_n = box_h / sem_h
173
+
174
+ class_id = 0 # 只有一个类:icon
175
+
176
+ label_lines.append(
177
+ f"{class_id} {x_center_n:.6f} {y_center_n:.6f} {w_n:.6f} {h_n:.6f}"
178
+ )
179
+
180
+ if not label_lines:
181
+ # 防止所有 bbox 都被过滤掉
182
+ no_icon += 1
183
+ continue
184
+
185
+ # 保存 label
186
+ label_path = os.path.join(OUT_LABELS, f"{ui_id}.txt")
187
+ with open(label_path, "w", encoding="utf-8") as f_lab:
188
+ f_lab.write("\n".join(label_lines))
189
+
190
+ # 保存训练图片(jpg)
191
+ out_img_path = os.path.join(OUT_IMAGES, f"{ui_id}.jpg")
192
+ cv2.imwrite(out_img_path, img_resized)
193
+
194
+ selected += 1
195
+
196
+ # 每 100 条保存一张 vis 图方便你检查(第 100, 200, 300, ...)
197
+ if selected % 100 == 0:
198
+ vis_path = os.path.join(OUT_VIS, f"{ui_id}_icons.jpg")
199
+ visualize_icons(img_resized, icons, vis_path)
200
+
201
+ except Exception as e:
202
+ errors += 1
203
+ print(f"[ERROR] {fname} -> {repr(e)}")
204
+
205
+ # 写 classes.txt(单类:icon)
206
+ classes_path = os.path.join(OUT_ROOT, "classes.txt")
207
+ with open(classes_path, "w", encoding="utf-8") as f_cls:
208
+ f_cls.write("icon\n")
209
+
210
+ print("\n=== DONE ===")
211
+ print(f"Total semantic json : {total_sem}")
212
+ print(f"Selected (with icon & screenshot): {selected}")
213
+ print(f"No icon : {no_icon}")
214
+ print(f"No screenshot : {no_screenshot}")
215
+ print(f"Errors : {errors}")
216
+ print(f"Output root : {OUT_ROOT}")
217
+ print(f"classes.txt : {classes_path}")
218
+
219
+
220
+ if __name__ == "__main__":
221
+ main()
get_yolo_small.py ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import shutil
3
+ import random
4
+ from tqdm import tqdm
5
+
6
+ # ============================
7
+ # ★★ 在这里填你的 YOLO 数据集路径 ★★
8
+ # ============================
9
+ DATASET_ROOT = "/mnt/d/mysite/SamVG/Dataset/rico/yolo_icon_full"
10
+
11
+ # 输出目标路径
12
+ OUT_ROOT = "/mnt/d/mysite/SamVG/Dataset/rico/yolo_icon_10k_2plus"
13
+
14
+ # 创建目录结构
15
+ for split in ["train", "test", "val"]:
16
+ os.makedirs(os.path.join(OUT_ROOT, "images", split), exist_ok=True)
17
+ os.makedirs(os.path.join(OUT_ROOT, "labels", split), exist_ok=True)
18
+
19
+ def collect_candidates(split_name):
20
+ """收集每个 split 中具有 >=2 icons 的样本"""
21
+ split_labels = os.path.join(DATASET_ROOT, "labels", split_name)
22
+ split_images = os.path.join(DATASET_ROOT, "images", split_name)
23
+
24
+ if not os.path.isdir(split_labels):
25
+ print(f"[WARN] No label folder: {split_labels}")
26
+ return []
27
+
28
+ label_files = [f for f in os.listdir(split_labels) if f.endswith(".txt")]
29
+
30
+ candidates = []
31
+ print(f"\nScanning {split_name} ({len(label_files)} files)...")
32
+
33
+ for lf in tqdm(label_files, desc=f"Reading {split_name}", ncols=100):
34
+ label_path = os.path.join(split_labels, lf)
35
+
36
+ try:
37
+ with open(label_path, "r") as f:
38
+ lines = f.readlines()
39
+ except Exception as e:
40
+ print(f"[ERR] Cannot read {label_path}: {e}")
41
+ continue
42
+
43
+ if len(lines) < 2: # 至少两个 icon
44
+ continue
45
+
46
+ img_id = lf.replace(".txt", "")
47
+ img_path = os.path.join(split_images, img_id + ".jpg")
48
+
49
+ if not os.path.isfile(img_path):
50
+ continue
51
+
52
+ candidates.append((split_name, img_id))
53
+
54
+ print(f"[OK] Found {len(candidates)} samples (>=2 icons) in {split_name}")
55
+ return candidates
56
+
57
+
58
+ # === Step1:收集全部候选 ===
59
+ all_candidates = []
60
+ for sp in ["train", "test", "val"]:
61
+ all_candidates.extend(collect_candidates(sp))
62
+
63
+ print(f"\nTotal qualified samples across all splits: {len(all_candidates)}")
64
+
65
+ # === Step2:随机选取 10k ===
66
+ total_needed = 10000
67
+ train_n = 8500
68
+ test_n = 1000
69
+ val_n = 500
70
+
71
+ random.shuffle(all_candidates)
72
+ subset = all_candidates[:total_needed]
73
+
74
+ train_set = subset[:train_n]
75
+ test_set = subset[train_n : train_n + test_n]
76
+ val_set = subset[train_n + test_n : train_n + test_n + val_n]
77
+
78
+
79
+ # === Step3:拷贝对应 sample ===
80
+ def copy_split(samples, split_name):
81
+ print(f"\nCopying {split_name} ({len(samples)})...")
82
+
83
+ for orig_split, img_id in tqdm(samples, desc=f"Copying {split_name}", ncols=100):
84
+ src_img = os.path.join(DATASET_ROOT, "images", orig_split, f"{img_id}.jpg")
85
+ src_lbl = os.path.join(DATASET_ROOT, "labels", orig_split, f"{img_id}.txt")
86
+
87
+ dst_img = os.path.join(OUT_ROOT, "images", split_name, f"{img_id}.jpg")
88
+ dst_lbl = os.path.join(OUT_ROOT, "labels", split_name, f"{img_id}.txt")
89
+
90
+ try:
91
+ shutil.copy2(src_img, dst_img)
92
+ shutil.copy2(src_lbl, dst_lbl)
93
+ except Exception as e:
94
+ print(f"[ERR] copying {img_id}: {e}")
95
+
96
+
97
+ copy_split(train_set, "train")
98
+ copy_split(test_set, "test")
99
+ copy_split(val_set, "val")
100
+
101
+ print("\n=== DONE ===")
102
+ print(f"Train: {len(train_set)}")
103
+ print(f"Test : {len(test_set)}")
104
+ print(f"Val : {len(val_set)}")
105
+ print(f"Output root: {OUT_ROOT}")
initial_kaggle_dataset.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ import kagglehub
2
+
3
+ # Download latest version
4
+ path = kagglehub.dataset_download("onurgunes1993/rico-dataset")
5
+
6
+ print("Path to dataset files:", path)
make_yolo_train_icon_first100.py ADDED
@@ -0,0 +1,188 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import json
3
+ import shutil
4
+ from typing import Dict, Any, List
5
+
6
+ import cv2
7
+
8
+
9
+ # ---------- 根据你当前路径配置 ----------
10
+ SCREENSHOT_DIR = "/mnt/d/mysite/SamVG/Dataset/rico/2/unique_uis/combined"
11
+ SEM_DIR = "/mnt/d/mysite/SamVG/Dataset/rico/2/rico_dataset_v0.1_semantic_annotations/semantic_annotations"
12
+
13
+ # YOLO 子集输出目录
14
+ OUT_ROOT = "/mnt/d/mysite/SamVG/Dataset/rico/yolo_icon_first100"
15
+ OUT_IMAGES = os.path.join(OUT_ROOT, "images")
16
+ OUT_LABELS = os.path.join(OUT_ROOT, "labels")
17
+ OUT_VIS = os.path.join(OUT_ROOT, "vis") # 可选:画框检查用
18
+
19
+
20
+ def ensure_dirs():
21
+ os.makedirs(OUT_IMAGES, exist_ok=True)
22
+ os.makedirs(OUT_LABELS, exist_ok=True)
23
+ os.makedirs(OUT_VIS, exist_ok=True)
24
+
25
+
26
+ def collect_icon_nodes(node: Dict[str, Any]) -> List[Dict[str, Any]]:
27
+ """递归收集所有 componentLabel == 'Icon' 的节点"""
28
+ icons = []
29
+ if node.get("componentLabel") == "Icon":
30
+ icons.append(node)
31
+ for child in node.get("children", []):
32
+ icons.extend(collect_icon_nodes(child))
33
+ return icons
34
+
35
+
36
+ def visualize_icons(image, icons, save_path):
37
+ """仅用于人工检查:在 image 上画出 icons"""
38
+ vis = image.copy()
39
+ font = cv2.FONT_HERSHEY_SIMPLEX
40
+ color = (0, 0, 255)
41
+
42
+ h, w = vis.shape[:2]
43
+
44
+ for node in icons:
45
+ bounds = node.get("bounds")
46
+ if not bounds or len(bounds) != 4:
47
+ continue
48
+ x1, y1, x2, y2 = bounds
49
+ x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2)
50
+ # 简单裁剪一下,防止越界
51
+ x1 = max(0, min(x1, w - 1))
52
+ x2 = max(0, min(x2, w - 1))
53
+ y1 = max(0, min(y1, h - 1))
54
+ y2 = max(0, min(y2, h - 1))
55
+
56
+ icon_class = node.get("iconClass") or "icon_generic"
57
+ label = f"Icon({icon_class})"
58
+
59
+ cv2.rectangle(vis, (x1, y1), (x2, y2), color, 3)
60
+ (tw, th), _ = cv2.getTextSize(label, font, 0.6, 2)
61
+ top_left = (x1, max(0, y1 - th - 4))
62
+ bottom_right = (x1 + tw + 4, y1)
63
+ cv2.rectangle(vis, top_left, bottom_right, color, -1)
64
+ cv2.putText(vis, label, (x1 + 2, y1 - 4), font, 0.6, (255, 255, 255), 2)
65
+
66
+ cv2.imwrite(save_path, vis)
67
+ print(f"[vis] {save_path}")
68
+
69
+
70
+ def main(max_num: int = 100):
71
+ ensure_dirs()
72
+
73
+ # 列出所有 semantic json,按数字排序
74
+ json_files = [
75
+ f for f in os.listdir(SEM_DIR) if f.lower().endswith(".json")
76
+ ]
77
+
78
+ def get_id(name: str) -> int:
79
+ base = os.path.splitext(name)[0]
80
+ try:
81
+ return int(base)
82
+ except ValueError:
83
+ return 10 ** 9
84
+
85
+ json_files.sort(key=get_id)
86
+
87
+ class2id: Dict[str, int] = {}
88
+ selected = 0
89
+
90
+ for fname in json_files:
91
+ if selected >= max_num:
92
+ break
93
+
94
+ ui_id = os.path.splitext(fname)[0]
95
+ json_path = os.path.join(SEM_DIR, fname)
96
+
97
+ with open(json_path, "r", encoding="utf-8") as f:
98
+ data = json.load(f)
99
+
100
+ # 这个 data 就是 semantic 的根
101
+ icons = collect_icon_nodes(data)
102
+ if not icons:
103
+ continue # 没有 icon,跳过
104
+
105
+ # 读 semantic png 以得到宽高
106
+ sem_png_path = os.path.join(SEM_DIR, f"{ui_id}.png")
107
+ sem_img = cv2.imread(sem_png_path)
108
+ if sem_img is None:
109
+ print(f"[!] semantic png not found or unreadable: {sem_png_path}")
110
+ continue
111
+
112
+ sem_h, sem_w = sem_img.shape[:2]
113
+
114
+ # 读 screenshot,并 resize 到 semantic 尺寸
115
+ screenshot_path = os.path.join(SCREENSHOT_DIR, f"{ui_id}.jpg")
116
+ if os.path.isfile(screenshot_path):
117
+ scr = cv2.imread(screenshot_path)
118
+ if scr is None:
119
+ print(f"[!] cannot read screenshot: {screenshot_path}")
120
+ continue
121
+ img_resized = cv2.resize(scr, (sem_w, sem_h), interpolation=cv2.INTER_LINEAR)
122
+ else:
123
+ # 没有 screenshot 时,就直接用 semantic png 作为训练图
124
+ img_resized = sem_img
125
+
126
+ selected += 1
127
+ print(f"[{selected}/{max_num}] UI {ui_id} with {len(icons)} icons")
128
+
129
+ # -------- 生成 YOLO label --------
130
+ label_lines = []
131
+ for node in icons:
132
+ bounds = node.get("bounds")
133
+ if not bounds or len(bounds) != 4:
134
+ continue
135
+ x1, y1, x2, y2 = bounds
136
+ x1, y1, x2, y2 = float(x1), float(y1), float(x2), float(y2)
137
+
138
+ # 坐标转 YOLO 格式(归一化)
139
+ box_w = x2 - x1
140
+ box_h = y2 - y1
141
+ x_center = x1 + box_w / 2.0
142
+ y_center = y1 + box_h / 2.0
143
+
144
+ x_center_n = x_center / sem_w
145
+ y_center_n = y_center / sem_h
146
+ w_n = box_w / sem_w
147
+ h_n = box_h / sem_h
148
+
149
+ icon_class = (node.get("iconClass") or "icon_generic").strip()
150
+ if icon_class not in class2id:
151
+ class2id[icon_class] = len(class2id)
152
+ cid = class2id[icon_class]
153
+
154
+ label_lines.append(
155
+ f"{cid} {x_center_n:.6f} {y_center_n:.6f} {w_n:.6f} {h_n:.6f}"
156
+ )
157
+
158
+ # 保存 label
159
+ label_path = os.path.join(OUT_LABELS, f"{ui_id}.txt")
160
+ with open(label_path, "w", encoding="utf-8") as f_lab:
161
+ f_lab.write("\n".join(label_lines))
162
+
163
+ # 保存 image(统一存 jpg)
164
+ out_img_path = os.path.join(OUT_IMAGES, f"{ui_id}.jpg")
165
+ cv2.imwrite(out_img_path, img_resized)
166
+
167
+ # 画一个只含 icon 的可视化图(方便你肉眼检查,可以删)
168
+ vis_path = os.path.join(OUT_VIS, f"{ui_id}_icons.jpg")
169
+ visualize_icons(img_resized, icons, vis_path)
170
+
171
+ # 保存 classes.txt
172
+ classes_path = os.path.join(OUT_ROOT, "classes.txt")
173
+ # 按 id 顺序写出类名
174
+ id2class = [""] * len(class2id)
175
+ for name, idx in class2id.items():
176
+ id2class[idx] = name
177
+ with open(classes_path, "w", encoding="utf-8") as f_cls:
178
+ for name in id2class:
179
+ f_cls.write(name + "\n")
180
+
181
+ print("\nDone.")
182
+ print(f"Total selected UIs: {selected}")
183
+ print(f"Num of icon classes: {len(class2id)}")
184
+ print(f"classes.txt saved to: {classes_path}")
185
+
186
+
187
+ if __name__ == "__main__":
188
+ main(max_num=100)
show_semantic_meaning.py ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import os
3
+ from typing import Dict, Any
4
+
5
+ import cv2
6
+
7
+
8
+ def draw_node_boxes(img, node: Dict[str, Any]):
9
+ """
10
+ 在 img 上根据 node 的 bounds 画框(不做任何缩放变换)
11
+ """
12
+ bounds = node.get("bounds")
13
+ if bounds and len(bounds) == 4:
14
+ x1, y1, x2, y2 = bounds
15
+ # 这里不做缩放,只画原始坐标的框
16
+ cv2.rectangle(img, (x1, y1), (x2, y2), (0, 255, 0), 2)
17
+
18
+ for child in node.get("children", []):
19
+ draw_node_boxes(img, child)
20
+
21
+
22
+ def show_semantic_meaning_stretched(
23
+ screenshot_path: str,
24
+ semantic_json_path: str,
25
+ semantic_png_path: str,
26
+ save_dir: str,
27
+ ) -> str:
28
+ """
29
+ 用 semantic PNG 的尺寸把 screenshot 拉伸,然后把 semantic JSON 的框画上去。
30
+
31
+ screenshot_path: 例如 /mnt/d/mysite/SamVG/Dataset/rico/2/unique_uis/combined/54.jpg
32
+ semantic_json_path: 例如 /mnt/d/mysite/SamVG/Dataset/rico/2/rico_dataset_v0.1_semantic_annotations/semantic_annotations/54.json
33
+ semantic_png_path: 例如 /mnt/d/mysite/SamVG/Dataset/rico/2/rico_dataset_v0.1_semantic_annotations/semantic_annotations/54.png
34
+ save_dir: 保存目录,例如 /mnt/d/mysite/SamVG/Dataset/rico/test
35
+ """
36
+
37
+ # 1. 读 screenshot(540×960)
38
+ src_img = cv2.imread(screenshot_path)
39
+ if src_img is None:
40
+ raise FileNotFoundError(f"Cannot read screenshot: {screenshot_path}")
41
+ h_src, w_src = src_img.shape[:2]
42
+ print(f"[info] screenshot size: {w_src} x {h_src}")
43
+
44
+ # 2. 读 semantic PNG(1440×2560,用来获取目标 size)
45
+ sem_img = cv2.imread(semantic_png_path)
46
+ if sem_img is None:
47
+ raise FileNotFoundError(f"Cannot read semantic png: {semantic_png_path}")
48
+ h_tgt, w_tgt = sem_img.shape[:2]
49
+ print(f"[info] semantic png size: {w_tgt} x {h_tgt}")
50
+
51
+ # 3. 把 screenshot 拉伸到 semantic png 同样尺寸
52
+ stretched = cv2.resize(src_img, (w_tgt, h_tgt), interpolation=cv2.INTER_LINEAR)
53
+
54
+ # 4. 读 semantic JSON
55
+ with open(semantic_json_path, "r", encoding="utf-8") as f:
56
+ data = json.load(f)
57
+
58
+ # 语义 json 根节点结构:你发的例子是直接就有 "ancestors" / "class" / "bounds" / "children"
59
+ # 也就是说 data 本身就是 root
60
+ root = data
61
+ print("[info] start drawing boxes with original bounds ...")
62
+
63
+ draw_node_boxes(stretched, root)
64
+
65
+ # 5. 保存结果
66
+ os.makedirs(save_dir, exist_ok=True)
67
+ base_name = os.path.splitext(os.path.basename(screenshot_path))[0]
68
+ out_path = os.path.join(save_dir, f"{base_name}_stretched_semantic.png")
69
+
70
+ cv2.imwrite(out_path, stretched)
71
+ print(f"[+] saved to: {out_path}")
72
+
73
+ return out_path
74
+
75
+
76
+ if __name__ == "__main__":
77
+ # 路径按你现在的环境改成 /mnt/d/ 版本
78
+ screenshot_path = "/mnt/d/mysite/SamVG/Dataset/rico/2/unique_uis/combined/54.jpg"
79
+ semantic_json_path = "/mnt/d/mysite/SamVG/Dataset/rico/2/rico_dataset_v0.1_semantic_annotations/semantic_annotations/54.json"
80
+ semantic_png_path = "/mnt/d/mysite/SamVG/Dataset/rico/2/rico_dataset_v0.1_semantic_annotations/semantic_annotations/54.png"
81
+
82
+ save_dir = "/mnt/d/mysite/SamVG/Dataset/rico/test"
83
+
84
+ show_semantic_meaning_stretched(
85
+ screenshot_path,
86
+ semantic_json_path,
87
+ semantic_png_path,
88
+ save_dir,
89
+ )
show_semantic_meaning_icon.py ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import os
3
+ from typing import Dict, Any
4
+
5
+ import cv2
6
+
7
+
8
+ def draw_icon_boxes(img, node: Dict[str, Any], show_icon_only: bool):
9
+ """
10
+ 在 img 上根据 semantic json 节点画框:
11
+ - 如果 show_icon_only=True,只画 componentLabel == "Icon" 的节点
12
+ - 坐标完全使用原始 bounds,不做缩放
13
+ """
14
+ bounds = node.get("bounds")
15
+ comp_label = node.get("componentLabel", "")
16
+
17
+ # 判断是否需要画当前节点
18
+ should_draw = True
19
+ if show_icon_only:
20
+ # 只画 Icon
21
+ should_draw = (comp_label == "Icon")
22
+
23
+ if bounds and len(bounds) == 4 and should_draw:
24
+ x1, y1, x2, y2 = bounds
25
+ # 原始坐标,直接画
26
+ color = (0, 0, 255) # 红色框表示 Icon
27
+ cv2.rectangle(img, (x1, y1), (x2, y2), color, 3)
28
+
29
+ # 标签:Icon 或 Icon(iconClass)
30
+ label = "Icon"
31
+ icon_cls = node.get("iconClass")
32
+ if icon_cls:
33
+ label = f"Icon({icon_cls})"
34
+
35
+ font = cv2.FONT_HERSHEY_SIMPLEX
36
+ (tw, th), baseline = cv2.getTextSize(label, font, 0.6, 2)
37
+ top_left = (x1, max(0, y1 - th - 4))
38
+ bottom_right = (x1 + tw + 4, y1)
39
+
40
+ cv2.rectangle(img, top_left, bottom_right, color, thickness=-1)
41
+ cv2.putText(
42
+ img,
43
+ label,
44
+ (x1 + 2, y1 - 4),
45
+ font,
46
+ 0.6,
47
+ (255, 255, 255),
48
+ 2,
49
+ lineType=cv2.LINE_AA,
50
+ )
51
+
52
+ # 继续递归 children(即使自己不画,也要看子节点里有没有 Icon)
53
+ for child in node.get("children", []):
54
+ draw_icon_boxes(img, child, show_icon_only)
55
+
56
+
57
+ def show_semantic_meaning_stretched(
58
+ screenshot_path: str,
59
+ semantic_json_path: str,
60
+ semantic_png_path: str,
61
+ save_dir: str,
62
+ show_icon_only: bool = False,
63
+ ) -> str:
64
+ """
65
+ 用 semantic PNG 的尺寸把 screenshot 拉伸,然后把 semantic JSON 的框画上去。
66
+
67
+ screenshot_path: /mnt/d/.../unique_uis/combined/54.jpg
68
+ semantic_json_path: /mnt/d/.../semantic_annotations/54.json
69
+ semantic_png_path: /mnt/d/.../semantic_annotations/54.png
70
+ save_dir: /mnt/d/.../test
71
+ show_icon_only: True 时只画 Icon
72
+ """
73
+
74
+ # 1. 读 screenshot(例如 540×960)
75
+ src_img = cv2.imread(screenshot_path)
76
+ if src_img is None:
77
+ raise FileNotFoundError(f"Cannot read screenshot: {screenshot_path}")
78
+ h_src, w_src = src_img.shape[:2]
79
+ print(f"[info] screenshot size: {w_src} x {h_src}")
80
+
81
+ # 2. 读 semantic PNG(例如 1440×2560)
82
+ sem_img = cv2.imread(semantic_png_path)
83
+ if sem_img is None:
84
+ raise FileNotFoundError(f"Cannot read semantic png: {semantic_png_path}")
85
+ h_tgt, w_tgt = sem_img.shape[:2]
86
+ print(f"[info] semantic png size: {w_tgt} x {h_tgt}")
87
+
88
+ # 3. 把 screenshot 拉伸到 semantic png 同样尺寸
89
+ stretched = cv2.resize(src_img, (w_tgt, h_tgt), interpolation=cv2.INTER_LINEAR)
90
+
91
+ # 4. 读 semantic JSON
92
+ with open(semantic_json_path, "r", encoding="utf-8") as f:
93
+ data = json.load(f)
94
+
95
+ # 你给的 semantic json 根结构就是包含 bounds / children 的 root
96
+ root = data
97
+ print(f"[info] drawing boxes, show_icon_only={show_icon_only} ...")
98
+
99
+ draw_icon_boxes(stretched, root, show_icon_only=show_icon_only)
100
+
101
+ # 5. 保存结果
102
+ os.makedirs(save_dir, exist_ok=True)
103
+ base_name = os.path.splitext(os.path.basename(screenshot_path))[0]
104
+ suffix = "_icons" if show_icon_only else "_all"
105
+ out_path = os.path.join(save_dir, f"{base_name}_stretched{suffix}.png")
106
+
107
+ cv2.imwrite(out_path, stretched)
108
+ print(f"[+] saved to: {out_path}")
109
+
110
+ return out_path
111
+
112
+
113
+ if __name__ == "__main__":
114
+ screenshot_path = "/mnt/d/mysite/SamVG/Dataset/rico/2/unique_uis/combined/100.jpg"
115
+ semantic_json_path = "/mnt/d/mysite/SamVG/Dataset/rico/2/rico_dataset_v0.1_semantic_annotations/semantic_annotations/100.json"
116
+ semantic_png_path = "/mnt/d/mysite/SamVG/Dataset/rico/2/rico_dataset_v0.1_semantic_annotations/semantic_annotations/100.png"
117
+ save_dir = "/mnt/d/mysite/SamVG/Dataset/rico/test"
118
+
119
+ # ✅ 只画 Icon
120
+ show_semantic_meaning_stretched(
121
+ screenshot_path,
122
+ semantic_json_path,
123
+ semantic_png_path,
124
+ save_dir,
125
+ show_icon_only=True,
126
+ )
split_train_test.py ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import random
3
+ import shutil
4
+ from tqdm import tqdm
5
+
6
+ # ==== 路径配置 ====
7
+ ROOT = "/mnt/d/mysite/SamVG/Dataset/rico/yolo_icon_full"
8
+
9
+ IMAGES_DIR = os.path.join(ROOT, "images")
10
+ LABELS_DIR = os.path.join(ROOT, "labels")
11
+
12
+ TRAIN_IMG_DIR = os.path.join(IMAGES_DIR, "train")
13
+ VAL_IMG_DIR = os.path.join(IMAGES_DIR, "val")
14
+ TEST_IMG_DIR = os.path.join(IMAGES_DIR, "test")
15
+
16
+ TRAIN_LBL_DIR = os.path.join(LABELS_DIR, "train")
17
+ VAL_LBL_DIR = os.path.join(LABELS_DIR, "val")
18
+ TEST_LBL_DIR = os.path.join(LABELS_DIR, "test")
19
+
20
+ TRAIN_RATIO = 0.90
21
+ VAL_RATIO = 0.05
22
+ RANDOM_SEED = 42
23
+
24
+
25
+ def ensure_dirs():
26
+ print(f"[LOG] 确保 train/val/test 子目录存在...")
27
+ os.makedirs(TRAIN_IMG_DIR, exist_ok=True)
28
+ os.makedirs(VAL_IMG_DIR, exist_ok=True)
29
+ os.makedirs(TEST_IMG_DIR, exist_ok=True)
30
+
31
+ os.makedirs(TRAIN_LBL_DIR, exist_ok=True)
32
+ os.makedirs(VAL_LBL_DIR, exist_ok=True)
33
+ os.makedirs(TEST_LBL_DIR, exist_ok=True)
34
+ print(f"[LOG] 子目录检查完成。")
35
+
36
+
37
+ def main():
38
+ print("===== YOLO train/val/test 拆分开始 =====")
39
+ print(f"[LOG] ROOT = {ROOT}")
40
+ print(f"[LOG] IMAGES_DIR = {IMAGES_DIR}")
41
+ print(f"[LOG] LABELS_DIR = {LABELS_DIR}")
42
+
43
+ if not os.path.isdir(IMAGES_DIR):
44
+ print(f"[ERROR] 图像目录不存在: {IMAGES_DIR}")
45
+ return
46
+ if not os.path.isdir(LABELS_DIR):
47
+ print(f"[ERROR] 标签目录不存在: {LABELS_DIR}")
48
+ return
49
+
50
+ ensure_dirs()
51
+
52
+ print("[LOG] 扫描 images 顶层(不含 train/val/test 子目录)...")
53
+
54
+ # 🔴 不再使用 os.path.isfile,只按后缀筛选
55
+ all_imgs = [
56
+ f for f in os.listdir(IMAGES_DIR)
57
+ if f.lower().endswith((".jpg", ".jpeg", ".png"))
58
+ ]
59
+
60
+ n_total = len(all_imgs)
61
+ print(f"[LOG] 找到图片数量: {n_total}")
62
+
63
+ if n_total == 0:
64
+ print("[ERROR] images/ 里没有任何顶层图片(可能已经全部被移动到 train/val/test 了?)")
65
+ return
66
+
67
+ print("[LOG] 示例前 5 张图片: ", all_imgs[:5])
68
+
69
+ random.seed(RANDOM_SEED)
70
+ random.shuffle(all_imgs)
71
+ print("[LOG] 打乱顺序完成。")
72
+
73
+ n_train = int(n_total * TRAIN_RATIO)
74
+ n_val = int(n_total * VAL_RATIO)
75
+ n_test = n_total - n_train - n_val
76
+
77
+ train_files = all_imgs[:n_train]
78
+ val_files = all_imgs[n_train:n_train + n_val]
79
+ test_files = all_imgs[n_train + n_val:]
80
+
81
+ print(f"[LOG] 划分结果:train={len(train_files)}, val={len(val_files)}, test={len(test_files)}")
82
+
83
+ # ---------- 移动 train ----------
84
+ print("[LOG] 开始移动 train 文件...")
85
+ for fname in tqdm(train_files, desc="Moving train set"):
86
+ base, _ = os.path.splitext(fname)
87
+ src_img = os.path.join(IMAGES_DIR, fname)
88
+ src_lbl = os.path.join(LABELS_DIR, base + ".txt")
89
+
90
+ if not os.path.exists(src_lbl):
91
+ # 理论上不该发生,如果出现就提醒一下
92
+ print(f"[WARN] 找不到标签文件: {src_lbl},跳过这张图。")
93
+ continue
94
+
95
+ dst_img = os.path.join(TRAIN_IMG_DIR, fname)
96
+ dst_lbl = os.path.join(TRAIN_LBL_DIR, base + ".txt")
97
+
98
+ shutil.move(src_img, dst_img)
99
+ shutil.move(src_lbl, dst_lbl)
100
+
101
+ # ---------- 移动 val ----------
102
+ print("[LOG] 开始移动 val 文件...")
103
+ for fname in tqdm(val_files, desc="Moving val set"):
104
+ base, _ = os.path.splitext(fname)
105
+ src_img = os.path.join(IMAGES_DIR, fname)
106
+ src_lbl = os.path.join(LABELS_DIR, base + ".txt")
107
+
108
+ if not os.path.exists(src_lbl):
109
+ print(f"[WARN] 找不到标签文件: {src_lbl},跳过这张图。")
110
+ continue
111
+
112
+ dst_img = os.path.join(VAL_IMG_DIR, fname)
113
+ dst_lbl = os.path.join(VAL_LBL_DIR, base + ".txt")
114
+
115
+ shutil.move(src_img, dst_img)
116
+ shutil.move(src_lbl, dst_lbl)
117
+
118
+ # ---------- 移动 test ----------
119
+ print("[LOG] 开始移动 test 文件...")
120
+ for fname in tqdm(test_files, desc="Moving test set"):
121
+ base, _ = os.path.splitext(fname)
122
+ src_img = os.path.join(IMAGES_DIR, fname)
123
+ src_lbl = os.path.join(LABELS_DIR, base + ".txt")
124
+
125
+ if not os.path.exists(src_lbl):
126
+ print(f"[WARN] 找不到标签文件: {src_lbl},跳过这张图。")
127
+ continue
128
+
129
+ dst_img = os.path.join(TEST_IMG_DIR, fname)
130
+ dst_lbl = os.path.join(TEST_LBL_DIR, base + ".txt")
131
+
132
+ shutil.move(src_img, dst_img)
133
+ shutil.move(src_lbl, dst_lbl)
134
+
135
+ print("===== 拆分完成 =====")
136
+ print(f"Images train dir : {TRAIN_IMG_DIR}")
137
+ print(f"Images val dir : {VAL_IMG_DIR}")
138
+ print(f"Images test dir : {TEST_IMG_DIR}")
139
+ print(f"Labels train dir : {TRAIN_LBL_DIR}")
140
+ print(f"Labels val dir : {VAL_LBL_DIR}")
141
+ print(f"Labels test dir : {TEST_LBL_DIR}")
142
+
143
+
144
+ if __name__ == "__main__":
145
+ main()
test.ipynb ADDED
@@ -0,0 +1,409 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 2,
6
+ "id": "d67c350f",
7
+ "metadata": {},
8
+ "outputs": [
9
+ {
10
+ "name": "stdout",
11
+ "output_type": "stream",
12
+ "text": [
13
+ "Sat Dec 6 12:09:27 2025 \n",
14
+ "+-----------------------------------------------------------------------------------------+\n",
15
+ "| NVIDIA-SMI 550.54.15 Driver Version: 550.54.15 CUDA Version: 12.4 |\n",
16
+ "|-----------------------------------------+------------------------+----------------------+\n",
17
+ "| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |\n",
18
+ "| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |\n",
19
+ "| | | MIG M. |\n",
20
+ "|=========================================+========================+======================|\n",
21
+ "| 0 Tesla T4 Off | 00000000:00:04.0 Off | 0 |\n",
22
+ "| N/A 36C P8 9W / 70W | 0MiB / 15360MiB | 0% Default |\n",
23
+ "| | | N/A |\n",
24
+ "+-----------------------------------------+------------------------+----------------------+\n",
25
+ " \n",
26
+ "+-----------------------------------------------------------------------------------------+\n",
27
+ "| Processes: |\n",
28
+ "| GPU GI CI PID Type Process name GPU Memory |\n",
29
+ "| ID ID Usage |\n",
30
+ "|=========================================================================================|\n",
31
+ "| No running processes found |\n",
32
+ "+-----------------------------------------------------------------------------------------+\n"
33
+ ]
34
+ }
35
+ ],
36
+ "source": [
37
+ "!nvidia-smi"
38
+ ]
39
+ },
40
+ {
41
+ "cell_type": "code",
42
+ "execution_count": 3,
43
+ "id": "5197eeca",
44
+ "metadata": {},
45
+ "outputs": [
46
+ {
47
+ "name": "stdout",
48
+ "output_type": "stream",
49
+ "text": [
50
+ "Collecting ultralytics\n",
51
+ " Downloading ultralytics-8.3.235-py3-none-any.whl.metadata (37 kB)\n",
52
+ "Requirement already satisfied: numpy>=1.23.0 in /usr/local/lib/python3.12/dist-packages (from ultralytics) (2.0.2)\n",
53
+ "Requirement already satisfied: matplotlib>=3.3.0 in /usr/local/lib/python3.12/dist-packages (from ultralytics) (3.10.0)\n",
54
+ "Requirement already satisfied: opencv-python>=4.6.0 in /usr/local/lib/python3.12/dist-packages (from ultralytics) (4.12.0.88)\n",
55
+ "Requirement already satisfied: pillow>=7.1.2 in /usr/local/lib/python3.12/dist-packages (from ultralytics) (11.3.0)\n",
56
+ "Requirement already satisfied: pyyaml>=5.3.1 in /usr/local/lib/python3.12/dist-packages (from ultralytics) (6.0.3)\n",
57
+ "Requirement already satisfied: requests>=2.23.0 in /usr/local/lib/python3.12/dist-packages (from ultralytics) (2.32.4)\n",
58
+ "Requirement already satisfied: scipy>=1.4.1 in /usr/local/lib/python3.12/dist-packages (from ultralytics) (1.16.3)\n",
59
+ "Requirement already satisfied: torch>=1.8.0 in /usr/local/lib/python3.12/dist-packages (from ultralytics) (2.9.0+cu126)\n",
60
+ "Requirement already satisfied: torchvision>=0.9.0 in /usr/local/lib/python3.12/dist-packages (from ultralytics) (0.24.0+cu126)\n",
61
+ "Requirement already satisfied: psutil>=5.8.0 in /usr/local/lib/python3.12/dist-packages (from ultralytics) (5.9.5)\n",
62
+ "Requirement already satisfied: polars>=0.20.0 in /usr/local/lib/python3.12/dist-packages (from ultralytics) (1.31.0)\n",
63
+ "Collecting ultralytics-thop>=2.0.18 (from ultralytics)\n",
64
+ " Downloading ultralytics_thop-2.0.18-py3-none-any.whl.metadata (14 kB)\n",
65
+ "Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3.3.0->ultralytics) (1.3.3)\n",
66
+ "Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3.3.0->ultralytics) (0.12.1)\n",
67
+ "Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3.3.0->ultralytics) (4.60.1)\n",
68
+ "Requirement already satisfied: kiwisolver>=1.3.1 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3.3.0->ultralytics) (1.4.9)\n",
69
+ "Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3.3.0->ultralytics) (25.0)\n",
70
+ "Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3.3.0->ultralytics) (3.2.5)\n",
71
+ "Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3.3.0->ultralytics) (2.9.0.post0)\n",
72
+ "Requirement already satisfied: charset_normalizer<4,>=2 in /usr/local/lib/python3.12/dist-packages (from requests>=2.23.0->ultralytics) (3.4.4)\n",
73
+ "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.12/dist-packages (from requests>=2.23.0->ultralytics) (3.11)\n",
74
+ "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.12/dist-packages (from requests>=2.23.0->ultralytics) (2.5.0)\n",
75
+ "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.12/dist-packages (from requests>=2.23.0->ultralytics) (2025.11.12)\n",
76
+ "Requirement already satisfied: filelock in /usr/local/lib/python3.12/dist-packages (from torch>=1.8.0->ultralytics) (3.20.0)\n",
77
+ "Requirement already satisfied: typing-extensions>=4.10.0 in /usr/local/lib/python3.12/dist-packages (from torch>=1.8.0->ultralytics) (4.15.0)\n",
78
+ "Requirement already satisfied: setuptools in /usr/local/lib/python3.12/dist-packages (from torch>=1.8.0->ultralytics) (75.2.0)\n",
79
+ "Requirement already satisfied: sympy>=1.13.3 in /usr/local/lib/python3.12/dist-packages (from torch>=1.8.0->ultralytics) (1.14.0)\n",
80
+ "Requirement already satisfied: networkx>=2.5.1 in /usr/local/lib/python3.12/dist-packages (from torch>=1.8.0->ultralytics) (3.6)\n",
81
+ "Requirement already satisfied: jinja2 in /usr/local/lib/python3.12/dist-packages (from torch>=1.8.0->ultralytics) (3.1.6)\n",
82
+ "Requirement already satisfied: fsspec>=0.8.5 in /usr/local/lib/python3.12/dist-packages (from torch>=1.8.0->ultralytics) (2025.3.0)\n",
83
+ "Requirement already satisfied: nvidia-cuda-nvrtc-cu12==12.6.77 in /usr/local/lib/python3.12/dist-packages (from torch>=1.8.0->ultralytics) (12.6.77)\n",
84
+ "Requirement already satisfied: nvidia-cuda-runtime-cu12==12.6.77 in /usr/local/lib/python3.12/dist-packages (from torch>=1.8.0->ultralytics) (12.6.77)\n",
85
+ "Requirement already satisfied: nvidia-cuda-cupti-cu12==12.6.80 in /usr/local/lib/python3.12/dist-packages (from torch>=1.8.0->ultralytics) (12.6.80)\n",
86
+ "Requirement already satisfied: nvidia-cudnn-cu12==9.10.2.21 in /usr/local/lib/python3.12/dist-packages (from torch>=1.8.0->ultralytics) (9.10.2.21)\n",
87
+ "Requirement already satisfied: nvidia-cublas-cu12==12.6.4.1 in /usr/local/lib/python3.12/dist-packages (from torch>=1.8.0->ultralytics) (12.6.4.1)\n",
88
+ "Requirement already satisfied: nvidia-cufft-cu12==11.3.0.4 in /usr/local/lib/python3.12/dist-packages (from torch>=1.8.0->ultralytics) (11.3.0.4)\n",
89
+ "Requirement already satisfied: nvidia-curand-cu12==10.3.7.77 in /usr/local/lib/python3.12/dist-packages (from torch>=1.8.0->ultralytics) (10.3.7.77)\n",
90
+ "Requirement already satisfied: nvidia-cusolver-cu12==11.7.1.2 in /usr/local/lib/python3.12/dist-packages (from torch>=1.8.0->ultralytics) (11.7.1.2)\n",
91
+ "Requirement already satisfied: nvidia-cusparse-cu12==12.5.4.2 in /usr/local/lib/python3.12/dist-packages (from torch>=1.8.0->ultralytics) (12.5.4.2)\n",
92
+ "Requirement already satisfied: nvidia-cusparselt-cu12==0.7.1 in /usr/local/lib/python3.12/dist-packages (from torch>=1.8.0->ultralytics) (0.7.1)\n",
93
+ "Requirement already satisfied: nvidia-nccl-cu12==2.27.5 in /usr/local/lib/python3.12/dist-packages (from torch>=1.8.0->ultralytics) (2.27.5)\n",
94
+ "Requirement already satisfied: nvidia-nvshmem-cu12==3.3.20 in /usr/local/lib/python3.12/dist-packages (from torch>=1.8.0->ultralytics) (3.3.20)\n",
95
+ "Requirement already satisfied: nvidia-nvtx-cu12==12.6.77 in /usr/local/lib/python3.12/dist-packages (from torch>=1.8.0->ultralytics) (12.6.77)\n",
96
+ "Requirement already satisfied: nvidia-nvjitlink-cu12==12.6.85 in /usr/local/lib/python3.12/dist-packages (from torch>=1.8.0->ultralytics) (12.6.85)\n",
97
+ "Requirement already satisfied: nvidia-cufile-cu12==1.11.1.6 in /usr/local/lib/python3.12/dist-packages (from torch>=1.8.0->ultralytics) (1.11.1.6)\n",
98
+ "Requirement already satisfied: triton==3.5.0 in /usr/local/lib/python3.12/dist-packages (from torch>=1.8.0->ultralytics) (3.5.0)\n",
99
+ "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.12/dist-packages (from python-dateutil>=2.7->matplotlib>=3.3.0->ultralytics) (1.17.0)\n",
100
+ "Requirement already satisfied: mpmath<1.4,>=1.1.0 in /usr/local/lib/python3.12/dist-packages (from sympy>=1.13.3->torch>=1.8.0->ultralytics) (1.3.0)\n",
101
+ "Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.12/dist-packages (from jinja2->torch>=1.8.0->ultralytics) (3.0.3)\n",
102
+ "Downloading ultralytics-8.3.235-py3-none-any.whl (1.1 MB)\n",
103
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.1/1.1 MB\u001b[0m \u001b[31m25.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m\n",
104
+ "\u001b[?25hDownloading ultralytics_thop-2.0.18-py3-none-any.whl (28 kB)\n",
105
+ "Installing collected packages: ultralytics-thop, ultralytics\n",
106
+ "Successfully installed ultralytics-8.3.235 ultralytics-thop-2.0.18\n"
107
+ ]
108
+ }
109
+ ],
110
+ "source": [
111
+ "!pip install ultralytics"
112
+ ]
113
+ },
114
+ {
115
+ "cell_type": "code",
116
+ "execution_count": 4,
117
+ "id": "7ed3adf8",
118
+ "metadata": {},
119
+ "outputs": [
120
+ {
121
+ "name": "stdout",
122
+ "output_type": "stream",
123
+ "text": [
124
+ "Creating new Ultralytics Settings v0.0.6 file ✅ \n",
125
+ "View Ultralytics Settings with 'yolo settings' or at '/root/.config/Ultralytics/settings.json'\n",
126
+ "Update Settings with 'yolo settings key=value', i.e. 'yolo settings runs_dir=path/to/dir'. For help see https://docs.ultralytics.com/quickstart/#ultralytics-settings.\n",
127
+ "\u001b[KDownloading https://github.com/ultralytics/assets/releases/download/v8.3.0/yolov8n.pt to 'yolov8n.pt': 100% ━━━━━━━━━━━━ 6.2MB 130.3MB/s 0.0s\n"
128
+ ]
129
+ }
130
+ ],
131
+ "source": [
132
+ "from ultralytics import YOLO\n",
133
+ "\n",
134
+ "model = YOLO(\"yolov8n.pt\") # 载入预训练模型\n"
135
+ ]
136
+ },
137
+ {
138
+ "cell_type": "code",
139
+ "execution_count": 5,
140
+ "id": "a6fe0e55",
141
+ "metadata": {},
142
+ "outputs": [
143
+ {
144
+ "name": "stdout",
145
+ "output_type": "stream",
146
+ "text": [
147
+ "CUDA available: True\n",
148
+ "GPU: Tesla T4\n"
149
+ ]
150
+ }
151
+ ],
152
+ "source": [
153
+ "import torch\n",
154
+ "print(\"CUDA available:\", torch.cuda.is_available())\n",
155
+ "print(\"GPU:\", torch.cuda.get_device_name(0))\n"
156
+ ]
157
+ },
158
+ {
159
+ "cell_type": "code",
160
+ "execution_count": 7,
161
+ "id": "c9e6b658",
162
+ "metadata": {},
163
+ "outputs": [
164
+ {
165
+ "data": {
166
+ "text/html": [
167
+ "\n",
168
+ " <input type=\"file\" id=\"files-c36b4f65-2de8-41fb-b639-9ec5da9486a9\" name=\"files[]\" multiple disabled\n",
169
+ " style=\"border:none\" />\n",
170
+ " <output id=\"result-c36b4f65-2de8-41fb-b639-9ec5da9486a9\">\n",
171
+ " Upload widget is only available when the cell has been executed in the\n",
172
+ " current browser session. Please rerun this cell to enable.\n",
173
+ " </output>\n",
174
+ " <script>// Copyright 2017 Google LLC\n",
175
+ "//\n",
176
+ "// Licensed under the Apache License, Version 2.0 (the \"License\");\n",
177
+ "// you may not use this file except in compliance with the License.\n",
178
+ "// You may obtain a copy of the License at\n",
179
+ "//\n",
180
+ "// http://www.apache.org/licenses/LICENSE-2.0\n",
181
+ "//\n",
182
+ "// Unless required by applicable law or agreed to in writing, software\n",
183
+ "// distributed under the License is distributed on an \"AS IS\" BASIS,\n",
184
+ "// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
185
+ "// See the License for the specific language governing permissions and\n",
186
+ "// limitations under the License.\n",
187
+ "\n",
188
+ "/**\n",
189
+ " * @fileoverview Helpers for google.colab Python module.\n",
190
+ " */\n",
191
+ "(function(scope) {\n",
192
+ "function span(text, styleAttributes = {}) {\n",
193
+ " const element = document.createElement('span');\n",
194
+ " element.textContent = text;\n",
195
+ " for (const key of Object.keys(styleAttributes)) {\n",
196
+ " element.style[key] = styleAttributes[key];\n",
197
+ " }\n",
198
+ " return element;\n",
199
+ "}\n",
200
+ "\n",
201
+ "// Max number of bytes which will be uploaded at a time.\n",
202
+ "const MAX_PAYLOAD_SIZE = 100 * 1024;\n",
203
+ "\n",
204
+ "function _uploadFiles(inputId, outputId) {\n",
205
+ " const steps = uploadFilesStep(inputId, outputId);\n",
206
+ " const outputElement = document.getElementById(outputId);\n",
207
+ " // Cache steps on the outputElement to make it available for the next call\n",
208
+ " // to uploadFilesContinue from Python.\n",
209
+ " outputElement.steps = steps;\n",
210
+ "\n",
211
+ " return _uploadFilesContinue(outputId);\n",
212
+ "}\n",
213
+ "\n",
214
+ "// This is roughly an async generator (not supported in the browser yet),\n",
215
+ "// where there are multiple asynchronous steps and the Python side is going\n",
216
+ "// to poll for completion of each step.\n",
217
+ "// This uses a Promise to block the python side on completion of each step,\n",
218
+ "// then passes the result of the previous step as the input to the next step.\n",
219
+ "function _uploadFilesContinue(outputId) {\n",
220
+ " const outputElement = document.getElementById(outputId);\n",
221
+ " const steps = outputElement.steps;\n",
222
+ "\n",
223
+ " const next = steps.next(outputElement.lastPromiseValue);\n",
224
+ " return Promise.resolve(next.value.promise).then((value) => {\n",
225
+ " // Cache the last promise value to make it available to the next\n",
226
+ " // step of the generator.\n",
227
+ " outputElement.lastPromiseValue = value;\n",
228
+ " return next.value.response;\n",
229
+ " });\n",
230
+ "}\n",
231
+ "\n",
232
+ "/**\n",
233
+ " * Generator function which is called between each async step of the upload\n",
234
+ " * process.\n",
235
+ " * @param {string} inputId Element ID of the input file picker element.\n",
236
+ " * @param {string} outputId Element ID of the output display.\n",
237
+ " * @return {!Iterable<!Object>} Iterable of next steps.\n",
238
+ " */\n",
239
+ "function* uploadFilesStep(inputId, outputId) {\n",
240
+ " const inputElement = document.getElementById(inputId);\n",
241
+ " inputElement.disabled = false;\n",
242
+ "\n",
243
+ " const outputElement = document.getElementById(outputId);\n",
244
+ " outputElement.innerHTML = '';\n",
245
+ "\n",
246
+ " const pickedPromise = new Promise((resolve) => {\n",
247
+ " inputElement.addEventListener('change', (e) => {\n",
248
+ " resolve(e.target.files);\n",
249
+ " });\n",
250
+ " });\n",
251
+ "\n",
252
+ " const cancel = document.createElement('button');\n",
253
+ " inputElement.parentElement.appendChild(cancel);\n",
254
+ " cancel.textContent = 'Cancel upload';\n",
255
+ " const cancelPromise = new Promise((resolve) => {\n",
256
+ " cancel.onclick = () => {\n",
257
+ " resolve(null);\n",
258
+ " };\n",
259
+ " });\n",
260
+ "\n",
261
+ " // Wait for the user to pick the files.\n",
262
+ " const files = yield {\n",
263
+ " promise: Promise.race([pickedPromise, cancelPromise]),\n",
264
+ " response: {\n",
265
+ " action: 'starting',\n",
266
+ " }\n",
267
+ " };\n",
268
+ "\n",
269
+ " cancel.remove();\n",
270
+ "\n",
271
+ " // Disable the input element since further picks are not allowed.\n",
272
+ " inputElement.disabled = true;\n",
273
+ "\n",
274
+ " if (!files) {\n",
275
+ " return {\n",
276
+ " response: {\n",
277
+ " action: 'complete',\n",
278
+ " }\n",
279
+ " };\n",
280
+ " }\n",
281
+ "\n",
282
+ " for (const file of files) {\n",
283
+ " const li = document.createElement('li');\n",
284
+ " li.append(span(file.name, {fontWeight: 'bold'}));\n",
285
+ " li.append(span(\n",
286
+ " `(${file.type || 'n/a'}) - ${file.size} bytes, ` +\n",
287
+ " `last modified: ${\n",
288
+ " file.lastModifiedDate ? file.lastModifiedDate.toLocaleDateString() :\n",
289
+ " 'n/a'} - `));\n",
290
+ " const percent = span('0% done');\n",
291
+ " li.appendChild(percent);\n",
292
+ "\n",
293
+ " outputElement.appendChild(li);\n",
294
+ "\n",
295
+ " const fileDataPromise = new Promise((resolve) => {\n",
296
+ " const reader = new FileReader();\n",
297
+ " reader.onload = (e) => {\n",
298
+ " resolve(e.target.result);\n",
299
+ " };\n",
300
+ " reader.readAsArrayBuffer(file);\n",
301
+ " });\n",
302
+ " // Wait for the data to be ready.\n",
303
+ " let fileData = yield {\n",
304
+ " promise: fileDataPromise,\n",
305
+ " response: {\n",
306
+ " action: 'continue',\n",
307
+ " }\n",
308
+ " };\n",
309
+ "\n",
310
+ " // Use a chunked sending to avoid message size limits. See b/62115660.\n",
311
+ " let position = 0;\n",
312
+ " do {\n",
313
+ " const length = Math.min(fileData.byteLength - position, MAX_PAYLOAD_SIZE);\n",
314
+ " const chunk = new Uint8Array(fileData, position, length);\n",
315
+ " position += length;\n",
316
+ "\n",
317
+ " const base64 = btoa(String.fromCharCode.apply(null, chunk));\n",
318
+ " yield {\n",
319
+ " response: {\n",
320
+ " action: 'append',\n",
321
+ " file: file.name,\n",
322
+ " data: base64,\n",
323
+ " },\n",
324
+ " };\n",
325
+ "\n",
326
+ " let percentDone = fileData.byteLength === 0 ?\n",
327
+ " 100 :\n",
328
+ " Math.round((position / fileData.byteLength) * 100);\n",
329
+ " percent.textContent = `${percentDone}% done`;\n",
330
+ "\n",
331
+ " } while (position < fileData.byteLength);\n",
332
+ " }\n",
333
+ "\n",
334
+ " // All done.\n",
335
+ " yield {\n",
336
+ " response: {\n",
337
+ " action: 'complete',\n",
338
+ " }\n",
339
+ " };\n",
340
+ "}\n",
341
+ "\n",
342
+ "scope.google = scope.google || {};\n",
343
+ "scope.google.colab = scope.google.colab || {};\n",
344
+ "scope.google.colab._files = {\n",
345
+ " _uploadFiles,\n",
346
+ " _uploadFilesContinue,\n",
347
+ "};\n",
348
+ "})(self);\n",
349
+ "</script> "
350
+ ],
351
+ "text/plain": [
352
+ "<IPython.core.display.HTML object>"
353
+ ]
354
+ },
355
+ "metadata": {},
356
+ "output_type": "display_data"
357
+ },
358
+ {
359
+ "ename": "KeyboardInterrupt",
360
+ "evalue": "",
361
+ "output_type": "error",
362
+ "traceback": [
363
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
364
+ "\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
365
+ "\u001b[0;32m/tmp/ipython-input-264872163.py\u001b[0m in \u001b[0;36m<cell line: 0>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mgoogle\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcolab\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mfiles\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0muploaded\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfiles\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mupload\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
366
+ "\u001b[0;32m/usr/local/lib/python3.12/dist-packages/google/colab/files.py\u001b[0m in \u001b[0;36mupload\u001b[0;34m(target_dir)\u001b[0m\n\u001b[1;32m 70\u001b[0m \"\"\"\n\u001b[1;32m 71\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 72\u001b[0;31m \u001b[0muploaded_files\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_upload_files\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmultiple\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 73\u001b[0m \u001b[0;31m# Mapping from original filename to filename as saved locally.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 74\u001b[0m \u001b[0mlocal_filenames\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
367
+ "\u001b[0;32m/usr/local/lib/python3.12/dist-packages/google/colab/files.py\u001b[0m in \u001b[0;36m_upload_files\u001b[0;34m(multiple)\u001b[0m\n\u001b[1;32m 162\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 163\u001b[0m \u001b[0;31m# First result is always an indication that the file picker has completed.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 164\u001b[0;31m result = _output.eval_js(\n\u001b[0m\u001b[1;32m 165\u001b[0m 'google.colab._files._uploadFiles(\"{input_id}\", \"{output_id}\")'.format(\n\u001b[1;32m 166\u001b[0m \u001b[0minput_id\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0minput_id\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0moutput_id\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0moutput_id\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
368
+ "\u001b[0;32m/usr/local/lib/python3.12/dist-packages/google/colab/output/_js.py\u001b[0m in \u001b[0;36meval_js\u001b[0;34m(script, ignore_result, timeout_sec)\u001b[0m\n\u001b[1;32m 38\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mignore_result\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 39\u001b[0m \u001b[0;32mreturn\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 40\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0m_message\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mread_reply_from_input\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrequest_id\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtimeout_sec\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 41\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 42\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
369
+ "\u001b[0;32m/usr/local/lib/python3.12/dist-packages/google/colab/_message.py\u001b[0m in \u001b[0;36mread_reply_from_input\u001b[0;34m(message_id, timeout_sec)\u001b[0m\n\u001b[1;32m 94\u001b[0m \u001b[0mreply\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_read_next_input_message\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 95\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mreply\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0m_NOT_READY\u001b[0m \u001b[0;32mor\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mreply\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdict\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 96\u001b[0;31m \u001b[0mtime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msleep\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m0.025\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 97\u001b[0m \u001b[0;32mcontinue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 98\u001b[0m if (\n",
370
+ "\u001b[0;31mKeyboardInterrupt\u001b[0m: "
371
+ ]
372
+ }
373
+ ],
374
+ "source": [
375
+ "from google.colab import files\n",
376
+ "uploaded = files.upload()\n"
377
+ ]
378
+ },
379
+ {
380
+ "cell_type": "code",
381
+ "execution_count": null,
382
+ "id": "dee3f32f",
383
+ "metadata": {},
384
+ "outputs": [],
385
+ "source": []
386
+ }
387
+ ],
388
+ "metadata": {
389
+ "kernelspec": {
390
+ "display_name": "base",
391
+ "language": "python",
392
+ "name": "python3"
393
+ },
394
+ "language_info": {
395
+ "codemirror_mode": {
396
+ "name": "ipython",
397
+ "version": 3
398
+ },
399
+ "file_extension": ".py",
400
+ "mimetype": "text/x-python",
401
+ "name": "python",
402
+ "nbconvert_exporter": "python",
403
+ "pygments_lexer": "ipython3",
404
+ "version": "3.12.7"
405
+ }
406
+ },
407
+ "nbformat": 4,
408
+ "nbformat_minor": 5
409
+ }
upload_dataset.py ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ from huggingface_hub import login, upload_folder
2
+
3
+
4
+ login()
5
+
6
+
7
+ upload_folder(folder_path=".", repo_id="lili24/yolo_rico_icon_48k", repo_type="dataset")