-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdownload.py
413 lines (293 loc) · 14.4 KB
/
download.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
import os
import zipfile
import requests
import io
import h5py
import numpy as np
import requests
from matplotlib.pyplot import imread, imsave
from scipy.io import loadmat
from scipy.ndimage import gaussian_filter
import gdown
def download_salicon(data_path):
"""Downloads the SALICON dataset. Three folders are then created that
contain the stimuli, binary fixation maps, and blurred saliency
distributions respectively.
Args:
data_path (str): Defines the path where the dataset will be
downloaded and extracted to.
.. seealso:: The code for downloading files from google drive is based
on the solution provided at [https://bit.ly/2JSVgMQ].
"""
print(">> Downloading SALICON dataset...", end="", flush=True)
default_path = data_path + "salicon/"
fixations_path = default_path + "fixations/"
saliency_path = default_path + "saliency/"
os.makedirs(fixations_path, exist_ok=True)
os.makedirs(saliency_path, exist_ok=True)
ids = ["1g8j-hTT-51IG1UFwP0xTGhLdgIUCW5e5",
"1P-jeZXCsjoKO79OhFUgnj6FGcyvmLDPj",
"1PnO7szbdub1559LfjYHMy65EDC4VhJC8"]
urls = ["https://drive.google.com/uc?id=" +
i + "&export=download" for i in ids]
save_paths = [default_path, fixations_path, saliency_path]
session = requests.Session()
for count, url in enumerate(urls):
gdown.download(url, data_path + "tmp.zip", quiet=False)
with zipfile.ZipFile(data_path + "tmp.zip", "r") as zip_ref:
for file in zip_ref.namelist():
if "test" not in file:
zip_ref.extract(file, save_paths[count])
os.rename(default_path + "images", default_path + "stimuli")
os.remove(data_path + "tmp.zip")
print("done!", flush=True)
def download_mit1003(data_path):
"""Downloads the MIT1003 dataset. Three folders are then created that
contain the stimuli, binary fixation maps, and blurred saliency
distributions respectively.
Args:
data_path (str): Defines the path where the dataset will be
downloaded and extracted to.
"""
print(">> Downloading MIT1003 dataset...", end="", flush=True)
default_path = data_path + "mit1003/"
stimuli_path = default_path + "stimuli/"
fixations_path = default_path + "fixations/"
saliency_path = default_path + "saliency/"
os.makedirs(stimuli_path, exist_ok=True)
os.makedirs(fixations_path, exist_ok=True)
os.makedirs(saliency_path, exist_ok=True)
url = "https://people.csail.mit.edu/tjudd/WherePeopleLook/ALLSTIMULI.zip"
with open(data_path + "tmp.zip", "wb") as f:
f.write(requests.get(url).content)
with zipfile.ZipFile(data_path + "tmp.zip", "r") as zip_ref:
for file in zip_ref.namelist():
if file.endswith(".jpeg"):
file_name = os.path.split(file)[1]
file_path = stimuli_path + file_name
with open(file_path, "wb") as stimulus:
stimulus.write(zip_ref.read(file))
url = "https://people.csail.mit.edu/tjudd/WherePeopleLook/ALLFIXATIONMAPS.zip"
with open(data_path + "tmp.zip", "wb") as f:
f.write(requests.get(url).content)
with zipfile.ZipFile(data_path + "tmp.zip", "r") as zip_ref:
for file in zip_ref.namelist():
file_name = os.path.split(file)[1]
if file.endswith("Pts.jpg"):
file_path = fixations_path + file_name
# this file is mistakenly included in the dataset and can be ignored
if file_name == "i05june05_static_street_boston_p1010764fixPts.jpg":
continue
with open(file_path, "wb") as fixations:
fixations.write(zip_ref.read(file))
elif file.endswith("Map.jpg"):
file_path = saliency_path + file_name
with open(file_path, "wb") as saliency:
saliency.write(zip_ref.read(file))
os.remove(data_path + "tmp.zip")
print("done!", flush=True)
def download_cat2000(data_path):
"""Downloads the CAT2000 dataset. Three folders are then created that
contain the stimuli, binary fixation maps, and blurred saliency
distributions respectively.
Args:
data_path (str): Defines the path where the dataset will be
downloaded and extracted to.
"""
print(">> Downloading CAT2000 dataset...", end="", flush=True)
default_path = data_path + "cat2000/"
os.makedirs(data_path, exist_ok=True)
url = "http://saliency.mit.edu/trainSet.zip"
with open(data_path + "tmp.zip", "wb") as f:
f.write(requests.get(url).content)
with zipfile.ZipFile(data_path + "tmp.zip", "r") as zip_ref:
for file in zip_ref.namelist():
if not("Output" in file or "allFixData" in file):
zip_ref.extract(file, data_path)
os.rename(data_path + "trainSet/", default_path)
os.rename(default_path + "Stimuli", default_path + "stimuli")
os.rename(default_path + "FIXATIONLOCS", default_path + "fixations")
os.rename(default_path + "FIXATIONMAPS", default_path + "saliency")
os.remove(data_path + "tmp.zip")
print("done!", flush=True)
def download_pascals(data_path):
"""Downloads the PASCAL-S dataset. Three folders are then created that
contain the stimuli, binary fixation maps, and blurred saliency
distributions respectively.
Args:
data_path (str): Defines the path where the dataset will be
downloaded and extracted to.
"""
print(">> Downloading PASCALS dataset...", end="", flush=True)
default_path = data_path + "pascals/"
stimuli_path = default_path + "stimuli/"
fixations_path = default_path + "fixations/"
saliency_path = default_path + "saliency/"
os.makedirs(stimuli_path, exist_ok=True)
os.makedirs(fixations_path, exist_ok=True)
os.makedirs(saliency_path, exist_ok=True)
url = "http://cbs.ic.gatech.edu/salobj/download/salObj.zip"
with open(data_path + "tmp.zip", "wb") as f:
f.write(requests.get(url).content)
with zipfile.ZipFile(data_path + "tmp.zip", "r") as zip_ref:
for file in zip_ref.namelist():
file_name = os.path.basename(file)
if file.endswith(".jpg") and "imgs/pascal" in file:
file_path = stimuli_path + file_name
with open(file_path, "wb") as stimulus:
stimulus.write(zip_ref.read(file))
elif file.endswith(".png") and "pascal/humanFix" in file:
file_path = saliency_path + file_name
with open(file_path, "wb") as saliency:
saliency.write(zip_ref.read(file))
elif "pascalFix.mat" in file:
loaded_zip = io.BytesIO(zip_ref.read(file))
with h5py.File(loaded_zip, "r") as f:
fixations = np.array(f.get("fixCell"))[0]
fixations_list = []
for reference in fixations:
obj = np.array(f[reference])
obj = np.stack((obj[0], obj[1]), axis=-1)
fixations_list.append(obj)
elif "pascalSize.mat" in file:
loaded_zip = io.BytesIO(zip_ref.read(file))
with h5py.File(loaded_zip, "r") as f:
sizes = np.array(f.get("sizeData"))
sizes = np.transpose(sizes, (1, 0))
for idx, value in enumerate(fixations_list):
size = [int(x) for x in sizes[idx]]
fixations_map = np.zeros(size)
for fixation in value:
fixations_map[int(fixation[0]) - 1,
int(fixation[1]) - 1] = 1
file_name = str(idx + 1) + ".png"
file_path = fixations_path + file_name
imsave(file_path, fixations_map, cmap="gray")
os.remove(data_path + "tmp.zip")
print("done!", flush=True)
def download_osie(data_path):
"""Downloads the OSIE dataset. Three folders are then created that
contain the stimuli, binary fixation maps, and blurred saliency
distributions respectively.
Args:
data_path (str): Defines the path where the dataset will be
downloaded and extracted to.
"""
print(">> Downloading OSIE dataset...", end="", flush=True)
default_path = data_path + "osie/"
stimuli_path = default_path + "stimuli/"
fixations_path = default_path + "fixations/"
saliency_path = default_path + "saliency/"
os.makedirs(stimuli_path, exist_ok=True)
os.makedirs(fixations_path, exist_ok=True)
os.makedirs(saliency_path, exist_ok=True)
url = "https://github.com/NUS-VIP/predicting-human-gaze-beyond-pixels/archive/master.zip"
with open(data_path + "tmp.zip", "wb") as f:
f.write(requests.get(url).content)
with zipfile.ZipFile(data_path + "tmp.zip", "r") as zip_ref:
for file in zip_ref.namelist():
file_name = os.path.basename(file)
if file.endswith(".jpg") and "data/stimuli" in file:
file_path = stimuli_path + file_name
with open(file_path, "wb") as stimulus:
stimulus.write(zip_ref.read(file))
elif file_name == "fixations.mat":
loaded_zip = io.BytesIO(zip_ref.read(file))
loaded_mat = loadmat(loaded_zip)["fixations"]
for idx, value in enumerate(loaded_mat):
subjects = value[0][0][0][1]
fixations_map = np.zeros((600, 800))
for subject in subjects:
x_vals = subject[0][0][0][0][0]
y_vals = subject[0][0][0][1][0]
fixations = np.stack((y_vals, x_vals), axis=-1)
fixations = fixations.astype(int)
fixations_map[fixations[:, 0],
fixations[:, 1]] = 1
file_name = str(1001 + idx) + ".png"
saliency_map = gaussian_filter(fixations_map, 16)
imsave(saliency_path + file_name, saliency_map, cmap="gray")
imsave(fixations_path + file_name, fixations_map, cmap="gray")
os.remove(data_path + "tmp.zip")
print("done!", flush=True)
def download_dutomron(data_path):
"""Downloads the DUT-OMRON dataset. Three folders are then created that
contain the stimuli, binary fixation maps, and blurred saliency
distributions respectively.
Args:
data_path (str): Defines the path where the dataset will be
downloaded and extracted to.
"""
print(">> Downloading DUTOMRON dataset...", end="", flush=True)
default_path = data_path + "dutomron/"
stimuli_path = default_path + "stimuli/"
fixations_path = default_path + "fixations/"
saliency_path = default_path + "saliency/"
os.makedirs(stimuli_path, exist_ok=True)
os.makedirs(fixations_path, exist_ok=True)
os.makedirs(saliency_path, exist_ok=True)
url = "http://saliencydetection.net/dut-omron/download/DUT-OMRON-image.zip"
with open(data_path + "tmp.zip", "wb") as f:
f.write(requests.get(url).content)
with zipfile.ZipFile(data_path + "tmp.zip", "r") as zip_ref:
for file in zip_ref.namelist():
if file.endswith(".jpg") and not "._" in file:
file_name = os.path.basename(file)
file_path = stimuli_path + file_name
with open(file_path, "wb") as stimulus:
stimulus.write(zip_ref.read(file))
url = "http://saliencydetection.net/dut-omron/download/DUT-OMRON-eye-fixations.zip"
with open(data_path + "tmp.zip", "wb") as f:
f.write(requests.get(url).content)
with zipfile.ZipFile(data_path + "tmp.zip", "r") as zip_ref:
for file in zip_ref.namelist():
if file.endswith(".mat") and not "._" in file:
file_name = os.path.basename(file)
file_name = os.path.splitext(file_name)[0] + ".png"
loaded_zip = io.BytesIO(zip_ref.read(file))
fixations = loadmat(loaded_zip)["s"]
sorted_idx = fixations[:, 2].argsort()
fixations = fixations[sorted_idx]
size = fixations[0, :2]
fixations_map = np.zeros((size[1], size[0]))
fixations_map[fixations[1:, 1],
fixations[1:, 0]] = 1
saliency_map = gaussian_filter(fixations_map, 16)
imsave(saliency_path + file_name, saliency_map, cmap="gray")
imsave(fixations_path + file_name, fixations_map, cmap="gray")
os.remove(data_path + "tmp.zip")
print("done!", flush=True)
def download_fiwi(data_path):
"""Downloads the FIWI dataset. Three folders are then created that
contain the stimuli, binary fixation maps, and blurred saliency
distributions respectively.
Args:
data_path (str): Defines the path where the dataset will be
downloaded and extracted to.
"""
print(">> Downloading FIWI dataset...", end="", flush=True)
default_path = data_path + "fiwi/"
stimuli_path = default_path + "stimuli/"
fixations_path = default_path + "fixations/"
saliency_path = default_path + "saliency/"
os.makedirs(stimuli_path, exist_ok=True)
os.makedirs(fixations_path, exist_ok=True)
os.makedirs(saliency_path, exist_ok=True)
url = "https://www.dropbox.com/s/30nxg2uwd1wpb80/webpage_dataset.zip?dl=1"
with open(data_path + "tmp.zip", "wb") as f:
f.write(requests.get(url).content)
with zipfile.ZipFile(data_path + "tmp.zip", "r") as zip_ref:
for file in zip_ref.namelist():
file_name = os.path.basename(file)
if file.endswith(".png") and "stimuli" in file:
file_path = stimuli_path + file_name
with open(file_path, "wb") as stimulus:
stimulus.write(zip_ref.read(file))
elif file.endswith(".png") and "all5" in file:
loaded_zip = io.BytesIO(zip_ref.read(file))
fixations = imread(loaded_zip)
saliency = gaussian_filter(fixations, 30)
imsave(saliency_path + file_name, saliency, cmap="gray")
imsave(fixations_path + file_name, fixations, cmap="gray")
os.remove(data_path + "tmp.zip")
print("done!", flush=True)