dnth commited on
Commit
cbe8eae
1 Parent(s): 0d9ab38

update notebooks

Browse files
Files changed (3) hide show
  1. add_image.ipynb +393 -0
  2. doc-image-10.parquet +3 -0
  3. merge.ipynb +0 -0
add_image.ipynb ADDED
@@ -0,0 +1,393 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "from datasets import load_dataset\n",
10
+ "\n",
11
+ "dataset = load_dataset(\"dnth/pets-enriched\")"
12
+ ]
13
+ },
14
+ {
15
+ "cell_type": "code",
16
+ "execution_count": 2,
17
+ "metadata": {},
18
+ "outputs": [
19
+ {
20
+ "data": {
21
+ "text/plain": [
22
+ "{'filename': Value(dtype='string', id=None),\n",
23
+ " 'caption': Value(dtype='string', id=None),\n",
24
+ " 'image_labels': Sequence(feature=Value(dtype='string', id=None), length=-1, id=None),\n",
25
+ " 'objects': [{'bbox': Sequence(feature=Value(dtype='float64', id=None), length=-1, id=None),\n",
26
+ " 'confidence': Value(dtype='float64', id=None),\n",
27
+ " 'label': Value(dtype='string', id=None)}]}"
28
+ ]
29
+ },
30
+ "execution_count": 2,
31
+ "metadata": {},
32
+ "output_type": "execute_result"
33
+ }
34
+ ],
35
+ "source": [
36
+ "dataset['train'].features"
37
+ ]
38
+ },
39
+ {
40
+ "cell_type": "code",
41
+ "execution_count": 3,
42
+ "metadata": {},
43
+ "outputs": [
44
+ {
45
+ "data": {
46
+ "text/plain": [
47
+ "{'filename': 'oxford-iiit-pet/images/Abyssinian_144.jpg',\n",
48
+ " 'caption': 'a cat standing on a wooden floor next to a glass',\n",
49
+ " 'image_labels': ['cat'],\n",
50
+ " 'objects': [{'bbox': [91.0, 13.0, 408.0, 345.0],\n",
51
+ " 'confidence': 0.9800000190734863,\n",
52
+ " 'label': 'cat'}]}"
53
+ ]
54
+ },
55
+ "execution_count": 3,
56
+ "metadata": {},
57
+ "output_type": "execute_result"
58
+ }
59
+ ],
60
+ "source": [
61
+ "dataset['train'][0]"
62
+ ]
63
+ },
64
+ {
65
+ "cell_type": "code",
66
+ "execution_count": 4,
67
+ "metadata": {},
68
+ "outputs": [
69
+ {
70
+ "data": {
71
+ "text/plain": [
72
+ "{'filename': 'oxford-iiit-pet/images/Abyssinian_100.jpg',\n",
73
+ " 'caption': 'a cat is sitting in a bag',\n",
74
+ " 'image_labels': ['cat'],\n",
75
+ " 'objects': [{'bbox': [48.0, 72.0, 288.0, 371.0],\n",
76
+ " 'confidence': 0.9539999961853027,\n",
77
+ " 'label': 'cat'},\n",
78
+ " {'bbox': [0.0, 31.0, 148.0, 92.0],\n",
79
+ " 'confidence': 0.4880000054836273,\n",
80
+ " 'label': 'strap'},\n",
81
+ " {'bbox': [241.0, 341.0, 153.0, 160.0],\n",
82
+ " 'confidence': 0.4309999942779541,\n",
83
+ " 'label': 'strap'},\n",
84
+ " {'bbox': [193.0, 1.0, 202.0, 179.0],\n",
85
+ " 'confidence': 0.3700000047683716,\n",
86
+ " 'label': 'pillow'}]}"
87
+ ]
88
+ },
89
+ "execution_count": 4,
90
+ "metadata": {},
91
+ "output_type": "execute_result"
92
+ }
93
+ ],
94
+ "source": [
95
+ "dataset['train'][10]"
96
+ ]
97
+ },
98
+ {
99
+ "cell_type": "code",
100
+ "execution_count": 5,
101
+ "metadata": {},
102
+ "outputs": [],
103
+ "source": [
104
+ "import os\n",
105
+ "from PIL import Image\n",
106
+ "import io\n",
107
+ "import datasets\n",
108
+ "\n",
109
+ "def load_image(example):\n",
110
+ " image_path = example['filename'] # Assuming 'filename' contains the path\n",
111
+ " if os.path.exists(image_path):\n",
112
+ " with Image.open(image_path) as img:\n",
113
+ " buf = io.BytesIO()\n",
114
+ " img.save(buf, format='PNG')\n",
115
+ " example['image'] = buf.getvalue()\n",
116
+ " else:\n",
117
+ " example['image'] = None\n",
118
+ " return example\n",
119
+ "\n",
120
+ "# Assuming your dataset is called 'dataset'\n",
121
+ "dataset = dataset.map(load_image)\n",
122
+ "\n",
123
+ "# Update the features of the dataset\n",
124
+ "dataset = dataset.cast_column(\"image\", datasets.Image())"
125
+ ]
126
+ },
127
+ {
128
+ "cell_type": "code",
129
+ "execution_count": 6,
130
+ "metadata": {},
131
+ "outputs": [
132
+ {
133
+ "data": {
134
+ "text/plain": [
135
+ "Dataset({\n",
136
+ " features: ['filename', 'caption', 'image_labels', 'objects', 'image'],\n",
137
+ " num_rows: 7275\n",
138
+ "})"
139
+ ]
140
+ },
141
+ "execution_count": 6,
142
+ "metadata": {},
143
+ "output_type": "execute_result"
144
+ }
145
+ ],
146
+ "source": [
147
+ "dataset['train']"
148
+ ]
149
+ },
150
+ {
151
+ "cell_type": "code",
152
+ "execution_count": 10,
153
+ "metadata": {},
154
+ "outputs": [
155
+ {
156
+ "data": {
157
+ "application/vnd.jupyter.widget-view+json": {
158
+ "model_id": "f35fb0f0588e477b985cc75dfdc00569",
159
+ "version_major": 2,
160
+ "version_minor": 0
161
+ },
162
+ "text/plain": [
163
+ "Uploading the dataset shards: 0%| | 0/5 [00:00<?, ?it/s]"
164
+ ]
165
+ },
166
+ "metadata": {},
167
+ "output_type": "display_data"
168
+ },
169
+ {
170
+ "data": {
171
+ "application/vnd.jupyter.widget-view+json": {
172
+ "model_id": "ca299917858a4d9e8b2264da5c609be1",
173
+ "version_major": 2,
174
+ "version_minor": 0
175
+ },
176
+ "text/plain": [
177
+ "Map: 0%| | 0/1455 [00:00<?, ? examples/s]"
178
+ ]
179
+ },
180
+ "metadata": {},
181
+ "output_type": "display_data"
182
+ },
183
+ {
184
+ "data": {
185
+ "application/vnd.jupyter.widget-view+json": {
186
+ "model_id": "21e2c7755e1c4890b8710a0fc3fb2e25",
187
+ "version_major": 2,
188
+ "version_minor": 0
189
+ },
190
+ "text/plain": [
191
+ "Creating parquet from Arrow format: 0%| | 0/15 [00:00<?, ?ba/s]"
192
+ ]
193
+ },
194
+ "metadata": {},
195
+ "output_type": "display_data"
196
+ },
197
+ {
198
+ "data": {
199
+ "application/vnd.jupyter.widget-view+json": {
200
+ "model_id": "05c256e8a8b54c4a8a9c905f7fcf78ab",
201
+ "version_major": 2,
202
+ "version_minor": 0
203
+ },
204
+ "text/plain": [
205
+ "Map: 0%| | 0/1455 [00:00<?, ? examples/s]"
206
+ ]
207
+ },
208
+ "metadata": {},
209
+ "output_type": "display_data"
210
+ },
211
+ {
212
+ "data": {
213
+ "application/vnd.jupyter.widget-view+json": {
214
+ "model_id": "0aa862e525f8403fa1489c11a08d9626",
215
+ "version_major": 2,
216
+ "version_minor": 0
217
+ },
218
+ "text/plain": [
219
+ "Creating parquet from Arrow format: 0%| | 0/15 [00:00<?, ?ba/s]"
220
+ ]
221
+ },
222
+ "metadata": {},
223
+ "output_type": "display_data"
224
+ },
225
+ {
226
+ "data": {
227
+ "application/vnd.jupyter.widget-view+json": {
228
+ "model_id": "1ae4a025e0a54f92a7932a2bfe104789",
229
+ "version_major": 2,
230
+ "version_minor": 0
231
+ },
232
+ "text/plain": [
233
+ "Map: 0%| | 0/1455 [00:00<?, ? examples/s]"
234
+ ]
235
+ },
236
+ "metadata": {},
237
+ "output_type": "display_data"
238
+ },
239
+ {
240
+ "data": {
241
+ "application/vnd.jupyter.widget-view+json": {
242
+ "model_id": "da530e1109d6437dbdd39fe40e091724",
243
+ "version_major": 2,
244
+ "version_minor": 0
245
+ },
246
+ "text/plain": [
247
+ "Creating parquet from Arrow format: 0%| | 0/15 [00:00<?, ?ba/s]"
248
+ ]
249
+ },
250
+ "metadata": {},
251
+ "output_type": "display_data"
252
+ },
253
+ {
254
+ "data": {
255
+ "application/vnd.jupyter.widget-view+json": {
256
+ "model_id": "9b71da5cc1cb4f12af4b04fc5597e4d1",
257
+ "version_major": 2,
258
+ "version_minor": 0
259
+ },
260
+ "text/plain": [
261
+ "Map: 0%| | 0/1455 [00:00<?, ? examples/s]"
262
+ ]
263
+ },
264
+ "metadata": {},
265
+ "output_type": "display_data"
266
+ },
267
+ {
268
+ "data": {
269
+ "application/vnd.jupyter.widget-view+json": {
270
+ "model_id": "a3f3ec986b044612a653fc7e27faa3b0",
271
+ "version_major": 2,
272
+ "version_minor": 0
273
+ },
274
+ "text/plain": [
275
+ "Creating parquet from Arrow format: 0%| | 0/15 [00:00<?, ?ba/s]"
276
+ ]
277
+ },
278
+ "metadata": {},
279
+ "output_type": "display_data"
280
+ },
281
+ {
282
+ "data": {
283
+ "application/vnd.jupyter.widget-view+json": {
284
+ "model_id": "8761c776867044e0a39c5be67b5e4536",
285
+ "version_major": 2,
286
+ "version_minor": 0
287
+ },
288
+ "text/plain": [
289
+ "Map: 0%| | 0/1455 [00:00<?, ? examples/s]"
290
+ ]
291
+ },
292
+ "metadata": {},
293
+ "output_type": "display_data"
294
+ },
295
+ {
296
+ "data": {
297
+ "application/vnd.jupyter.widget-view+json": {
298
+ "model_id": "2d64775cae0e46c2b96db080977f7caf",
299
+ "version_major": 2,
300
+ "version_minor": 0
301
+ },
302
+ "text/plain": [
303
+ "Creating parquet from Arrow format: 0%| | 0/15 [00:00<?, ?ba/s]"
304
+ ]
305
+ },
306
+ "metadata": {},
307
+ "output_type": "display_data"
308
+ },
309
+ {
310
+ "data": {
311
+ "application/vnd.jupyter.widget-view+json": {
312
+ "model_id": "81348e1aa35f41b9b68e178c9f7fd203",
313
+ "version_major": 2,
314
+ "version_minor": 0
315
+ },
316
+ "text/plain": [
317
+ "README.md: 0%| | 0.00/478 [00:00<?, ?B/s]"
318
+ ]
319
+ },
320
+ "metadata": {},
321
+ "output_type": "display_data"
322
+ },
323
+ {
324
+ "data": {
325
+ "text/plain": [
326
+ "CommitInfo(commit_url='https://huggingface.co/datasets/dnth/pets-enriched/commit/1e0711eae3c228b4bdd45096d28ae167f1ae49e7', commit_message='Upload dataset', commit_description='', oid='1e0711eae3c228b4bdd45096d28ae167f1ae49e7', pr_url=None, pr_revision=None, pr_num=None)"
327
+ ]
328
+ },
329
+ "execution_count": 10,
330
+ "metadata": {},
331
+ "output_type": "execute_result"
332
+ }
333
+ ],
334
+ "source": [
335
+ "dataset.push_to_hub('dnth/pets-enriched')"
336
+ ]
337
+ },
338
+ {
339
+ "cell_type": "code",
340
+ "execution_count": 9,
341
+ "metadata": {},
342
+ "outputs": [
343
+ {
344
+ "data": {
345
+ "application/vnd.jupyter.widget-view+json": {
346
+ "model_id": "421ffbe1dea442bc956d20ccedc539f8",
347
+ "version_major": 2,
348
+ "version_minor": 0
349
+ },
350
+ "text/plain": [
351
+ "VBox(children=(HTML(value='<center> <img\\nsrc=https://huggingface.co/front/assets/huggingface_logo-noborder.sv…"
352
+ ]
353
+ },
354
+ "metadata": {},
355
+ "output_type": "display_data"
356
+ }
357
+ ],
358
+ "source": [
359
+ "from huggingface_hub import login\n",
360
+ "\n",
361
+ "login()"
362
+ ]
363
+ },
364
+ {
365
+ "cell_type": "code",
366
+ "execution_count": null,
367
+ "metadata": {},
368
+ "outputs": [],
369
+ "source": []
370
+ }
371
+ ],
372
+ "metadata": {
373
+ "kernelspec": {
374
+ "display_name": "Python 3",
375
+ "language": "python",
376
+ "name": "python3"
377
+ },
378
+ "language_info": {
379
+ "codemirror_mode": {
380
+ "name": "ipython",
381
+ "version": 3
382
+ },
383
+ "file_extension": ".py",
384
+ "mimetype": "text/x-python",
385
+ "name": "python",
386
+ "nbconvert_exporter": "python",
387
+ "pygments_lexer": "ipython3",
388
+ "version": "3.10.12"
389
+ }
390
+ },
391
+ "nbformat": 4,
392
+ "nbformat_minor": 2
393
+ }
doc-image-10.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:31d22c17d8178238571741400429875d3e7d23d23cef144affcfb3df3af0869c
3
+ size 224379
merge.ipynb CHANGED
The diff for this file is too large to render. See raw diff