huseinzol05 commited on
Commit
401b84c
β€’
1 Parent(s): 1fa8a65

Upload prepare-blip-images.ipynb

Browse files
Files changed (1) hide show
  1. prepare-blip-images.ipynb +317 -0
prepare-blip-images.ipynb ADDED
@@ -0,0 +1,317 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "11397531",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "import json\n",
11
+ "from glob import glob\n",
12
+ "from tqdm import tqdm\n",
13
+ "import os\n",
14
+ "import shutil"
15
+ ]
16
+ },
17
+ {
18
+ "cell_type": "code",
19
+ "execution_count": 4,
20
+ "id": "639a635c",
21
+ "metadata": {},
22
+ "outputs": [
23
+ {
24
+ "name": "stdout",
25
+ "output_type": "stream",
26
+ "text": [
27
+ "macaw-multimodal/synthetic-multi-images-multi-audio-relationship.jsonl\r\n",
28
+ "macaw-multimodal/synthetic-multi-images-relationship.jsonl\r\n"
29
+ ]
30
+ }
31
+ ],
32
+ "source": [
33
+ "!ls macaw-multimodal/synthetic-*images*.jsonl"
34
+ ]
35
+ },
36
+ {
37
+ "cell_type": "code",
38
+ "execution_count": 5,
39
+ "id": "230fda70",
40
+ "metadata": {},
41
+ "outputs": [
42
+ {
43
+ "data": {
44
+ "text/plain": [
45
+ "['macaw-multimodal/synthetic-multi-images-relationship.jsonl',\n",
46
+ " 'macaw-multimodal/synthetic-multi-images-multi-audio-relationship.jsonl']"
47
+ ]
48
+ },
49
+ "execution_count": 5,
50
+ "metadata": {},
51
+ "output_type": "execute_result"
52
+ }
53
+ ],
54
+ "source": [
55
+ "files = glob('macaw-multimodal/synthetic-*images*.jsonl')\n",
56
+ "files"
57
+ ]
58
+ },
59
+ {
60
+ "cell_type": "code",
61
+ "execution_count": 6,
62
+ "id": "dbdd6fd6",
63
+ "metadata": {},
64
+ "outputs": [],
65
+ "source": [
66
+ "!mkdir filtered-blip-images"
67
+ ]
68
+ },
69
+ {
70
+ "cell_type": "code",
71
+ "execution_count": 9,
72
+ "id": "fc2f5947",
73
+ "metadata": {},
74
+ "outputs": [
75
+ {
76
+ "name": "stderr",
77
+ "output_type": "stream",
78
+ "text": [
79
+ "100000it [00:01, 88185.31it/s]\n",
80
+ "59400it [00:01, 52003.73it/s]\n"
81
+ ]
82
+ }
83
+ ],
84
+ "source": [
85
+ "images = []\n",
86
+ "\n",
87
+ "for f in files:\n",
88
+ " with open(f) as fopen:\n",
89
+ " for l in tqdm(fopen):\n",
90
+ " l = json.loads(l)\n",
91
+ " for f_ in l['filename']:\n",
92
+ " if f_.endswith('.jpg'):\n",
93
+ " images.append(f_)\n",
94
+ "# break\n",
95
+ "# img = l['image']\n",
96
+ "# f_img = f'train2014/COCO_train2014_{img}'\n",
97
+ "# if not os.path.exists(f_img):\n",
98
+ "# continue\n",
99
+ "# shutil.copyfile(f_img, os.path.join('filtered-llava-images', img))"
100
+ ]
101
+ },
102
+ {
103
+ "cell_type": "code",
104
+ "execution_count": 10,
105
+ "id": "75ff4044",
106
+ "metadata": {
107
+ "scrolled": true
108
+ },
109
+ "outputs": [
110
+ {
111
+ "data": {
112
+ "text/plain": [
113
+ "259400"
114
+ ]
115
+ },
116
+ "execution_count": 10,
117
+ "metadata": {},
118
+ "output_type": "execute_result"
119
+ }
120
+ ],
121
+ "source": [
122
+ "len(images)"
123
+ ]
124
+ },
125
+ {
126
+ "cell_type": "code",
127
+ "execution_count": 18,
128
+ "id": "dda18075",
129
+ "metadata": {},
130
+ "outputs": [
131
+ {
132
+ "name": "stderr",
133
+ "output_type": "stream",
134
+ "text": [
135
+ "100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 238135/238135 [17:04<00:00, 232.47it/s] \n"
136
+ ]
137
+ }
138
+ ],
139
+ "source": [
140
+ "for img in tqdm(list(set(images))):\n",
141
+ " f = os.path.join('blip', img)\n",
142
+ " folder = f.split('/')[1]\n",
143
+ " os.makedirs(os.path.join('filtered-blip-images', folder), exist_ok = True)\n",
144
+ " shutil.copyfile(f, os.path.join('filtered-blip-images', img))"
145
+ ]
146
+ },
147
+ {
148
+ "cell_type": "code",
149
+ "execution_count": 19,
150
+ "id": "bbc499fe",
151
+ "metadata": {},
152
+ "outputs": [
153
+ {
154
+ "name": "stdout",
155
+ "output_type": "stream",
156
+ "text": [
157
+ "12G\tfiltered-blip-images\r\n"
158
+ ]
159
+ }
160
+ ],
161
+ "source": [
162
+ "!du -hs filtered-blip-images"
163
+ ]
164
+ },
165
+ {
166
+ "cell_type": "code",
167
+ "execution_count": 20,
168
+ "id": "29021779",
169
+ "metadata": {},
170
+ "outputs": [],
171
+ "source": [
172
+ "!~/7zz -v5g a filtered-blip-images.7z filtered-blip-images > /dev/null"
173
+ ]
174
+ },
175
+ {
176
+ "cell_type": "code",
177
+ "execution_count": 21,
178
+ "id": "ac2eb144",
179
+ "metadata": {},
180
+ "outputs": [],
181
+ "source": [
182
+ "from huggingface_hub import HfApi\n",
183
+ "api = HfApi()"
184
+ ]
185
+ },
186
+ {
187
+ "cell_type": "code",
188
+ "execution_count": 23,
189
+ "id": "34db3d8d",
190
+ "metadata": {},
191
+ "outputs": [
192
+ {
193
+ "name": "stdout",
194
+ "output_type": "stream",
195
+ "text": [
196
+ "filtered-blip-images.7z.003\n"
197
+ ]
198
+ },
199
+ {
200
+ "data": {
201
+ "application/vnd.jupyter.widget-view+json": {
202
+ "model_id": "35049f783ad84ea0b66c3c45bd2718d9",
203
+ "version_major": 2,
204
+ "version_minor": 0
205
+ },
206
+ "text/plain": [
207
+ "filtered-blip-images.7z.003: 0%| | 0.00/747M [00:00<?, ?B/s]"
208
+ ]
209
+ },
210
+ "metadata": {},
211
+ "output_type": "display_data"
212
+ },
213
+ {
214
+ "name": "stdout",
215
+ "output_type": "stream",
216
+ "text": [
217
+ "filtered-blip-images.7z.001\n"
218
+ ]
219
+ },
220
+ {
221
+ "data": {
222
+ "application/vnd.jupyter.widget-view+json": {
223
+ "model_id": "ceca06d30dc442f8a1da0f5ee10c8431",
224
+ "version_major": 2,
225
+ "version_minor": 0
226
+ },
227
+ "text/plain": [
228
+ "filtered-blip-images.7z.001: 0%| | 0.00/5.37G [00:00<?, ?B/s]"
229
+ ]
230
+ },
231
+ "metadata": {},
232
+ "output_type": "display_data"
233
+ },
234
+ {
235
+ "name": "stdout",
236
+ "output_type": "stream",
237
+ "text": [
238
+ "filtered-blip-images.7z.002\n"
239
+ ]
240
+ },
241
+ {
242
+ "data": {
243
+ "application/vnd.jupyter.widget-view+json": {
244
+ "model_id": "8fbb602e8f494ec680fda22bfafcad2f",
245
+ "version_major": 2,
246
+ "version_minor": 0
247
+ },
248
+ "text/plain": [
249
+ "filtered-blip-images.7z.002: 0%| | 0.00/5.37G [00:00<?, ?B/s]"
250
+ ]
251
+ },
252
+ "metadata": {},
253
+ "output_type": "display_data"
254
+ }
255
+ ],
256
+ "source": [
257
+ "for f in glob('*.7z.*'):\n",
258
+ " print(f)\n",
259
+ " api.upload_file(\n",
260
+ " path_or_fileobj=f,\n",
261
+ " path_in_repo=f,\n",
262
+ " repo_id='mesolitica/translated-LLaVA-Pretrain',\n",
263
+ " repo_type='dataset',\n",
264
+ ")"
265
+ ]
266
+ },
267
+ {
268
+ "cell_type": "code",
269
+ "execution_count": 24,
270
+ "id": "f4916183",
271
+ "metadata": {},
272
+ "outputs": [],
273
+ "source": [
274
+ "!rm *.7z.*"
275
+ ]
276
+ },
277
+ {
278
+ "cell_type": "code",
279
+ "execution_count": 25,
280
+ "id": "f29eaac3",
281
+ "metadata": {},
282
+ "outputs": [
283
+ {
284
+ "name": "stdout",
285
+ "output_type": "stream",
286
+ "text": [
287
+ "27G\tblip\r\n"
288
+ ]
289
+ }
290
+ ],
291
+ "source": [
292
+ "!du -hs blip"
293
+ ]
294
+ }
295
+ ],
296
+ "metadata": {
297
+ "kernelspec": {
298
+ "display_name": "Python 3 (ipykernel)",
299
+ "language": "python",
300
+ "name": "python3"
301
+ },
302
+ "language_info": {
303
+ "codemirror_mode": {
304
+ "name": "ipython",
305
+ "version": 3
306
+ },
307
+ "file_extension": ".py",
308
+ "mimetype": "text/x-python",
309
+ "name": "python",
310
+ "nbconvert_exporter": "python",
311
+ "pygments_lexer": "ipython3",
312
+ "version": "3.10.12"
313
+ }
314
+ },
315
+ "nbformat": 4,
316
+ "nbformat_minor": 5
317
+ }