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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"id": "5f3bbfca",
|
7 |
+
"metadata": {},
|
8 |
+
"outputs": [],
|
9 |
+
"source": [
|
10 |
+
"import json\n",
|
11 |
+
"import requests\n",
|
12 |
+
"import time\n"
|
13 |
+
]
|
14 |
+
},
|
15 |
+
{
|
16 |
+
"cell_type": "code",
|
17 |
+
"execution_count": 2,
|
18 |
+
"id": "b82b8cda",
|
19 |
+
"metadata": {},
|
20 |
+
"outputs": [],
|
21 |
+
"source": [
|
22 |
+
"! mkdir esci_imgs"
|
23 |
+
]
|
24 |
+
},
|
25 |
+
{
|
26 |
+
"cell_type": "code",
|
27 |
+
"execution_count": 3,
|
28 |
+
"id": "e80143a7",
|
29 |
+
"metadata": {},
|
30 |
+
"outputs": [
|
31 |
+
{
|
32 |
+
"name": "stdout",
|
33 |
+
"output_type": "stream",
|
34 |
+
"text": [
|
35 |
+
" 1480714 collection-imgs.json\r\n"
|
36 |
+
]
|
37 |
+
}
|
38 |
+
],
|
39 |
+
"source": [
|
40 |
+
"! wc -l collection-imgs.json"
|
41 |
+
]
|
42 |
+
},
|
43 |
+
{
|
44 |
+
"cell_type": "code",
|
45 |
+
"execution_count": 4,
|
46 |
+
"id": "a7d602a2",
|
47 |
+
"metadata": {},
|
48 |
+
"outputs": [
|
49 |
+
{
|
50 |
+
"name": "stdout",
|
51 |
+
"output_type": "stream",
|
52 |
+
"text": [
|
53 |
+
"{\"doc_id\": 0, \"image_url\": \"https://m.media-amazon.com/images/I/815fXDqFFQL.__AC_SX300_SY300_QL70_ML2_.jpg\"}\r\n",
|
54 |
+
"{\"doc_id\": 1, \"image_url\": \"https://m.media-amazon.com/images/I/81bdoltQWVL.__AC_SY300_SX300_QL70_FMwebp_.jpg\"}\r\n",
|
55 |
+
"{\"doc_id\": 2, \"image_url\": \"https://m.media-amazon.com/images/W/WEBP_402378-T2/images/I/71DqTKVRneL.__AC_SY445_SX342_QL70_FMwebp_.jpg\"}\r\n",
|
56 |
+
"{\"doc_id\": 3, \"image_url\": \"https://m.media-amazon.com/images/I/819OiK-OD6L.__AC_SY445_SX342_QL70_ML2_.jpg\"}\r\n",
|
57 |
+
"{\"doc_id\": 4, \"image_url\": \"https://m.media-amazon.com/images/I/61NemNt5X6L.__AC_SX300_SY300_QL70_ML2_.jpg\"}\r\n",
|
58 |
+
"{\"doc_id\": 6, \"image_url\": \"https://m.media-amazon.com/images/I/41On0AlK82L.__AC_SX300_SY300_QL70_FMwebp_.jpg\"}\r\n",
|
59 |
+
"{\"doc_id\": 7, \"image_url\": \"\"}\r\n",
|
60 |
+
"{\"doc_id\": 9, \"image_url\": \"\"}\r\n",
|
61 |
+
"{\"doc_id\": 10, \"image_url\": \"https://m.media-amazon.com/images/W/WEBP_402378-T1/images/I/813GQqEX9UL.__AC_SX300_SY300_QL70_FMwebp_.jpg\"}\r\n",
|
62 |
+
"{\"doc_id\": 11, \"image_url\": \"https://m.media-amazon.com/images/W/WEBP_402378-T1/images/I/71qbCHQo2vL.__AC_SY445_SX342_QL70_FMwebp_.jpg\"}\r\n"
|
63 |
+
]
|
64 |
+
}
|
65 |
+
],
|
66 |
+
"source": [
|
67 |
+
"! head collection-imgs.json"
|
68 |
+
]
|
69 |
+
},
|
70 |
+
{
|
71 |
+
"cell_type": "code",
|
72 |
+
"execution_count": 5,
|
73 |
+
"id": "146b3a26",
|
74 |
+
"metadata": {},
|
75 |
+
"outputs": [
|
76 |
+
{
|
77 |
+
"name": "stdout",
|
78 |
+
"output_type": "stream",
|
79 |
+
"text": [
|
80 |
+
"1480714\n"
|
81 |
+
]
|
82 |
+
}
|
83 |
+
],
|
84 |
+
"source": [
|
85 |
+
"id2imgurl = {}\n",
|
86 |
+
"with open('collection-imgs.json','r') as f:\n",
|
87 |
+
" for l in f:\n",
|
88 |
+
" j = json.loads(l)\n",
|
89 |
+
" id2imgurl[j['doc_id']] = j['image_url']\n",
|
90 |
+
"print(len(id2imgurl))"
|
91 |
+
]
|
92 |
+
},
|
93 |
+
{
|
94 |
+
"cell_type": "code",
|
95 |
+
"execution_count": 6,
|
96 |
+
"id": "693fb9ce",
|
97 |
+
"metadata": {},
|
98 |
+
"outputs": [],
|
99 |
+
"source": [
|
100 |
+
"target_url = id2imgurl[2]"
|
101 |
+
]
|
102 |
+
},
|
103 |
+
{
|
104 |
+
"cell_type": "code",
|
105 |
+
"execution_count": 7,
|
106 |
+
"id": "093e563c",
|
107 |
+
"metadata": {},
|
108 |
+
"outputs": [],
|
109 |
+
"source": [
|
110 |
+
"img_data = requests.get(target_url).content\n",
|
111 |
+
"with open('esci_imgs/' + str(2) + '.jpg', 'wb') as handler:\n",
|
112 |
+
" handler.write(img_data)"
|
113 |
+
]
|
114 |
+
},
|
115 |
+
{
|
116 |
+
"cell_type": "code",
|
117 |
+
"execution_count": null,
|
118 |
+
"id": "11aa2665",
|
119 |
+
"metadata": {},
|
120 |
+
"outputs": [],
|
121 |
+
"source": [
|
122 |
+
"! ls esci_imgs | wc -l"
|
123 |
+
]
|
124 |
+
},
|
125 |
+
{
|
126 |
+
"cell_type": "code",
|
127 |
+
"execution_count": null,
|
128 |
+
"id": "fac1d815",
|
129 |
+
"metadata": {},
|
130 |
+
"outputs": [
|
131 |
+
{
|
132 |
+
"name": "stdout",
|
133 |
+
"output_type": "stream",
|
134 |
+
"text": [
|
135 |
+
"Succefully downloaded 0 Images\n",
|
136 |
+
"UnSuccefully downloaded 0 Images\n",
|
137 |
+
"Succefully downloaded 888 Images\n",
|
138 |
+
"UnSuccefully downloaded 112 Images\n",
|
139 |
+
"Succefully downloaded 1772 Images\n",
|
140 |
+
"UnSuccefully downloaded 228 Images\n",
|
141 |
+
"Succefully downloaded 2648 Images\n",
|
142 |
+
"UnSuccefully downloaded 352 Images\n",
|
143 |
+
"Succefully downloaded 3543 Images\n",
|
144 |
+
"UnSuccefully downloaded 457 Images\n",
|
145 |
+
"Succefully downloaded 4430 Images\n",
|
146 |
+
"UnSuccefully downloaded 570 Images\n",
|
147 |
+
"Succefully downloaded 5299 Images\n",
|
148 |
+
"UnSuccefully downloaded 701 Images\n",
|
149 |
+
"Succefully downloaded 6177 Images\n",
|
150 |
+
"UnSuccefully downloaded 823 Images\n",
|
151 |
+
"Succefully downloaded 7066 Images\n",
|
152 |
+
"UnSuccefully downloaded 934 Images\n",
|
153 |
+
"Succefully downloaded 7950 Images\n",
|
154 |
+
"UnSuccefully downloaded 1050 Images\n",
|
155 |
+
"Succefully downloaded 8825 Images\n",
|
156 |
+
"UnSuccefully downloaded 1175 Images\n",
|
157 |
+
"Succefully downloaded 9724 Images\n",
|
158 |
+
"UnSuccefully downloaded 1276 Images\n",
|
159 |
+
"Succefully downloaded 10607 Images\n",
|
160 |
+
"UnSuccefully downloaded 1393 Images\n",
|
161 |
+
"Succefully downloaded 11495 Images\n",
|
162 |
+
"UnSuccefully downloaded 1505 Images\n",
|
163 |
+
"Succefully downloaded 12393 Images\n",
|
164 |
+
"UnSuccefully downloaded 1607 Images\n",
|
165 |
+
"Succefully downloaded 13279 Images\n",
|
166 |
+
"UnSuccefully downloaded 1721 Images\n",
|
167 |
+
"Succefully downloaded 14181 Images\n",
|
168 |
+
"UnSuccefully downloaded 1819 Images\n",
|
169 |
+
"Succefully downloaded 15046 Images\n",
|
170 |
+
"UnSuccefully downloaded 1954 Images\n",
|
171 |
+
"Succefully downloaded 15917 Images\n",
|
172 |
+
"UnSuccefully downloaded 2083 Images\n",
|
173 |
+
"Succefully downloaded 16796 Images\n",
|
174 |
+
"UnSuccefully downloaded 2204 Images\n",
|
175 |
+
"Succefully downloaded 17663 Images\n",
|
176 |
+
"UnSuccefully downloaded 2337 Images\n",
|
177 |
+
"Succefully downloaded 18546 Images\n",
|
178 |
+
"UnSuccefully downloaded 2454 Images\n",
|
179 |
+
"Succefully downloaded 19442 Images\n",
|
180 |
+
"UnSuccefully downloaded 2558 Images\n",
|
181 |
+
"Succefully downloaded 20312 Images\n",
|
182 |
+
"UnSuccefully downloaded 2688 Images\n",
|
183 |
+
"Succefully downloaded 21198 Images\n",
|
184 |
+
"UnSuccefully downloaded 2802 Images\n",
|
185 |
+
"Succefully downloaded 22083 Images\n",
|
186 |
+
"UnSuccefully downloaded 2917 Images\n",
|
187 |
+
"Succefully downloaded 22973 Images\n",
|
188 |
+
"UnSuccefully downloaded 3027 Images\n",
|
189 |
+
"Succefully downloaded 23860 Images\n",
|
190 |
+
"UnSuccefully downloaded 3140 Images\n",
|
191 |
+
"Succefully downloaded 24744 Images\n",
|
192 |
+
"UnSuccefully downloaded 3256 Images\n",
|
193 |
+
"Succefully downloaded 25635 Images\n",
|
194 |
+
"UnSuccefully downloaded 3365 Images\n",
|
195 |
+
"Succefully downloaded 26524 Images\n",
|
196 |
+
"UnSuccefully downloaded 3476 Images\n",
|
197 |
+
"Succefully downloaded 27404 Images\n",
|
198 |
+
"UnSuccefully downloaded 3596 Images\n",
|
199 |
+
"Succefully downloaded 28282 Images\n",
|
200 |
+
"UnSuccefully downloaded 3718 Images\n",
|
201 |
+
"Succefully downloaded 29156 Images\n",
|
202 |
+
"UnSuccefully downloaded 3844 Images\n",
|
203 |
+
"Succefully downloaded 30046 Images\n",
|
204 |
+
"UnSuccefully downloaded 3954 Images\n",
|
205 |
+
"Succefully downloaded 30943 Images\n",
|
206 |
+
"UnSuccefully downloaded 4057 Images\n",
|
207 |
+
"Succefully downloaded 31806 Images\n",
|
208 |
+
"UnSuccefully downloaded 4194 Images\n",
|
209 |
+
"Succefully downloaded 32686 Images\n",
|
210 |
+
"UnSuccefully downloaded 4314 Images\n",
|
211 |
+
"Succefully downloaded 33576 Images\n",
|
212 |
+
"UnSuccefully downloaded 4424 Images\n",
|
213 |
+
"Succefully downloaded 34469 Images\n",
|
214 |
+
"UnSuccefully downloaded 4531 Images\n",
|
215 |
+
"Succefully downloaded 35349 Images\n",
|
216 |
+
"UnSuccefully downloaded 4651 Images\n",
|
217 |
+
"Succefully downloaded 36232 Images\n",
|
218 |
+
"UnSuccefully downloaded 4768 Images\n",
|
219 |
+
"Succefully downloaded 37113 Images\n",
|
220 |
+
"UnSuccefully downloaded 4887 Images\n",
|
221 |
+
"Succefully downloaded 37993 Images\n",
|
222 |
+
"UnSuccefully downloaded 5007 Images\n",
|
223 |
+
"Succefully downloaded 38866 Images\n",
|
224 |
+
"UnSuccefully downloaded 5134 Images\n",
|
225 |
+
"Succefully downloaded 39752 Images\n",
|
226 |
+
"UnSuccefully downloaded 5248 Images\n",
|
227 |
+
"Succefully downloaded 40646 Images\n",
|
228 |
+
"UnSuccefully downloaded 5354 Images\n",
|
229 |
+
"Succefully downloaded 41535 Images\n",
|
230 |
+
"UnSuccefully downloaded 5465 Images\n",
|
231 |
+
"Succefully downloaded 42421 Images\n",
|
232 |
+
"UnSuccefully downloaded 5579 Images\n",
|
233 |
+
"Succefully downloaded 43313 Images\n",
|
234 |
+
"UnSuccefully downloaded 5687 Images\n",
|
235 |
+
"Succefully downloaded 44177 Images\n",
|
236 |
+
"UnSuccefully downloaded 5823 Images\n",
|
237 |
+
"Succefully downloaded 45057 Images\n",
|
238 |
+
"UnSuccefully downloaded 5943 Images\n",
|
239 |
+
"Succefully downloaded 45933 Images\n",
|
240 |
+
"UnSuccefully downloaded 6067 Images\n",
|
241 |
+
"Succefully downloaded 46810 Images\n",
|
242 |
+
"UnSuccefully downloaded 6190 Images\n",
|
243 |
+
"Succefully downloaded 47697 Images\n",
|
244 |
+
"UnSuccefully downloaded 6303 Images\n",
|
245 |
+
"Succefully downloaded 48579 Images\n",
|
246 |
+
"UnSuccefully downloaded 6421 Images\n",
|
247 |
+
"Succefully downloaded 49449 Images\n",
|
248 |
+
"UnSuccefully downloaded 6551 Images\n",
|
249 |
+
"Succefully downloaded 50330 Images\n",
|
250 |
+
"UnSuccefully downloaded 6670 Images\n",
|
251 |
+
"Succefully downloaded 51235 Images\n",
|
252 |
+
"UnSuccefully downloaded 6765 Images\n",
|
253 |
+
"Succefully downloaded 52113 Images\n",
|
254 |
+
"UnSuccefully downloaded 6887 Images\n",
|
255 |
+
"Succefully downloaded 52999 Images\n",
|
256 |
+
"UnSuccefully downloaded 7001 Images\n",
|
257 |
+
"Succefully downloaded 53877 Images\n",
|
258 |
+
"UnSuccefully downloaded 7123 Images\n",
|
259 |
+
"Succefully downloaded 54776 Images\n",
|
260 |
+
"UnSuccefully downloaded 7224 Images\n",
|
261 |
+
"Succefully downloaded 55646 Images\n",
|
262 |
+
"UnSuccefully downloaded 7354 Images\n",
|
263 |
+
"Succefully downloaded 56530 Images\n",
|
264 |
+
"UnSuccefully downloaded 7470 Images\n",
|
265 |
+
"Succefully downloaded 57423 Images\n",
|
266 |
+
"UnSuccefully downloaded 7577 Images\n",
|
267 |
+
"Succefully downloaded 58300 Images\n",
|
268 |
+
"UnSuccefully downloaded 7700 Images\n",
|
269 |
+
"Succefully downloaded 59205 Images\n",
|
270 |
+
"UnSuccefully downloaded 7795 Images\n",
|
271 |
+
"Succefully downloaded 60084 Images\n",
|
272 |
+
"UnSuccefully downloaded 7916 Images\n",
|
273 |
+
"Succefully downloaded 60990 Images\n",
|
274 |
+
"UnSuccefully downloaded 8010 Images\n",
|
275 |
+
"Succefully downloaded 61888 Images\n",
|
276 |
+
"UnSuccefully downloaded 8112 Images\n",
|
277 |
+
"Succefully downloaded 62786 Images\n",
|
278 |
+
"UnSuccefully downloaded 8214 Images\n",
|
279 |
+
"Succefully downloaded 63662 Images\n",
|
280 |
+
"UnSuccefully downloaded 8338 Images\n",
|
281 |
+
"Succefully downloaded 64559 Images\n",
|
282 |
+
"UnSuccefully downloaded 8441 Images\n",
|
283 |
+
"Succefully downloaded 65441 Images\n",
|
284 |
+
"UnSuccefully downloaded 8559 Images\n",
|
285 |
+
"Succefully downloaded 66332 Images\n",
|
286 |
+
"UnSuccefully downloaded 8668 Images\n",
|
287 |
+
"Succefully downloaded 67216 Images\n",
|
288 |
+
"UnSuccefully downloaded 8784 Images\n",
|
289 |
+
"Succefully downloaded 68077 Images\n",
|
290 |
+
"UnSuccefully downloaded 8923 Images\n",
|
291 |
+
"Succefully downloaded 68968 Images\n",
|
292 |
+
"UnSuccefully downloaded 9032 Images\n",
|
293 |
+
"Succefully downloaded 69852 Images\n",
|
294 |
+
"UnSuccefully downloaded 9148 Images\n",
|
295 |
+
"Succefully downloaded 70744 Images\n",
|
296 |
+
"UnSuccefully downloaded 9256 Images\n",
|
297 |
+
"Succefully downloaded 71625 Images\n",
|
298 |
+
"UnSuccefully downloaded 9375 Images\n",
|
299 |
+
"Succefully downloaded 72518 Images\n",
|
300 |
+
"UnSuccefully downloaded 9482 Images\n",
|
301 |
+
"Succefully downloaded 73403 Images\n",
|
302 |
+
"UnSuccefully downloaded 9597 Images\n"
|
303 |
+
]
|
304 |
+
}
|
305 |
+
],
|
306 |
+
"source": [
|
307 |
+
"missed_list = []\n",
|
308 |
+
"hit_list = []\n",
|
309 |
+
"count = 0\n",
|
310 |
+
"for i in id2imgurl:\n",
|
311 |
+
" if count % 100 == 0:\n",
|
312 |
+
" time.sleep(1)\n",
|
313 |
+
" if count % 1000 == 0:\n",
|
314 |
+
" print(\"Succefully downloaded {} Images\".format(len(hit_list)))\n",
|
315 |
+
" print(\"UnSuccefully downloaded {} Images\".format(len(missed_list)))\n",
|
316 |
+
" target_url = id2imgurl[i]\n",
|
317 |
+
" count += 1\n",
|
318 |
+
" try:\n",
|
319 |
+
" img_data = requests.get(target_url).content\n",
|
320 |
+
" with open('esci_imgs/' + str(i) + '.jpg', 'wb') as handler:\n",
|
321 |
+
" handler.write(img_data)\n",
|
322 |
+
" hit_list.append(i)\n",
|
323 |
+
" except:\n",
|
324 |
+
" missed_list.append(i)"
|
325 |
+
]
|
326 |
+
},
|
327 |
+
{
|
328 |
+
"cell_type": "code",
|
329 |
+
"execution_count": null,
|
330 |
+
"id": "51271307",
|
331 |
+
"metadata": {},
|
332 |
+
"outputs": [],
|
333 |
+
"source": []
|
334 |
+
}
|
335 |
+
],
|
336 |
+
"metadata": {
|
337 |
+
"kernelspec": {
|
338 |
+
"display_name": "Python 3 (ipykernel)",
|
339 |
+
"language": "python",
|
340 |
+
"name": "python3"
|
341 |
+
},
|
342 |
+
"language_info": {
|
343 |
+
"codemirror_mode": {
|
344 |
+
"name": "ipython",
|
345 |
+
"version": 3
|
346 |
+
},
|
347 |
+
"file_extension": ".py",
|
348 |
+
"mimetype": "text/x-python",
|
349 |
+
"name": "python",
|
350 |
+
"nbconvert_exporter": "python",
|
351 |
+
"pygments_lexer": "ipython3",
|
352 |
+
"version": "3.9.12"
|
353 |
+
}
|
354 |
+
},
|
355 |
+
"nbformat": 4,
|
356 |
+
"nbformat_minor": 5
|
357 |
+
}
|