-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy path001_down_data.py
122 lines (77 loc) · 3.25 KB
/
001_down_data.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
#!/usr/bin/env python3
import requests
import os
import shutil
"""
Script to download
Wider Face Training Images
Wider Face Validation Images
from Google Drive using Python3.6
http://mmlab.ie.cuhk.edu.hk/projects/WIDERFace/
Wider_face_split is included in repo
"""
# credits: https://stackoverflow.com/a/16664766
# https://stackoverflow.com/questions/16664526/howto-download-file-from-drive-api-using-python-script
def download_file_from_google_drive(id, destination):
def get_confirm_token(response):
for key, value in response.cookies.items():
if key.startswith('download_warning'):
return value
return None
def save_response_content(response, destination):
CHUNK_SIZE = 32768
with open(destination, "wb") as f:
for chunk in response.iter_content(CHUNK_SIZE):
if chunk: # filter out keep-alive new chunks
f.write(chunk)
URL = "https://docs.google.com/uc?export=download"
session = requests.Session()
response = session.get(URL, params = { 'id' : id }, stream = True)
token = get_confirm_token(response)
if token:
params = { 'id' : id, 'confirm' : token }
response = session.get(URL, params = params, stream = True)
save_response_content(response, destination)
# The script
curr_path = os.getcwd()
models_path = os.path.join(curr_path,"data")
# make dir => wider_data in folder
try:
os.makedirs(models_path)
except Exception as e:
pass
if os.path.exists(os.path.join(models_path,"train.zip")) == False:
print("downloading.. train.zip -- 1.47GB")
download_file_from_google_drive("0B6eKvaijfFUDQUUwd21EckhUbWs", os.path.join(models_path,"train.zip"))
if os.path.exists(os.path.join(models_path,"val.zip")) == False:
print("downloading.. val.zip -- 362.8MB")
download_file_from_google_drive("0B6eKvaijfFUDd3dIRmpvSk8tLUk", os.path.join(models_path,"val.zip"))
print("files downloaded")
# unzip the files
import zipfile
if os.path.exists(os.path.join(models_path,"WIDER_train")) == False:
with zipfile.ZipFile(os.path.join(models_path,"train.zip"),"r") as zip_ref:
zip_ref.extractall(models_path)
if os.path.exists(os.path.join(models_path,"WIDER_val")) == False:
with zipfile.ZipFile(os.path.join(models_path,"val.zip"),"r") as zip_ref:
zip_ref.extractall(models_path)
print("files unziped")
# downloading from: https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo.md
url = 'http://download.tensorflow.org/models/object_detection/ssd_mobilenet_v1_coco_11_06_2017.tar.gz'
if os.path.exists(os.path.join(models_path,"ssd_mobilenet_v1_coco_11_06_2017.tar.gz")) == False:
response = requests.get(url, stream=True)
with open(os.path.join(models_path,"ssd_mobilenet_v1_coco_11_06_2017.tar.gz"), 'wb') as out_file:
shutil.copyfileobj(response.raw, out_file)
del response
import tarfile
filePath = os.path.join(models_path,"ssd_mobilenet_v1_coco_11_06_2017.tar.gz")
os.chdir(models_path)
if (filePath.endswith("tar.gz")):
tar = tarfile.open(filePath, "r:gz")
tar.extractall()
tar.close()
elif (filePath.endswith("tar")):
tar = tarfile.open(filePath, "r:")
tar.extractall()
tar.close()
print("done")