Upload 20 files
Browse files- .gitattributes +8 -0
- dataset-export-yolo.ipynb +229 -0
- dataset-stats.ipynb +201 -0
- export_prediction_to_label_studio.py +102 -0
- fashionpedia.yaml +54 -0
- results/yolov8n-fashionpedia-1.onnx +3 -0
- results/yolov8n-fashionpedia-1.torchscript +3 -0
- results/yolov8s-fashionpedia-1.onnx +3 -0
- results/yolov8s-fashionpedia-1.torchscript +3 -0
- results/yolovn8-fashionpedia-1.md +55 -0
- results/yolovs8-fashionpedia-1.md +55 -0
- shared/describe_clothes.py +32 -0
- shared/yolov8n-fashionpedia-1.torchscript +3 -0
- test/courte.png +3 -0
- test/longue.png +3 -0
- test/rayure.png +3 -0
- test/sans-manche.png +3 -0
- test/test_shared.py +17 -0
- test/trois-quart.png +3 -0
- yolo8-pre-annotate.ipynb +315 -0
- yolo8.ipynb +101 -0
.gitattributes
CHANGED
@@ -33,3 +33,11 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
results/yolov8n-fashionpedia-1.torchscript filter=lfs diff=lfs merge=lfs -text
|
37 |
+
results/yolov8s-fashionpedia-1.torchscript filter=lfs diff=lfs merge=lfs -text
|
38 |
+
shared/yolov8n-fashionpedia-1.torchscript filter=lfs diff=lfs merge=lfs -text
|
39 |
+
test/courte.png filter=lfs diff=lfs merge=lfs -text
|
40 |
+
test/longue.png filter=lfs diff=lfs merge=lfs -text
|
41 |
+
test/rayure.png filter=lfs diff=lfs merge=lfs -text
|
42 |
+
test/sans-manche.png filter=lfs diff=lfs merge=lfs -text
|
43 |
+
test/trois-quart.png filter=lfs diff=lfs merge=lfs -text
|
dataset-export-yolo.ipynb
ADDED
@@ -0,0 +1,229 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"id": "9ca8370e29b99d9b",
|
6 |
+
"metadata": {
|
7 |
+
"collapsed": true,
|
8 |
+
"ExecuteTime": {
|
9 |
+
"end_time": "2024-04-17T07:40:35.575275Z",
|
10 |
+
"start_time": "2024-04-17T07:40:35.397474Z"
|
11 |
+
}
|
12 |
+
},
|
13 |
+
"source": [
|
14 |
+
"import json\n",
|
15 |
+
"import os\n",
|
16 |
+
"import shutil\n",
|
17 |
+
"\n",
|
18 |
+
"import pandas as pd"
|
19 |
+
],
|
20 |
+
"execution_count": 2,
|
21 |
+
"outputs": []
|
22 |
+
},
|
23 |
+
{
|
24 |
+
"metadata": {
|
25 |
+
"ExecuteTime": {
|
26 |
+
"end_time": "2024-04-17T07:59:30.461558Z",
|
27 |
+
"start_time": "2024-04-17T07:59:30.458532Z"
|
28 |
+
}
|
29 |
+
},
|
30 |
+
"cell_type": "code",
|
31 |
+
"source": [
|
32 |
+
"def load_dataset(input_annotations_file: str, input_img_dir: str, output_dir: str):\n",
|
33 |
+
" with open(input_annotations_file, \"r\") as f:\n",
|
34 |
+
" dataset = json.load(f)\n",
|
35 |
+
" df_annotation = pd.DataFrame(dataset['annotations']).drop(['segmentation', 'attribute_ids'], axis='columns')\n",
|
36 |
+
" df_images = pd.DataFrame(dataset['images'])\n",
|
37 |
+
" df_categories = pd.DataFrame(dataset['categories'])\n",
|
38 |
+
"\n",
|
39 |
+
" df_dataset = pd.merge(df_images, df_annotation, how='inner', left_on='id', right_on='image_id')\n",
|
40 |
+
" df_dataset = pd.merge(df_dataset, df_categories, how='inner', left_on='category_id', right_on='id')\n",
|
41 |
+
" df_dataset['path_to_image'] = input_img_dir + df_dataset['file_name']\n",
|
42 |
+
" return df_dataset\n"
|
43 |
+
],
|
44 |
+
"id": "initial_id",
|
45 |
+
"execution_count": 48,
|
46 |
+
"outputs": []
|
47 |
+
},
|
48 |
+
{
|
49 |
+
"metadata": {
|
50 |
+
"ExecuteTime": {
|
51 |
+
"end_time": "2024-04-17T07:59:30.763506Z",
|
52 |
+
"start_time": "2024-04-17T07:59:30.759581Z"
|
53 |
+
}
|
54 |
+
},
|
55 |
+
"cell_type": "code",
|
56 |
+
"source": [
|
57 |
+
"def save_labels_one_image(df_one_image: pd.DataFrame, output_folder: str, subfolder: str):\n",
|
58 |
+
" path_to_image = df_one_image.iloc[0]['path_to_image']\n",
|
59 |
+
" image_id = df_one_image.iloc[0]['image_id']\n",
|
60 |
+
" image_width = df_one_image.iloc[0]['width']\n",
|
61 |
+
" image_height = df_one_image.iloc[0]['height']\n",
|
62 |
+
"\n",
|
63 |
+
" def format_one_box(one_line) -> str:\n",
|
64 |
+
" label_index = str(one_line['category_id'])\n",
|
65 |
+
"\n",
|
66 |
+
" [x_center, y_center, width, height] = one_line['bbox']\n",
|
67 |
+
" x_center_normalised, y_center_normalised = (x_center+width/2) / image_width, (y_center+height/2) / image_height\n",
|
68 |
+
" width_normalised, height_normalised = width / image_width, height / image_height\n",
|
69 |
+
" box = ' '.join(map(str, [x_center_normalised, y_center_normalised, width_normalised, height_normalised]))\n",
|
70 |
+
"\n",
|
71 |
+
" line = f'{label_index} {box}'\n",
|
72 |
+
" return line\n",
|
73 |
+
"\n",
|
74 |
+
" boxes_formatted = df_one_image.apply(format_one_box, axis='columns').tolist()\n",
|
75 |
+
"\n",
|
76 |
+
" with open(os.path.join(output_folder, 'labels', subfolder, f'{image_id}.txt'), 'w') as f:\n",
|
77 |
+
" f.write('\\n'.join(boxes_formatted))\n",
|
78 |
+
" shutil.copy(path_to_image, os.path.join(output_folder, 'images', subfolder, f'{image_id}.jpg'))\n",
|
79 |
+
"\n",
|
80 |
+
" return image_id\n"
|
81 |
+
],
|
82 |
+
"id": "aa0ec50c0b8b00f3",
|
83 |
+
"execution_count": 49,
|
84 |
+
"outputs": []
|
85 |
+
},
|
86 |
+
{
|
87 |
+
"metadata": {
|
88 |
+
"ExecuteTime": {
|
89 |
+
"end_time": "2024-04-17T07:59:33.282829Z",
|
90 |
+
"start_time": "2024-04-17T07:59:32.281139Z"
|
91 |
+
}
|
92 |
+
},
|
93 |
+
"cell_type": "code",
|
94 |
+
"source": [
|
95 |
+
"path_to_json_validation = \"./dataset/fashionpedia2020/instances_attributes_val2020.json\"\n",
|
96 |
+
"path_to_image_folder_validation = './dataset/fashionpedia2020/val_test2020/test/'\n",
|
97 |
+
"output_folder_validation = 'val2020'\n",
|
98 |
+
"fashionpedia_dataset_validation = load_dataset(path_to_json_validation, path_to_image_folder_validation,\n",
|
99 |
+
" 'dataset/fashionpedia-yolo')\n",
|
100 |
+
"fashionpedia_dataset_validation.groupby(['image_id']).apply(save_labels_one_image, './dataset/fashionpedia-yolo',\n",
|
101 |
+
" output_folder_validation)"
|
102 |
+
],
|
103 |
+
"id": "31756215355a324e",
|
104 |
+
"execution_count": 50,
|
105 |
+
"outputs": []
|
106 |
+
},
|
107 |
+
{
|
108 |
+
"metadata": {
|
109 |
+
"ExecuteTime": {
|
110 |
+
"end_time": "2024-04-17T08:00:11.718962Z",
|
111 |
+
"start_time": "2024-04-17T07:59:33.326724Z"
|
112 |
+
}
|
113 |
+
},
|
114 |
+
"cell_type": "code",
|
115 |
+
"source": [
|
116 |
+
"path_to_json_train = \"./dataset/fashionpedia2020/instances_attributes_train2020.json\"\n",
|
117 |
+
"path_to_image_folder_train = './dataset/fashionpedia2020/train2020/train/'\n",
|
118 |
+
"output_folder_train = 'train2020'\n",
|
119 |
+
"fashionpedia_dataset_train = load_dataset(path_to_json_train, path_to_image_folder_train, 'dataset/fashionpedia-yolo')\n",
|
120 |
+
"fashionpedia_dataset_train.groupby(['image_id']).apply(save_labels_one_image, './dataset/fashionpedia-yolo',\n",
|
121 |
+
" output_folder_train)"
|
122 |
+
],
|
123 |
+
"id": "ba95b509750ea10b",
|
124 |
+
"execution_count": 51,
|
125 |
+
"outputs": []
|
126 |
+
},
|
127 |
+
{
|
128 |
+
"metadata": {},
|
129 |
+
"cell_type": "code",
|
130 |
+
"execution_count": null,
|
131 |
+
"source": "",
|
132 |
+
"id": "77dff2cb00f9b08c",
|
133 |
+
"outputs": []
|
134 |
+
},
|
135 |
+
{
|
136 |
+
"metadata": {
|
137 |
+
"ExecuteTime": {
|
138 |
+
"end_time": "2024-04-17T08:00:11.733525Z",
|
139 |
+
"start_time": "2024-04-17T08:00:11.731305Z"
|
140 |
+
}
|
141 |
+
},
|
142 |
+
"cell_type": "code",
|
143 |
+
"source": [
|
144 |
+
"from matplotlib import pyplot as plt\n",
|
145 |
+
"\n",
|
146 |
+
"COLORS = ['lightcoral', 'yellowgreen', 'darkturquoise', 'hotpink', 'mediumslateblue']\n",
|
147 |
+
"\n",
|
148 |
+
"\n",
|
149 |
+
"def plot_results(pil_img, boxes, class_labels):\n",
|
150 |
+
" plt.figure(figsize=(16, 10))\n",
|
151 |
+
" plt.imshow(pil_img)\n",
|
152 |
+
" ax = plt.gca()\n",
|
153 |
+
" colors = COLORS * 100\n",
|
154 |
+
" for [xcenter, ycenter, xlength, ylength], c, label in zip(boxes, colors, class_labels):\n",
|
155 |
+
" xmin = (xcenter-(xlength/2)) * pil_img.width\n",
|
156 |
+
" xmax = (xcenter+(xlength/2)) * pil_img.width\n",
|
157 |
+
" ymin = (ycenter-(ylength/2)) * pil_img.height\n",
|
158 |
+
" ymax = (ycenter+(ylength/2)) * pil_img.height\n",
|
159 |
+
" \n",
|
160 |
+
" print(xmin, ymin)\n",
|
161 |
+
" ax.add_patch(plt.Rectangle((xmin, ymin), xmax - xmin, ymax - ymin,\n",
|
162 |
+
" fill=False, color=c, linewidth=2))\n",
|
163 |
+
" ax.text(xmin, ymin, str(label), fontsize=15,\n",
|
164 |
+
" bbox=dict(facecolor=c, alpha=0.5))\n",
|
165 |
+
" plt.axis('off')\n",
|
166 |
+
" plt.show()"
|
167 |
+
],
|
168 |
+
"id": "a16ebfa1cf517c1a",
|
169 |
+
"execution_count": 52,
|
170 |
+
"outputs": []
|
171 |
+
},
|
172 |
+
{
|
173 |
+
"metadata": {
|
174 |
+
"ExecuteTime": {
|
175 |
+
"end_time": "2024-04-17T08:00:11.921853Z",
|
176 |
+
"start_time": "2024-04-17T08:00:11.733970Z"
|
177 |
+
}
|
178 |
+
},
|
179 |
+
"cell_type": "code",
|
180 |
+
"source": [
|
181 |
+
"from PIL import Image\n",
|
182 |
+
"\n",
|
183 |
+
"pil_image = Image.open('dataset/fashionpedia-yolo/images/train2020/23.jpg')\n",
|
184 |
+
"with open('dataset/fashionpedia-yolo/labels/train2020/23.txt' ) as f:\n",
|
185 |
+
" labels = f.readlines()\n",
|
186 |
+
"\n",
|
187 |
+
"class_labels = []\n",
|
188 |
+
"box_center_length = []\n",
|
189 |
+
"for a_label in labels:\n",
|
190 |
+
" labels_split = a_label.split(' ')\n",
|
191 |
+
" class_labels.append(int(labels_split[0]))\n",
|
192 |
+
" box_center_length.append(list(map(float, labels_split[1:])))\n",
|
193 |
+
"plot_results(pil_image,box_center_length, class_labels)"
|
194 |
+
],
|
195 |
+
"id": "8c5dacbcecca7d42",
|
196 |
+
"execution_count": 53,
|
197 |
+
"outputs": []
|
198 |
+
},
|
199 |
+
{
|
200 |
+
"metadata": {},
|
201 |
+
"cell_type": "code",
|
202 |
+
"execution_count": null,
|
203 |
+
"source": "",
|
204 |
+
"id": "d7ac9abea09107e1",
|
205 |
+
"outputs": []
|
206 |
+
}
|
207 |
+
],
|
208 |
+
"metadata": {
|
209 |
+
"kernelspec": {
|
210 |
+
"display_name": "Python 3",
|
211 |
+
"language": "python",
|
212 |
+
"name": "python3"
|
213 |
+
},
|
214 |
+
"language_info": {
|
215 |
+
"codemirror_mode": {
|
216 |
+
"name": "ipython",
|
217 |
+
"version": 2
|
218 |
+
},
|
219 |
+
"file_extension": ".py",
|
220 |
+
"mimetype": "text/x-python",
|
221 |
+
"name": "python",
|
222 |
+
"nbconvert_exporter": "python",
|
223 |
+
"pygments_lexer": "ipython2",
|
224 |
+
"version": "2.7.6"
|
225 |
+
}
|
226 |
+
},
|
227 |
+
"nbformat": 4,
|
228 |
+
"nbformat_minor": 5
|
229 |
+
}
|
dataset-stats.ipynb
ADDED
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"id": "755f1267a6176c24",
|
6 |
+
"metadata": {
|
7 |
+
"collapsed": true,
|
8 |
+
"ExecuteTime": {
|
9 |
+
"end_time": "2024-04-15T08:56:52.063622Z",
|
10 |
+
"start_time": "2024-04-15T08:56:51.856029Z"
|
11 |
+
}
|
12 |
+
},
|
13 |
+
"source": [
|
14 |
+
"import json\n",
|
15 |
+
"import pandas as pd"
|
16 |
+
],
|
17 |
+
"execution_count": 1,
|
18 |
+
"outputs": []
|
19 |
+
},
|
20 |
+
{
|
21 |
+
"metadata": {
|
22 |
+
"ExecuteTime": {
|
23 |
+
"end_time": "2024-04-15T08:57:05.764152Z",
|
24 |
+
"start_time": "2024-04-15T08:57:05.390988Z"
|
25 |
+
}
|
26 |
+
},
|
27 |
+
"cell_type": "code",
|
28 |
+
"source": [
|
29 |
+
"with open(\"./dataset/instances_attributes_val2020.json\", \"r\") as f:\n",
|
30 |
+
" dataset = json.load(f)\n",
|
31 |
+
"\n",
|
32 |
+
"print(dataset.keys())"
|
33 |
+
],
|
34 |
+
"id": "initial_id",
|
35 |
+
"execution_count": 3,
|
36 |
+
"outputs": []
|
37 |
+
},
|
38 |
+
{
|
39 |
+
"metadata": {
|
40 |
+
"ExecuteTime": {
|
41 |
+
"end_time": "2024-04-15T09:41:18.117520Z",
|
42 |
+
"start_time": "2024-04-15T09:41:18.110946Z"
|
43 |
+
}
|
44 |
+
},
|
45 |
+
"cell_type": "code",
|
46 |
+
"source": [
|
47 |
+
"a = dataset['images']\n",
|
48 |
+
"print(len(a))\n",
|
49 |
+
"print(a)"
|
50 |
+
],
|
51 |
+
"id": "24c0ff8dda428023",
|
52 |
+
"execution_count": 30,
|
53 |
+
"outputs": []
|
54 |
+
},
|
55 |
+
{
|
56 |
+
"metadata": {
|
57 |
+
"ExecuteTime": {
|
58 |
+
"end_time": "2024-04-15T12:48:49.207137Z",
|
59 |
+
"start_time": "2024-04-15T12:48:49.202422Z"
|
60 |
+
}
|
61 |
+
},
|
62 |
+
"cell_type": "code",
|
63 |
+
"source": [
|
64 |
+
"df_categories = pd.DataFrame(dataset['categories'])\n",
|
65 |
+
"df_categories"
|
66 |
+
],
|
67 |
+
"id": "4e45dd93ed3d6d11",
|
68 |
+
"execution_count": 107,
|
69 |
+
"outputs": []
|
70 |
+
},
|
71 |
+
{
|
72 |
+
"metadata": {
|
73 |
+
"ExecuteTime": {
|
74 |
+
"end_time": "2024-04-15T09:02:58.490674Z",
|
75 |
+
"start_time": "2024-04-15T09:02:58.485590Z"
|
76 |
+
}
|
77 |
+
},
|
78 |
+
"cell_type": "code",
|
79 |
+
"source": [
|
80 |
+
"df_attributes = pd.DataFrame(dataset['attributes'])\n",
|
81 |
+
"df_attributes"
|
82 |
+
],
|
83 |
+
"id": "f8c1f1649b4890b7",
|
84 |
+
"execution_count": 18,
|
85 |
+
"outputs": []
|
86 |
+
},
|
87 |
+
{
|
88 |
+
"metadata": {
|
89 |
+
"ExecuteTime": {
|
90 |
+
"end_time": "2024-04-15T09:02:21.405195Z",
|
91 |
+
"start_time": "2024-04-15T09:02:21.390532Z"
|
92 |
+
}
|
93 |
+
},
|
94 |
+
"cell_type": "code",
|
95 |
+
"source": [
|
96 |
+
"df_annotation = pd.DataFrame(dataset['annotations'])\n",
|
97 |
+
"df_annotation = df_annotation.drop(['segmentation'], axis='columns')\n",
|
98 |
+
"df_annotation_exploded =df_annotation.explode('attribute_ids') "
|
99 |
+
],
|
100 |
+
"id": "4c53c3115c3dbef8",
|
101 |
+
"execution_count": 16,
|
102 |
+
"outputs": []
|
103 |
+
},
|
104 |
+
{
|
105 |
+
"metadata": {
|
106 |
+
"ExecuteTime": {
|
107 |
+
"end_time": "2024-04-15T09:02:23.057097Z",
|
108 |
+
"start_time": "2024-04-15T09:02:23.051760Z"
|
109 |
+
}
|
110 |
+
},
|
111 |
+
"cell_type": "code",
|
112 |
+
"source": "df_annotation_exploded",
|
113 |
+
"id": "618f069b857225fc",
|
114 |
+
"execution_count": 17,
|
115 |
+
"outputs": []
|
116 |
+
},
|
117 |
+
{
|
118 |
+
"metadata": {
|
119 |
+
"ExecuteTime": {
|
120 |
+
"end_time": "2024-04-15T09:03:53.975762Z",
|
121 |
+
"start_time": "2024-04-15T09:03:53.959100Z"
|
122 |
+
}
|
123 |
+
},
|
124 |
+
"cell_type": "code",
|
125 |
+
"source": [
|
126 |
+
"df_joined = df_attributes.merge(df_annotation_exploded, how='left', left_on='id', right_on='attribute_ids')\n",
|
127 |
+
"df_joined"
|
128 |
+
],
|
129 |
+
"id": "8a85bbf68e23920b",
|
130 |
+
"execution_count": 20,
|
131 |
+
"outputs": []
|
132 |
+
},
|
133 |
+
{
|
134 |
+
"metadata": {
|
135 |
+
"ExecuteTime": {
|
136 |
+
"end_time": "2024-04-15T09:08:05.647378Z",
|
137 |
+
"start_time": "2024-04-15T09:08:05.637874Z"
|
138 |
+
}
|
139 |
+
},
|
140 |
+
"cell_type": "code",
|
141 |
+
"source": [
|
142 |
+
"df_neck_collar = df_joined[df_joined.name.str.contains('neck') | df_joined.name.str.contains('collar') ]\n",
|
143 |
+
"df_neck_collar['name'].value_counts()"
|
144 |
+
],
|
145 |
+
"id": "2888345540b560d5",
|
146 |
+
"execution_count": 28,
|
147 |
+
"outputs": []
|
148 |
+
},
|
149 |
+
{
|
150 |
+
"metadata": {
|
151 |
+
"ExecuteTime": {
|
152 |
+
"end_time": "2024-04-15T09:49:34.287590Z",
|
153 |
+
"start_time": "2024-04-15T09:49:34.263905Z"
|
154 |
+
}
|
155 |
+
},
|
156 |
+
"cell_type": "code",
|
157 |
+
"source": [
|
158 |
+
"df_annotation = pd.DataFrame(dataset['annotations']).drop(['segmentation', 'attribute_ids'], axis='columns')\n",
|
159 |
+
"df_images = pd.DataFrame(dataset['images'])\n",
|
160 |
+
"df_categories = pd.DataFrame(dataset['categories'])\n",
|
161 |
+
"\n",
|
162 |
+
"df_dataset = pd.merge(df_images, df_annotation, how='inner', left_on='id', right_on='image_id')\n",
|
163 |
+
"df_dataset = pd.merge(df_dataset, df_categories, how='inner', left_on='category_id', right_on='id')\n",
|
164 |
+
"df_dataset['path_to_image'] = 'coucou/' + df_dataset['file_name']\n",
|
165 |
+
"df_dataset"
|
166 |
+
],
|
167 |
+
"id": "ebb14b7642a1459d",
|
168 |
+
"execution_count": 37,
|
169 |
+
"outputs": []
|
170 |
+
},
|
171 |
+
{
|
172 |
+
"metadata": {},
|
173 |
+
"cell_type": "code",
|
174 |
+
"execution_count": null,
|
175 |
+
"source": "",
|
176 |
+
"id": "20ba29a56c257d56",
|
177 |
+
"outputs": []
|
178 |
+
}
|
179 |
+
],
|
180 |
+
"metadata": {
|
181 |
+
"kernelspec": {
|
182 |
+
"display_name": "Python 3",
|
183 |
+
"language": "python",
|
184 |
+
"name": "python3"
|
185 |
+
},
|
186 |
+
"language_info": {
|
187 |
+
"codemirror_mode": {
|
188 |
+
"name": "ipython",
|
189 |
+
"version": 2
|
190 |
+
},
|
191 |
+
"file_extension": ".py",
|
192 |
+
"mimetype": "text/x-python",
|
193 |
+
"name": "python",
|
194 |
+
"nbconvert_exporter": "python",
|
195 |
+
"pygments_lexer": "ipython2",
|
196 |
+
"version": "2.7.6"
|
197 |
+
}
|
198 |
+
},
|
199 |
+
"nbformat": 4,
|
200 |
+
"nbformat_minor": 5
|
201 |
+
}
|
export_prediction_to_label_studio.py
ADDED
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import os
|
3 |
+
from uuid import uuid4
|
4 |
+
|
5 |
+
|
6 |
+
def export_one_prediction_to_label_studio(prediction, label_studio_relative_path: str, output_folder: str,
|
7 |
+
model_name: str, from_name: str,
|
8 |
+
threshold_to_export: float = 0.1):
|
9 |
+
image_name = label_studio_relative_path.split('/')[-1]
|
10 |
+
output_file = image_name.replace('.jpg', ".json").replace('.jpeg', ".json")
|
11 |
+
output_path = os.path.join(output_folder, output_file)
|
12 |
+
|
13 |
+
original_width, original_height = prediction.orig_shape
|
14 |
+
boxes_filtered = filter(lambda x: float(x.conf[0]) > threshold_to_export, prediction.boxes)
|
15 |
+
json_content = {
|
16 |
+
"data": {
|
17 |
+
"img": label_studio_relative_path,
|
18 |
+
},
|
19 |
+
"predictions": [
|
20 |
+
{
|
21 |
+
"model_version": model_name,
|
22 |
+
"result": [
|
23 |
+
{
|
24 |
+
"original_width": original_width,
|
25 |
+
"original_height": original_height,
|
26 |
+
"score": float(box.conf[0]),
|
27 |
+
"value": {
|
28 |
+
# nightmareeeeeee
|
29 |
+
"x": float(box.xywhn[0][0] - box.xywhn[0][2] / 2) * 100,
|
30 |
+
"y": float(box.xywhn[0][1] - box.xywhn[0][3] / 2) * 100,
|
31 |
+
"width": float(box.xywhn[0][2]) * 100,
|
32 |
+
"height": float(box.xywhn[0][3]) * 100,
|
33 |
+
"rotation": 0
|
34 |
+
},
|
35 |
+
"id": str(uuid4()),
|
36 |
+
"from_name": from_name,
|
37 |
+
"to_name": "image",
|
38 |
+
"type": "rectangle"
|
39 |
+
} for box in boxes_filtered],
|
40 |
+
}]
|
41 |
+
}
|
42 |
+
|
43 |
+
with open(output_path, 'w') as fp:
|
44 |
+
json.dump(json_content, fp)
|
45 |
+
|
46 |
+
return json_content
|
47 |
+
|
48 |
+
|
49 |
+
def export_one_yolo_output_to_label_studio_rectangles(yolo_prediction,
|
50 |
+
model_version: str,
|
51 |
+
label_studio_relative_path: str,
|
52 |
+
output_folder: str,
|
53 |
+
label_studio_to_name: str = 'image',
|
54 |
+
label_studio_from_name: str = 'label',
|
55 |
+
confidence_threshold: float = 0.1,
|
56 |
+
overwrite_existing_files: bool = False):
|
57 |
+
os.makedirs(output_folder, exist_ok=True)
|
58 |
+
|
59 |
+
image_name = label_studio_relative_path.split('/')[-1]
|
60 |
+
output_file = image_name.replace('.jpg', ".json").replace('.jpeg', ".json")
|
61 |
+
output_path = os.path.join(output_folder, output_file)
|
62 |
+
|
63 |
+
original_width, original_height = yolo_prediction.orig_shape
|
64 |
+
class_names = yolo_prediction.names
|
65 |
+
boxes_filtered = filter(lambda x: float(x.conf[0]) >= confidence_threshold
|
66 |
+
, yolo_prediction.boxes)
|
67 |
+
|
68 |
+
if not os.path.exists(output_path) or overwrite_existing_files:
|
69 |
+
json_content = {
|
70 |
+
"data": {
|
71 |
+
"image": label_studio_relative_path,
|
72 |
+
},
|
73 |
+
"predictions": [
|
74 |
+
{
|
75 |
+
"model_version": model_version,
|
76 |
+
"result": [
|
77 |
+
{
|
78 |
+
"original_width": original_width,
|
79 |
+
"original_height": original_height,
|
80 |
+
"score": float(box.conf[0]),
|
81 |
+
"value": {
|
82 |
+
# label studio x, y, width and height are in percent multiplied by 100
|
83 |
+
# x and y are the position of the box top left corner
|
84 |
+
"x": float(box.xywhn[0][0] - box.xywhn[0][2] / 2) * 100,
|
85 |
+
"y": float(box.xywhn[0][1] - box.xywhn[0][3] / 2) * 100,
|
86 |
+
"width": float(box.xywhn[0][2]) * 100,
|
87 |
+
"height": float(box.xywhn[0][3]) * 100,
|
88 |
+
"rotation": 0,
|
89 |
+
"rectanglelabels": [class_names[int(box.cls)]]
|
90 |
+
},
|
91 |
+
"id": str(uuid4()),
|
92 |
+
"from_name": label_studio_from_name,
|
93 |
+
"to_name": label_studio_to_name,
|
94 |
+
"type": "rectanglelabels",
|
95 |
+
} for box in boxes_filtered],
|
96 |
+
}]
|
97 |
+
}
|
98 |
+
|
99 |
+
with open(output_path, 'w') as fp:
|
100 |
+
json.dump(json_content, fp)
|
101 |
+
|
102 |
+
return json_content
|
fashionpedia.yaml
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
path: fashionpedia-yolo
|
2 |
+
train: images/train2020
|
3 |
+
val: images/val2020
|
4 |
+
test: # test images (optional)
|
5 |
+
|
6 |
+
# Classes
|
7 |
+
names:
|
8 |
+
0: "shirt, blouse"
|
9 |
+
1: "top, t-shirt, sweatshirt"
|
10 |
+
2: sweater
|
11 |
+
3: cardigan
|
12 |
+
4: jacket
|
13 |
+
5: vest
|
14 |
+
6: pants
|
15 |
+
7: shorts
|
16 |
+
8: skirt
|
17 |
+
9: coat
|
18 |
+
10: dress
|
19 |
+
11: jumpsuit
|
20 |
+
12: cape
|
21 |
+
13: glasses
|
22 |
+
14: hat
|
23 |
+
15: "headband, head covering, hair accessory"
|
24 |
+
16: tie
|
25 |
+
17: glove
|
26 |
+
18: watch
|
27 |
+
19: belt
|
28 |
+
20: leg warmer
|
29 |
+
21: "tights, stockings"
|
30 |
+
22: sock
|
31 |
+
23: shoe
|
32 |
+
24: "bag, wallet"
|
33 |
+
25: scarf
|
34 |
+
26: umbrella
|
35 |
+
27: hood
|
36 |
+
28: collar
|
37 |
+
29: lapel
|
38 |
+
30: epaulette
|
39 |
+
31: sleeve
|
40 |
+
32: pocket
|
41 |
+
33: neckline
|
42 |
+
34: buckle
|
43 |
+
35: zipper
|
44 |
+
36: applique
|
45 |
+
37: bead
|
46 |
+
38: bow
|
47 |
+
39: flower
|
48 |
+
40: fringe
|
49 |
+
41: ribbon
|
50 |
+
42: rivet
|
51 |
+
43: ruffle
|
52 |
+
44: sequin
|
53 |
+
45: tassel
|
54 |
+
|
results/yolov8n-fashionpedia-1.onnx
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6b581af3abe2b4ae97a84cbe9aef5ae37207a68ee966d22b0b8d7969d79e6920
|
3 |
+
size 12273953
|
results/yolov8n-fashionpedia-1.torchscript
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:2053a5d7f854e46a06394b6866b15427c3055bdbca95f94821a359c76e6a7b3e
|
3 |
+
size 12505310
|
results/yolov8s-fashionpedia-1.onnx
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9432e4a850d0a3049724c897fc22bcedf5caa32092f7d023df04fa6c8823299e
|
3 |
+
size 44789121
|
results/yolov8s-fashionpedia-1.torchscript
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:40667a8e28ae5b8d6bb30663de642467759536565fa57b959d78c7fcb760087e
|
3 |
+
size 45020318
|
results/yolovn8-fashionpedia-1.md
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
|
2 |
+
200/200 5.6G 0.7991 0.6805 1.012 181 640: 100%|██████████| 1426/1426 [02:24<00:00, 9.90it/s]
|
3 |
+
Class Images Instances Box(P R mAP50 mAP50-95): 100%|██████████| 713/713 [01:24<00:00, 8.46it/s]
|
4 |
+
all 45623 333400 0.737 0.583 0.631 0.501
|
5 |
+
200 epochs completed in 12.290 hours.
|
6 |
+
|
7 |
+
Class Images Instances Box(P R mAP50 mAP50-95): 100%|██████████| 713/713 [01:28<00:00, 8.08it/s]
|
8 |
+
all 45623 333400 0.735 0.583 0.631 0.501
|
9 |
+
shirt, blouse 45623 6161 0.695 0.777 0.824 0.713
|
10 |
+
top, t-shirt, sweatshirt 45623 16548 0.827 0.839 0.895 0.794
|
11 |
+
sweater 45623 1494 0.749 0.775 0.828 0.772
|
12 |
+
cardigan 45623 1107 0.761 0.836 0.868 0.807
|
13 |
+
jacket 45623 7833 0.876 0.938 0.962 0.916
|
14 |
+
vest 45623 719 0.683 0.565 0.648 0.477
|
15 |
+
pants 45623 12414 0.868 0.961 0.974 0.921
|
16 |
+
shorts 45623 2756 0.844 0.897 0.929 0.818
|
17 |
+
skirt 45623 5046 0.793 0.91 0.933 0.87
|
18 |
+
coat 45623 3124 0.815 0.916 0.945 0.876
|
19 |
+
dress 45623 18739 0.921 0.965 0.985 0.941
|
20 |
+
jumpsuit 45623 922 0.791 0.826 0.882 0.821
|
21 |
+
cape 45623 152 0.763 0.914 0.909 0.838
|
22 |
+
glasses 45623 4855 0.911 0.845 0.893 0.664
|
23 |
+
hat 45623 2518 0.847 0.911 0.935 0.814
|
24 |
+
headband, head covering, hair accessory 45623 3470 0.7 0.373 0.438 0.272
|
25 |
+
tie 45623 1457 0.743 0.781 0.823 0.538
|
26 |
+
glove 45623 1385 0.746 0.669 0.74 0.552
|
27 |
+
watch 45623 3389 0.679 0.569 0.644 0.406
|
28 |
+
belt 45623 6851 0.673 0.535 0.595 0.386
|
29 |
+
leg warmer 45623 112 0.713 0.446 0.52 0.373
|
30 |
+
tights, stockings 45623 4326 0.757 0.809 0.839 0.677
|
31 |
+
sock 45623 2582 0.708 0.368 0.444 0.281
|
32 |
+
shoe 45623 46374 0.899 0.909 0.946 0.757
|
33 |
+
bag, wallet 45623 7217 0.755 0.751 0.801 0.595
|
34 |
+
scarf 45623 1374 0.651 0.571 0.623 0.426
|
35 |
+
umbrella 45623 135 0.744 0.607 0.687 0.556
|
36 |
+
hood 45623 1226 0.662 0.62 0.649 0.486
|
37 |
+
collar 45623 10159 0.817 0.751 0.826 0.603
|
38 |
+
lapel 45623 5972 0.847 0.802 0.871 0.674
|
39 |
+
epaulette 45623 874 0.644 0.399 0.468 0.264
|
40 |
+
sleeve 45623 59448 0.909 0.907 0.946 0.779
|
41 |
+
pocket 45623 27179 0.721 0.469 0.556 0.336
|
42 |
+
neckline 45623 34258 0.804 0.75 0.814 0.554
|
43 |
+
buckle 45623 3300 0.63 0.361 0.397 0.196
|
44 |
+
zipper 45623 7991 0.609 0.154 0.235 0.104
|
45 |
+
applique 45623 3529 0.515 0.154 0.21 0.133
|
46 |
+
bead 45623 5084 0.529 0.145 0.159 0.105
|
47 |
+
bow 45623 528 0.55 0.134 0.205 0.129
|
48 |
+
flower 45623 1367 0.663 0.266 0.338 0.217
|
49 |
+
fringe 45623 588 0.578 0.259 0.303 0.206
|
50 |
+
ribbon 45623 274 0.395 0.0693 0.11 0.0747
|
51 |
+
rivet 45623 4892 1 0.0015 0.00799 0.0041
|
52 |
+
ruffle 45623 2407 0.567 0.295 0.36 0.266
|
53 |
+
sequin 45623 929 0.464 0.0243 0.0753 0.0537
|
54 |
+
tassel 45623 335 1 0 0.00828 0.00475
|
55 |
+
Speed: 0.1ms preprocess, 0.4ms inference, 0.0ms loss, 0.3ms postprocess per image
|
results/yolovs8-fashionpedia-1.md
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
|
2 |
+
200/200 7.76G 0.6451 0.4508 0.9281 181 640: 100%|██████████| 1426/1426 [03:52<00:00, 6.12it/s]
|
3 |
+
Class Images Instances Box(P R mAP50 mAP50-95): 100%|██████████| 713/713 [01:43<00:00, 6.92it/s]
|
4 |
+
all 45623 333400 0.852 0.737 0.79 0.661
|
5 |
+
200 epochs completed in 18.949 hours
|
6 |
+
|
7 |
+
Class Images Instances Box(P R mAP50 mAP50-95): 100%|██████████| 713/713 [01:50<00:00, 6.43it/s]
|
8 |
+
all 45623 333400 0.852 0.737 0.79 0.661
|
9 |
+
shirt, blouse 45623 6161 0.857 0.887 0.941 0.863
|
10 |
+
top, t-shirt, sweatshirt 45623 16548 0.939 0.92 0.964 0.898
|
11 |
+
sweater 45623 1494 0.936 0.915 0.961 0.915
|
12 |
+
cardigan 45623 1107 0.974 0.948 0.977 0.946
|
13 |
+
jacket 45623 7833 0.982 0.976 0.991 0.97
|
14 |
+
vest 45623 719 0.868 0.847 0.917 0.766
|
15 |
+
pants 45623 12414 0.94 0.985 0.991 0.969
|
16 |
+
shorts 45623 2756 0.95 0.965 0.984 0.915
|
17 |
+
skirt 45623 5046 0.961 0.98 0.992 0.961
|
18 |
+
coat 45623 3124 0.977 0.98 0.993 0.964
|
19 |
+
dress 45623 18739 0.988 0.988 0.995 0.978
|
20 |
+
jumpsuit 45623 922 0.972 0.971 0.991 0.962
|
21 |
+
cape 45623 152 0.948 0.987 0.992 0.955
|
22 |
+
glasses 45623 4855 0.946 0.91 0.945 0.749
|
23 |
+
hat 45623 2518 0.929 0.963 0.98 0.905
|
24 |
+
headband, head covering, hair accessory 45623 3470 0.819 0.533 0.616 0.441
|
25 |
+
tie 45623 1457 0.848 0.898 0.93 0.692
|
26 |
+
glove 45623 1385 0.899 0.853 0.918 0.747
|
27 |
+
watch 45623 3389 0.8 0.709 0.803 0.55
|
28 |
+
belt 45623 6851 0.826 0.721 0.806 0.591
|
29 |
+
leg warmer 45623 112 0.894 0.848 0.876 0.723
|
30 |
+
tights, stockings 45623 4326 0.927 0.921 0.958 0.838
|
31 |
+
sock 45623 2582 0.869 0.542 0.64 0.448
|
32 |
+
shoe 45623 46374 0.958 0.942 0.973 0.829
|
33 |
+
bag, wallet 45623 7217 0.906 0.889 0.938 0.791
|
34 |
+
scarf 45623 1374 0.854 0.811 0.887 0.715
|
35 |
+
umbrella 45623 135 0.906 0.844 0.893 0.789
|
36 |
+
hood 45623 1226 0.843 0.82 0.882 0.735
|
37 |
+
collar 45623 10159 0.903 0.849 0.913 0.725
|
38 |
+
lapel 45623 5972 0.914 0.888 0.942 0.788
|
39 |
+
epaulette 45623 874 0.77 0.594 0.675 0.42
|
40 |
+
sleeve 45623 59448 0.954 0.945 0.973 0.851
|
41 |
+
pocket 45623 27179 0.837 0.63 0.74 0.491
|
42 |
+
neckline 45623 34258 0.894 0.821 0.89 0.661
|
43 |
+
buckle 45623 3300 0.764 0.466 0.545 0.307
|
44 |
+
zipper 45623 7991 0.742 0.342 0.454 0.26
|
45 |
+
applique 45623 3529 0.708 0.474 0.545 0.383
|
46 |
+
bead 45623 5084 0.674 0.237 0.283 0.205
|
47 |
+
bow 45623 528 0.737 0.505 0.611 0.448
|
48 |
+
flower 45623 1367 0.778 0.538 0.628 0.441
|
49 |
+
fringe 45623 588 0.722 0.602 0.65 0.497
|
50 |
+
ribbon 45623 274 0.692 0.31 0.393 0.304
|
51 |
+
rivet 45623 4892 0.564 0.018 0.0309 0.0108
|
52 |
+
ruffle 45623 2407 0.792 0.604 0.715 0.583
|
53 |
+
sequin 45623 929 0.712 0.333 0.404 0.311
|
54 |
+
tassel 45623 335 0.528 0.18 0.228 0.131
|
55 |
+
Speed
|
shared/describe_clothes.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import os
|
3 |
+
from typing import List
|
4 |
+
|
5 |
+
from numpy import ndarray
|
6 |
+
from ultralytics.models import YOLO
|
7 |
+
|
8 |
+
|
9 |
+
def import_describe_model() -> YOLO:
|
10 |
+
current_folder = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))
|
11 |
+
neural_network_file = os.path.join(current_folder, "./yolov8n-fashionpedia-1.torchscript")
|
12 |
+
return YOLO(neural_network_file, task='detect')
|
13 |
+
|
14 |
+
|
15 |
+
def describe_clothes_batch_opencv_bgr(yolo_model_loaded: YOLO,
|
16 |
+
pictures_rgb: List[ndarray],
|
17 |
+
threshold_to_save: float):
|
18 |
+
results = yolo_model_loaded(pictures_rgb, verbose=False, conf=threshold_to_save)
|
19 |
+
|
20 |
+
formatted_results = []
|
21 |
+
for a_result in results:
|
22 |
+
formatted_results.append(json.loads(a_result.tojson()))
|
23 |
+
|
24 |
+
return formatted_results
|
25 |
+
|
26 |
+
|
27 |
+
def describe_single_clothes_opencv_rgb(yolo_model_loaded: YOLO,
|
28 |
+
one_clothes_picture_rgb: ndarray,
|
29 |
+
threshold_to_save: float):
|
30 |
+
return describe_clothes_batch_opencv_bgr(yolo_model_loaded,
|
31 |
+
[one_clothes_picture_rgb],
|
32 |
+
threshold_to_save)[0]
|
shared/yolov8n-fashionpedia-1.torchscript
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:2053a5d7f854e46a06394b6866b15427c3055bdbca95f94821a359c76e6a7b3e
|
3 |
+
size 12505310
|
test/courte.png
ADDED
![]() |
Git LFS Details
|
test/longue.png
ADDED
![]() |
Git LFS Details
|
test/rayure.png
ADDED
![]() |
Git LFS Details
|
test/sans-manche.png
ADDED
![]() |
Git LFS Details
|
test/test_shared.py
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import cv2
|
2 |
+
|
3 |
+
from clothes_description_v1.shared.describe_clothes import import_describe_model, describe_clothes_batch_opencv_bgr, \
|
4 |
+
describe_single_clothes_opencv_bgr
|
5 |
+
|
6 |
+
|
7 |
+
def test_shared_opencv():
|
8 |
+
yolo_model = import_describe_model()
|
9 |
+
courte = cv2.imread('courte.png')
|
10 |
+
results = describe_clothes_batch_opencv_bgr(yolo_model, [courte])
|
11 |
+
print(results)
|
12 |
+
result = describe_single_clothes_opencv_bgr(yolo_model, courte)
|
13 |
+
print(result)
|
14 |
+
|
15 |
+
|
16 |
+
if __name__ == '__main__':
|
17 |
+
test_shared_opencv()
|
test/trois-quart.png
ADDED
![]() |
Git LFS Details
|
yolo8-pre-annotate.ipynb
ADDED
@@ -0,0 +1,315 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"metadata": {
|
5 |
+
"ExecuteTime": {
|
6 |
+
"end_time": "2024-08-28T07:38:11.097948Z",
|
7 |
+
"start_time": "2024-08-28T07:38:10.051274Z"
|
8 |
+
}
|
9 |
+
},
|
10 |
+
"cell_type": "code",
|
11 |
+
"source": [
|
12 |
+
"import json\n",
|
13 |
+
"\n",
|
14 |
+
"from ultralytics import YOLO\n",
|
15 |
+
"import os\n",
|
16 |
+
"\n",
|
17 |
+
"from export_prediction_to_label_studio import export_one_yolo_output_to_label_studio_rectangles"
|
18 |
+
],
|
19 |
+
"id": "688b209f5c7b833e",
|
20 |
+
"outputs": [],
|
21 |
+
"execution_count": 1
|
22 |
+
},
|
23 |
+
{
|
24 |
+
"metadata": {
|
25 |
+
"ExecuteTime": {
|
26 |
+
"end_time": "2024-08-28T07:38:24.127255Z",
|
27 |
+
"start_time": "2024-08-28T07:38:23.889160Z"
|
28 |
+
}
|
29 |
+
},
|
30 |
+
"cell_type": "code",
|
31 |
+
"source": [
|
32 |
+
"%load_ext autoreload\n",
|
33 |
+
"%autoreload 2"
|
34 |
+
],
|
35 |
+
"id": "bcbe8835eff23931",
|
36 |
+
"outputs": [
|
37 |
+
{
|
38 |
+
"name": "stdout",
|
39 |
+
"output_type": "stream",
|
40 |
+
"text": [
|
41 |
+
"The autoreload extension is already loaded. To reload it, use:\n",
|
42 |
+
" %reload_ext autoreload\n"
|
43 |
+
]
|
44 |
+
}
|
45 |
+
],
|
46 |
+
"execution_count": 3
|
47 |
+
},
|
48 |
+
{
|
49 |
+
"metadata": {
|
50 |
+
"ExecuteTime": {
|
51 |
+
"end_time": "2024-08-28T07:38:24.905478Z",
|
52 |
+
"start_time": "2024-08-28T07:38:24.890872Z"
|
53 |
+
}
|
54 |
+
},
|
55 |
+
"cell_type": "code",
|
56 |
+
"source": "yolo_model_loaded = YOLO(\"shared/yolov8n-fashionpedia-1.torchscript\", task='detect')",
|
57 |
+
"id": "f427e4ba2cff784",
|
58 |
+
"outputs": [],
|
59 |
+
"execution_count": 4
|
60 |
+
},
|
61 |
+
{
|
62 |
+
"metadata": {
|
63 |
+
"ExecuteTime": {
|
64 |
+
"end_time": "2024-08-28T07:38:31.339742Z",
|
65 |
+
"start_time": "2024-08-28T07:38:31.325405Z"
|
66 |
+
}
|
67 |
+
},
|
68 |
+
"cell_type": "code",
|
69 |
+
"source": "root_dataset_folder = '/home/louis/vetement_ai/ai_that_look/pattern_detection/dataset/dataset-clothes-8-pattern-v0-labeled-15k'",
|
70 |
+
"id": "f6b614baa08e709",
|
71 |
+
"outputs": [],
|
72 |
+
"execution_count": 5
|
73 |
+
},
|
74 |
+
{
|
75 |
+
"metadata": {
|
76 |
+
"ExecuteTime": {
|
77 |
+
"end_time": "2024-08-28T07:42:03.489627Z",
|
78 |
+
"start_time": "2024-08-28T07:39:47.352446Z"
|
79 |
+
}
|
80 |
+
},
|
81 |
+
"cell_type": "code",
|
82 |
+
"source": [
|
83 |
+
"for root, dirs, files in os.walk(os.path.join(root_dataset_folder, 'images')):\n",
|
84 |
+
" print(root)\n",
|
85 |
+
" for a_file in files:\n",
|
86 |
+
" if a_file.endswith('.jpg') or a_file.endswith('.jpeg') or a_file.endswith('.png'):\n",
|
87 |
+
" result = yolo_model_loaded([os.path.join(root, a_file)], verbose=False)[0]\n",
|
88 |
+
" current_folder = root.split('/')[-1]\n",
|
89 |
+
" export_one_yolo_output_to_label_studio_rectangles(\n",
|
90 |
+
" result,\n",
|
91 |
+
" 'yolov8n-fashionpedia-1-torchscript-c98616b267958c24874073ce091a977ce25489f5',\n",
|
92 |
+
" f'/data/local-files/?d=clothes_pattern/images/{current_folder}/{a_file}',\n",
|
93 |
+
" root.replace('images/', 'pre-annotations/'),\n",
|
94 |
+
" label_studio_from_name='clothes_pattern'\n",
|
95 |
+
" )"
|
96 |
+
],
|
97 |
+
"id": "66db1d64f1f26295",
|
98 |
+
"outputs": [
|
99 |
+
{
|
100 |
+
"name": "stdout",
|
101 |
+
"output_type": "stream",
|
102 |
+
"text": [
|
103 |
+
"/home/louis/vetement_ai/ai_that_look/pattern_detection/dataset/dataset-clothes-8-pattern-v0-labeled-15k/images\n",
|
104 |
+
"/home/louis/vetement_ai/ai_that_look/pattern_detection/dataset/dataset-clothes-8-pattern-v0-labeled-15k/images/plisse_drape_fronce\n",
|
105 |
+
"/home/louis/vetement_ai/ai_that_look/pattern_detection/dataset/dataset-clothes-8-pattern-v0-labeled-15k/images/jersey cotele\n",
|
106 |
+
"/home/louis/vetement_ai/ai_that_look/pattern_detection/dataset/dataset-clothes-8-pattern-v0-labeled-15k/images/non_classe\n",
|
107 |
+
"/home/louis/vetement_ai/ai_that_look/pattern_detection/dataset/dataset-clothes-8-pattern-v0-labeled-15k/images/rayure\n",
|
108 |
+
"/home/louis/vetement_ai/ai_that_look/pattern_detection/dataset/dataset-clothes-8-pattern-v0-labeled-15k/images/motif repete\n",
|
109 |
+
"/home/louis/vetement_ai/ai_that_look/pattern_detection/dataset/dataset-clothes-8-pattern-v0-labeled-15k/images/liberty\n",
|
110 |
+
"/home/louis/vetement_ai/ai_that_look/pattern_detection/dataset/dataset-clothes-8-pattern-v0-labeled-15k/images/motif place\n",
|
111 |
+
"/home/louis/vetement_ai/ai_that_look/pattern_detection/dataset/dataset-clothes-8-pattern-v0-labeled-15k/images/pied de poule\n",
|
112 |
+
"/home/louis/vetement_ai/ai_that_look/pattern_detection/dataset/dataset-clothes-8-pattern-v0-labeled-15k/images/animal\n",
|
113 |
+
"/home/louis/vetement_ai/ai_that_look/pattern_detection/dataset/dataset-clothes-8-pattern-v0-labeled-15k/images/pois\n",
|
114 |
+
"/home/louis/vetement_ai/ai_that_look/pattern_detection/dataset/dataset-clothes-8-pattern-v0-labeled-15k/images/pois_monochrome\n",
|
115 |
+
"/home/louis/vetement_ai/ai_that_look/pattern_detection/dataset/dataset-clothes-8-pattern-v0-labeled-15k/images/carreau\n",
|
116 |
+
"/home/louis/vetement_ai/ai_that_look/pattern_detection/dataset/dataset-clothes-8-pattern-v0-labeled-15k/images/paillette\n",
|
117 |
+
"/home/louis/vetement_ai/ai_that_look/pattern_detection/dataset/dataset-clothes-8-pattern-v0-labeled-15k/images/floral\n"
|
118 |
+
]
|
119 |
+
}
|
120 |
+
],
|
121 |
+
"execution_count": 8
|
122 |
+
},
|
123 |
+
{
|
124 |
+
"metadata": {},
|
125 |
+
"cell_type": "code",
|
126 |
+
"outputs": [],
|
127 |
+
"execution_count": null,
|
128 |
+
"source": "",
|
129 |
+
"id": "513093f0ca4ac231"
|
130 |
+
},
|
131 |
+
{
|
132 |
+
"metadata": {
|
133 |
+
"ExecuteTime": {
|
134 |
+
"end_time": "2024-08-07T14:10:47.957914Z",
|
135 |
+
"start_time": "2024-08-07T14:10:47.920287Z"
|
136 |
+
}
|
137 |
+
},
|
138 |
+
"cell_type": "code",
|
139 |
+
"source": [
|
140 |
+
"kids_output = [\n",
|
141 |
+
" \"body\",\n",
|
142 |
+
" \"chemise\",\n",
|
143 |
+
" \"combinaison\",\n",
|
144 |
+
" \"gigoteuse\",\n",
|
145 |
+
" \"gilet\",\n",
|
146 |
+
" \"jupe\",\n",
|
147 |
+
" \"pantalon\",\n",
|
148 |
+
" \"pyjama\",\n",
|
149 |
+
" \"robe\",\n",
|
150 |
+
" \"tshirt\"\n",
|
151 |
+
"]\n",
|
152 |
+
"\n",
|
153 |
+
"attributes_to_transform_default = {\n",
|
154 |
+
" \"shirt, blouse\": \"chemise\",\n",
|
155 |
+
" \"top, t-shirt, sweatshirt\": \"tshirt\",\n",
|
156 |
+
" \"sweater\": \"gilet\",\n",
|
157 |
+
" \"cardigan\": \"gilet\",\n",
|
158 |
+
" \"jacket\": \"gilet\",\n",
|
159 |
+
" \"vest\": \"gilet\",\n",
|
160 |
+
" \"pants\": \"pantalon\",\n",
|
161 |
+
" \"shorts\": \"pantalon\",\n",
|
162 |
+
" \"skirt\": \"jupe\",\n",
|
163 |
+
" \"coat\": \"gilet\",\n",
|
164 |
+
" \"dress\": \"robe\",\n",
|
165 |
+
" \"jumpsuit\": \"combinaison\",\n",
|
166 |
+
"}\n",
|
167 |
+
"attributes_to_keep = {\n",
|
168 |
+
" \"sleeve\": \"manche\",\n",
|
169 |
+
" \"pocket\": \"poche\",\n",
|
170 |
+
" \"buckle\": \"zip\",\n",
|
171 |
+
" \"collar\": \"col\",\n",
|
172 |
+
" \"lapel\": \"revers\",\n",
|
173 |
+
" \"hood\": \"capuche\",\n",
|
174 |
+
"}"
|
175 |
+
],
|
176 |
+
"id": "aa14e86f94358cb1",
|
177 |
+
"outputs": [],
|
178 |
+
"execution_count": 27
|
179 |
+
},
|
180 |
+
{
|
181 |
+
"metadata": {
|
182 |
+
"ExecuteTime": {
|
183 |
+
"end_time": "2024-08-07T14:53:59.250707Z",
|
184 |
+
"start_time": "2024-08-07T14:53:57.334490Z"
|
185 |
+
}
|
186 |
+
},
|
187 |
+
"cell_type": "code",
|
188 |
+
"source": [
|
189 |
+
"attributes_to_transform = {k: 'pyjama' for k in attributes_to_transform_default.keys()}\n",
|
190 |
+
"\n",
|
191 |
+
"attributes_to_label = {\n",
|
192 |
+
" **attributes_to_transform,\n",
|
193 |
+
" **attributes_to_keep,\n",
|
194 |
+
"}\n",
|
195 |
+
"\n",
|
196 |
+
"assert len(set(attributes_to_transform.keys()).intersection(set(attributes_to_transform.values()))) == 0\n",
|
197 |
+
"\n",
|
198 |
+
"score_threshold = 0.5\n",
|
199 |
+
"for root, dirs, files in os.walk(os.path.join(root_dataset_folder, 'pre-annotations', 'pyjama')):\n",
|
200 |
+
" for a_file in files:\n",
|
201 |
+
" if a_file.endswith('.json'):\n",
|
202 |
+
" filepath = os.path.join(root, a_file)\n",
|
203 |
+
" with open(filepath, 'r') as f:\n",
|
204 |
+
" file_content_json = json.load(f)\n",
|
205 |
+
"\n",
|
206 |
+
" predictions = file_content_json['predictions']\n",
|
207 |
+
" annotations = predictions[0]['result']\n",
|
208 |
+
" annotations = [p for p in annotations if p['score'] >= score_threshold]\n",
|
209 |
+
"\n",
|
210 |
+
" updated_annotations = []\n",
|
211 |
+
" for an_annotation in annotations:\n",
|
212 |
+
" rectangle_labels = an_annotation['value']['rectanglelabels']\n",
|
213 |
+
"\n",
|
214 |
+
" updated_labels = []\n",
|
215 |
+
" for a_label in rectangle_labels:\n",
|
216 |
+
" if a_label in attributes_to_label.keys():\n",
|
217 |
+
" updated_labels.append(attributes_to_label[a_label])\n",
|
218 |
+
" elif a_label in attributes_to_label.values():\n",
|
219 |
+
" # to make it idempotent\n",
|
220 |
+
" updated_labels.append(a_label)\n",
|
221 |
+
"\n",
|
222 |
+
" if len(updated_labels) > 0:\n",
|
223 |
+
" an_annotation['value']['rectanglelabels'] = updated_labels\n",
|
224 |
+
" updated_annotations.append(an_annotation)\n",
|
225 |
+
"\n",
|
226 |
+
" with open(filepath, 'w') as f:\n",
|
227 |
+
" json.dump({\n",
|
228 |
+
" **file_content_json,\n",
|
229 |
+
" 'predictions': [\n",
|
230 |
+
" {\n",
|
231 |
+
" **predictions[0],\n",
|
232 |
+
" \"result\": updated_annotations\n",
|
233 |
+
" }\n",
|
234 |
+
" ]\n",
|
235 |
+
" }, f)"
|
236 |
+
],
|
237 |
+
"id": "4df42b4df9ca7f17",
|
238 |
+
"outputs": [],
|
239 |
+
"execution_count": 43
|
240 |
+
},
|
241 |
+
{
|
242 |
+
"metadata": {
|
243 |
+
"ExecuteTime": {
|
244 |
+
"end_time": "2024-08-28T07:44:23.257797Z",
|
245 |
+
"start_time": "2024-08-28T07:44:22.988904Z"
|
246 |
+
}
|
247 |
+
},
|
248 |
+
"cell_type": "code",
|
249 |
+
"source": [
|
250 |
+
"# largest surface to specific label\n",
|
251 |
+
"score_threshold = 0.5\n",
|
252 |
+
"folder = 'rayure'\n",
|
253 |
+
"for root, dirs, files in os.walk(os.path.join(root_dataset_folder, 'pre-annotations', folder)):\n",
|
254 |
+
" for a_file in files:\n",
|
255 |
+
" if a_file.endswith('.json'):\n",
|
256 |
+
" filepath = os.path.join(root, a_file)\n",
|
257 |
+
" with open(filepath, 'r') as f:\n",
|
258 |
+
" file_content_json = json.load(f)\n",
|
259 |
+
"\n",
|
260 |
+
" predictions = file_content_json['predictions']\n",
|
261 |
+
" annotations = predictions[0]['result']\n",
|
262 |
+
" annotations = list(filter(lambda x: x[\"score\"] > 0.5, annotations))\n",
|
263 |
+
" if len(annotations) > 0: \n",
|
264 |
+
" only_annotation = max(annotations, key=lambda p: p['value']['width'] * p['value']['height'])\n",
|
265 |
+
" only_annotation['value']['rectanglelabels'] = [folder]\n",
|
266 |
+
" result = [only_annotation]\n",
|
267 |
+
" else:\n",
|
268 |
+
" result = []\n",
|
269 |
+
"\n",
|
270 |
+
" with open(filepath, 'w') as f:\n",
|
271 |
+
" json.dump({\n",
|
272 |
+
" **file_content_json,\n",
|
273 |
+
" 'predictions': [\n",
|
274 |
+
" {\n",
|
275 |
+
" **predictions[0],\n",
|
276 |
+
" \"result\": result\n",
|
277 |
+
" }\n",
|
278 |
+
" ]\n",
|
279 |
+
" }, f)"
|
280 |
+
],
|
281 |
+
"id": "bba8c29714c2ab7b",
|
282 |
+
"outputs": [],
|
283 |
+
"execution_count": 21
|
284 |
+
},
|
285 |
+
{
|
286 |
+
"metadata": {},
|
287 |
+
"cell_type": "code",
|
288 |
+
"outputs": [],
|
289 |
+
"execution_count": null,
|
290 |
+
"source": "",
|
291 |
+
"id": "262fe6ef762f57d1"
|
292 |
+
}
|
293 |
+
],
|
294 |
+
"metadata": {
|
295 |
+
"kernelspec": {
|
296 |
+
"display_name": "Python 3",
|
297 |
+
"language": "python",
|
298 |
+
"name": "python3"
|
299 |
+
},
|
300 |
+
"language_info": {
|
301 |
+
"codemirror_mode": {
|
302 |
+
"name": "ipython",
|
303 |
+
"version": 2
|
304 |
+
},
|
305 |
+
"file_extension": ".py",
|
306 |
+
"mimetype": "text/x-python",
|
307 |
+
"name": "python",
|
308 |
+
"nbconvert_exporter": "python",
|
309 |
+
"pygments_lexer": "ipython2",
|
310 |
+
"version": "2.7.6"
|
311 |
+
}
|
312 |
+
},
|
313 |
+
"nbformat": 4,
|
314 |
+
"nbformat_minor": 5
|
315 |
+
}
|
yolo8.ipynb
ADDED
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"metadata": {},
|
5 |
+
"cell_type": "code",
|
6 |
+
"source": [
|
7 |
+
"from ultralytics import YOLO\n",
|
8 |
+
"\n",
|
9 |
+
"original_model_name = 'yolov8s'\n",
|
10 |
+
"original_model_nickname = 'fashionpedia'\n",
|
11 |
+
"yolo_model = YOLO(original_model_name)"
|
12 |
+
],
|
13 |
+
"id": "688b209f5c7b833e",
|
14 |
+
"outputs": [],
|
15 |
+
"execution_count": null
|
16 |
+
},
|
17 |
+
{
|
18 |
+
"metadata": {},
|
19 |
+
"cell_type": "code",
|
20 |
+
"source": [
|
21 |
+
"results = yolo_model.train(data='fashionpedia.yaml', epochs=300, batch=32, save_period=1, plots=True,\n",
|
22 |
+
" name=f'{original_model_name}-{original_model_nickname}', exist_ok=True, resume=False,\n",
|
23 |
+
" deterministic=False, close_mosaic=50, val=False,\n",
|
24 |
+
" label_smoothing=0.05, workers=20, cache=False, task=\"detect\",\n",
|
25 |
+
" translate=0.2, degrees=30, shear=10, mosaic=0.8, perspective=0.000_01\n",
|
26 |
+
" )"
|
27 |
+
],
|
28 |
+
"id": "dd14c466280421c4",
|
29 |
+
"outputs": [],
|
30 |
+
"execution_count": null
|
31 |
+
},
|
32 |
+
{
|
33 |
+
"metadata": {},
|
34 |
+
"cell_type": "code",
|
35 |
+
"source": [],
|
36 |
+
"id": "8884f7e383561fc2",
|
37 |
+
"outputs": [],
|
38 |
+
"execution_count": null
|
39 |
+
},
|
40 |
+
{
|
41 |
+
"metadata": {},
|
42 |
+
"cell_type": "code",
|
43 |
+
"source": [
|
44 |
+
"# load saved model\n",
|
45 |
+
"yolo_model_loaded = YOLO(\"shared/yolov8n-fashionpedia-1.torchscript\", task='detect')"
|
46 |
+
],
|
47 |
+
"id": "f427e4ba2cff784",
|
48 |
+
"outputs": [],
|
49 |
+
"execution_count": null
|
50 |
+
},
|
51 |
+
{
|
52 |
+
"metadata": {},
|
53 |
+
"cell_type": "code",
|
54 |
+
"source": [
|
55 |
+
"# Run batched inference on a list of images\n",
|
56 |
+
"inference_results = yolo_model_loaded(['./test/courte.png',\n",
|
57 |
+
" './test/longue.png',\n",
|
58 |
+
" './test/rayure.png',\n",
|
59 |
+
" './test/sans-manche.png',\n",
|
60 |
+
" './test/trois-quart.png'\n",
|
61 |
+
" ], verbose=False)\n",
|
62 |
+
"for result in inference_results:\n",
|
63 |
+
" boxes = result.boxes # Boxes object for bounding box outputs\n",
|
64 |
+
" probs = result.probs # Probs object for classification outputs\n",
|
65 |
+
" result.show() # display to screen"
|
66 |
+
],
|
67 |
+
"id": "f0815af787b52825",
|
68 |
+
"outputs": [],
|
69 |
+
"execution_count": null
|
70 |
+
},
|
71 |
+
{
|
72 |
+
"metadata": {},
|
73 |
+
"cell_type": "code",
|
74 |
+
"source": [],
|
75 |
+
"id": "793f625e9139f76d",
|
76 |
+
"outputs": [],
|
77 |
+
"execution_count": null
|
78 |
+
}
|
79 |
+
],
|
80 |
+
"metadata": {
|
81 |
+
"kernelspec": {
|
82 |
+
"display_name": "Python 3",
|
83 |
+
"language": "python",
|
84 |
+
"name": "python3"
|
85 |
+
},
|
86 |
+
"language_info": {
|
87 |
+
"codemirror_mode": {
|
88 |
+
"name": "ipython",
|
89 |
+
"version": 2
|
90 |
+
},
|
91 |
+
"file_extension": ".py",
|
92 |
+
"mimetype": "text/x-python",
|
93 |
+
"name": "python",
|
94 |
+
"nbconvert_exporter": "python",
|
95 |
+
"pygments_lexer": "ipython2",
|
96 |
+
"version": "2.7.6"
|
97 |
+
}
|
98 |
+
},
|
99 |
+
"nbformat": 4,
|
100 |
+
"nbformat_minor": 5
|
101 |
+
}
|