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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ----------------------------------------------------------------------------
|
| 2 |
+
# - TanksAndTemples Website Toolbox -
|
| 3 |
+
# - http://www.tanksandtemples.org -
|
| 4 |
+
# ----------------------------------------------------------------------------
|
| 5 |
+
# The MIT License (MIT)
|
| 6 |
+
#
|
| 7 |
+
# Copyright (c) 2017
|
| 8 |
+
# Arno Knapitsch <arno.knapitsch@gmail.com >
|
| 9 |
+
# Jaesik Park <syncle@gmail.com>
|
| 10 |
+
# Qian-Yi Zhou <Qianyi.Zhou@gmail.com>
|
| 11 |
+
# Vladlen Koltun <vkoltun@gmail.com>
|
| 12 |
+
#
|
| 13 |
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 14 |
+
# of this software and associated documentation files (the "Software"), to deal
|
| 15 |
+
# in the Software without restriction, including without limitation the rights
|
| 16 |
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 17 |
+
# copies of the Software, and to permit persons to whom the Software is
|
| 18 |
+
# furnished to do so, subject to the following conditions:
|
| 19 |
+
#
|
| 20 |
+
# The above copyright notice and this permission notice shall be included in
|
| 21 |
+
# all copies or substantial portions of the Software.
|
| 22 |
+
#
|
| 23 |
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 24 |
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 25 |
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 26 |
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 27 |
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 28 |
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 29 |
+
# THE SOFTWARE.
|
| 30 |
+
# ----------------------------------------------------------------------------
|
| 31 |
+
#
|
| 32 |
+
# This python script is for downloading dataset from www.tanksandtemples.org
|
| 33 |
+
# The dataset has a different license, please refer to
|
| 34 |
+
# https://tanksandtemples.org/license/
|
| 35 |
+
|
| 36 |
+
import sys
|
| 37 |
+
import os
|
| 38 |
+
import argparse
|
| 39 |
+
import zipfile
|
| 40 |
+
import hashlib
|
| 41 |
+
import requests
|
| 42 |
+
if (sys.version_info > (3, 0)):
|
| 43 |
+
pversion = 3
|
| 44 |
+
from urllib.request import Request, urlopen
|
| 45 |
+
else:
|
| 46 |
+
pversion = 2
|
| 47 |
+
from urllib2 import Request, urlopen
|
| 48 |
+
|
| 49 |
+
id_download_dict = {
|
| 50 |
+
'Auditorium.mp4': '0B-ePgl6HF260SmdGUzJSX0ZfZXc',
|
| 51 |
+
'Auditorium.zip': '0B-ePgl6HF260N1VHWFBTSWQ2MDg',
|
| 52 |
+
'Ballroom.mp4': '0B-ePgl6HF260MzlmY2Jwa0dqME0',
|
| 53 |
+
'Ballroom.zip': '0B-ePgl6HF260aS1hQXJHeHFxNVE',
|
| 54 |
+
'Barn.mp4': '0B-ePgl6HF260ZlBZcHFrTHFLdGM',
|
| 55 |
+
'Barn.zip': '0B-ePgl6HF260NzQySklGdXZyQzA',
|
| 56 |
+
'Church.mp4': '0B-ePgl6HF260dnlGMkFkNlpibG8',
|
| 57 |
+
'Church.zip': '0B-ePgl6HF260SmhXM0czaHJ3SU0',
|
| 58 |
+
'Caterpillar.mp4': '0B-ePgl6HF260Z00xVWgyN2c3WEU',
|
| 59 |
+
'Caterpillar.zip': '0B-ePgl6HF260b2JNbnZYYjczU2s',
|
| 60 |
+
'Courthouse.mp4': '0B-ePgl6HF260TEpnajBqRFJ1enM',
|
| 61 |
+
'Courthouse.zip': '0B-ePgl6HF260bHRNZTJnU1pWMVE',
|
| 62 |
+
'Courtroom.mp4': '0B-ePgl6HF260b0JZeUJlUThSWjQ',
|
| 63 |
+
'Courtroom.zip': '0B-ePgl6HF260UmZIQVgtLXhtZUE',
|
| 64 |
+
'Family.mp4': '0B-ePgl6HF260UmNxYmlQeDhmeFE',
|
| 65 |
+
'Family.tar.gz': '0B-ePgl6HF260SWRlRDZCRXZRZlk',
|
| 66 |
+
'Family.zip': '0B-ePgl6HF260NVRhRmxnTW4tQTQ',
|
| 67 |
+
'Francis.mp4': '0B-ePgl6HF260emtkUElRT0lXQ3M',
|
| 68 |
+
'Francis.tar.gz': '0B-ePgl6HF260MnVqcW1EWDVMcFE',
|
| 69 |
+
'Francis.zip': '0B-ePgl6HF260SHk4ejdaSEhqd28',
|
| 70 |
+
'Horse.mp4': '0B-ePgl6HF260RGFBcF9iTk5XQTA',
|
| 71 |
+
'Horse.tar.gz': '0B-ePgl6HF260eE9EVTdpS3hYamc',
|
| 72 |
+
'Horse.zip': '0B-ePgl6HF260VFdBc0RvQjJuQXc',
|
| 73 |
+
'Ignatius.mp4': '0B-ePgl6HF260T19oUTIyUTRwTE0',
|
| 74 |
+
'Ignatius.zip': '0B-ePgl6HF260d0l0ZDNSZ3ZxREk',
|
| 75 |
+
'Lighthouse.mp4': '0B-ePgl6HF260T184cUdCbFFBVEE',
|
| 76 |
+
'Lighthouse.zip': '0B-ePgl6HF260dHpldktMNV9NRTA',
|
| 77 |
+
'M60.mp4': '0B-ePgl6HF260dG9nTzZHdkRJblE',
|
| 78 |
+
'M60.zip': '0B-ePgl6HF260b2lSTWxwLU1CQ2s',
|
| 79 |
+
'Meetingroom.mp4': '0B-ePgl6HF260V3BFSFFTZFJwSWc',
|
| 80 |
+
'Meetingroom.zip': '0B-ePgl6HF260cV9lNmlZZGp6aUU',
|
| 81 |
+
'Museum.mp4': '0B-ePgl6HF260ZXRwck5rWk4tc2c',
|
| 82 |
+
'Museum.zip': '0B-ePgl6HF260RTY4Ml9Ubm9fUkk',
|
| 83 |
+
'Palace.mp4': '0B-ePgl6HF260X21ac1ZXNmx3VTA',
|
| 84 |
+
'Palace.zip': '0B-ePgl6HF260ZHlJejlXbmFKS3M',
|
| 85 |
+
'Panther.mp4': '0B-ePgl6HF260bVRndWVYRGM4c0U',
|
| 86 |
+
'Panther.zip': '0B-ePgl6HF260SUNBeVhMc1hpb28',
|
| 87 |
+
'Playground.mp4': '0B-ePgl6HF260d0JoR2pWak9RbnM',
|
| 88 |
+
'Playground.zip': '0B-ePgl6HF260TVktaTFyclFhaDg',
|
| 89 |
+
'Temple.mp4': '0B-ePgl6HF260N1VTMGNES0FsaDA',
|
| 90 |
+
'Temple.zip': '0B-ePgl6HF260V2VaSG5GTkl5dmc',
|
| 91 |
+
'Train.mp4': '0B-ePgl6HF260YUttRUI4U0xtS1E',
|
| 92 |
+
'Train.zip': '0B-ePgl6HF260UFNWeXk3MHhCT00',
|
| 93 |
+
'Truck.mp4': '0B-ePgl6HF260aVVZMzhSdVc5Njg',
|
| 94 |
+
'Truck.zip': '0B-ePgl6HF260NEw3OGN4ckF0dnM',
|
| 95 |
+
'advanced_video.chk': '0B-ePgl6HF260RWJIcjRPRnlUS28',
|
| 96 |
+
'advanced_video.zip': '0B-ePgl6HF260OXgzbEJleDVSZ0k',
|
| 97 |
+
'image_sets_md5.chk': '0B-ePgl6HF260dE5zR3FhQmxVbHc',
|
| 98 |
+
'intermediate_video.chk': '0B-ePgl6HF260SVdpbG1peXBOYnM',
|
| 99 |
+
'intermediate_video.zip': '0B-ePgl6HF260UU1zUTd6SzlmczA',
|
| 100 |
+
'advanced_image.zip': '0B-ePgl6HF260UXlhWDBiNVZvdk0',
|
| 101 |
+
'intermediate_image.zip': '0B-ePgl6HF260UU1zUTd6SzlmczA',
|
| 102 |
+
'advanced_image.chk': '0B-ePgl6HF260RWJIcjRPRnlUS28',
|
| 103 |
+
'intermediate_image.chk': '0B-ePgl6HF260SVdpbG1peXBOYnM',
|
| 104 |
+
'md5.txt': '0B-ePgl6HF260QTlJUXpqc3RQOGM',
|
| 105 |
+
'training.zip': '0B-ePgl6HF260dU1pejdkeXdMb00',
|
| 106 |
+
'video_set_md5.chk': '0B-ePgl6HF260M2h5Q3o1bGdpc1U'
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
sep = os.sep
|
| 110 |
+
parser = argparse.ArgumentParser(description='Tanks and Temples file' +
|
| 111 |
+
'downloader')
|
| 112 |
+
parser.add_argument(
|
| 113 |
+
'--modality',
|
| 114 |
+
type=str,
|
| 115 |
+
help='(image|video|both) ' +
|
| 116 |
+
'choose if you want to download video sequences (very big) or pre sampled' +
|
| 117 |
+
' image sets',
|
| 118 |
+
default='image')
|
| 119 |
+
parser.add_argument(
|
| 120 |
+
'--group',
|
| 121 |
+
type=str,
|
| 122 |
+
help='(intermediate|advanced|both|training|all)' +
|
| 123 |
+
' choose if you want to download intermediate, advanced or training dataset',
|
| 124 |
+
default='both')
|
| 125 |
+
parser.add_argument('--pathname',
|
| 126 |
+
type=str,
|
| 127 |
+
help='chose destination path name, default = local path',
|
| 128 |
+
default='')
|
| 129 |
+
parser.add_argument('-s',
|
| 130 |
+
action='store_true',
|
| 131 |
+
default=False,
|
| 132 |
+
dest='status',
|
| 133 |
+
help='show data status')
|
| 134 |
+
parser.add_argument('--unpack_off',
|
| 135 |
+
action='store_false',
|
| 136 |
+
default=True,
|
| 137 |
+
dest='unpack',
|
| 138 |
+
help='do not un-zip the folders after download')
|
| 139 |
+
parser.add_argument('--calc_md5_off',
|
| 140 |
+
action='store_false',
|
| 141 |
+
default=True,
|
| 142 |
+
dest='calc_md5',
|
| 143 |
+
help='do not calculate md5sum after download')
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
def download_file_from_google_drive(id, destination):
|
| 147 |
+
URL = "https://docs.google.com/uc?export=download"
|
| 148 |
+
session = requests.Session()
|
| 149 |
+
response = session.get(URL, params={'id': id}, stream=True)
|
| 150 |
+
token = get_confirm_token2(response)
|
| 151 |
+
if token:
|
| 152 |
+
params = {'id': id, 'confirm': token}
|
| 153 |
+
response = session.get(URL, params=params, stream=True)
|
| 154 |
+
save_response_content(response, destination)
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
def get_confirm_token(response):
|
| 158 |
+
for key, value in response.cookies.items():
|
| 159 |
+
if key.startswith('download_warning'):
|
| 160 |
+
return value
|
| 161 |
+
return None
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
def get_confirm_token2(response):
|
| 165 |
+
for key, value in response.headers.items():
|
| 166 |
+
if key.startswith('Set-Cookie'):
|
| 167 |
+
return value.split('=')[1].split(';')[0]
|
| 168 |
+
return None
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
def save_response_content(response, destination):
|
| 172 |
+
CHUNK_SIZE = 32768
|
| 173 |
+
|
| 174 |
+
if not os.path.exists(os.path.dirname(destination)):
|
| 175 |
+
os.makedirs(os.path.dirname(destination))
|
| 176 |
+
total_filesize = 0
|
| 177 |
+
with open(destination, "wb") as f:
|
| 178 |
+
for chunk in response.iter_content(CHUNK_SIZE):
|
| 179 |
+
if chunk: # filter out keep-alive new chunks
|
| 180 |
+
f.write(chunk)
|
| 181 |
+
total_filesize += CHUNK_SIZE
|
| 182 |
+
sys.stdout.write("\r%5.0f MB downloaded" %
|
| 183 |
+
(float(total_filesize) / 1000000))
|
| 184 |
+
sys.stdout.flush()
|
| 185 |
+
sys.stdout.write("\rDownload Complete \n")
|
| 186 |
+
sys.stdout.flush()
|
| 187 |
+
return chunk
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
def generate_file_md5(filename, blocksize=2**20):
|
| 191 |
+
m = hashlib.md5()
|
| 192 |
+
with open(filename, "rb") as f:
|
| 193 |
+
while True:
|
| 194 |
+
buf = f.read(blocksize)
|
| 195 |
+
if not buf:
|
| 196 |
+
break
|
| 197 |
+
m.update(buf)
|
| 198 |
+
return m.hexdigest()
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
def download_video(pathname, scene, image_md5_dict, calc_md5):
|
| 202 |
+
scene_out_dir = pathname + 'videos'
|
| 203 |
+
download_file = scene + '.mp4'
|
| 204 |
+
print('\ndownloading video ' + download_file.split('/')[-1])
|
| 205 |
+
idd = id_download_dict[download_file]
|
| 206 |
+
download_file_local = scene_out_dir + sep + scene + '.mp4'
|
| 207 |
+
download_file_from_google_drive(idd, download_file_local)
|
| 208 |
+
|
| 209 |
+
if (calc_md5):
|
| 210 |
+
h_md5 = generate_file_md5(download_file_local)
|
| 211 |
+
print('\nmd5 downloaded: ' + h_md5)
|
| 212 |
+
print('md5 original: ' + video_md5_dict[scene])
|
| 213 |
+
md5_check = h_md5 == video_md5_dict[scene]
|
| 214 |
+
|
| 215 |
+
if (not md5_check):
|
| 216 |
+
print('\nWarning: MD5 does not match, delete file and restart' +
|
| 217 |
+
' download\n')
|
| 218 |
+
else:
|
| 219 |
+
if (unpack):
|
| 220 |
+
extr_dir = scene_out_dir
|
| 221 |
+
zip_file = scene_out_dir + sep + scene + '.zip'
|
| 222 |
+
if (zipfile.is_zipfile(zip_file)):
|
| 223 |
+
if not os.path.exists(extr_dir):
|
| 224 |
+
os.makedirs(extr_dir)
|
| 225 |
+
zip = zipfile.ZipFile(zip_file, 'r')
|
| 226 |
+
zip.extractall(extr_dir)
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
def check_video(pathname, scene, image_md5_dict):
|
| 230 |
+
scene_out_dir = pathname + 'videos'
|
| 231 |
+
ret_str = ' '
|
| 232 |
+
download_file_local = scene_out_dir + sep + scene + '.mp4'
|
| 233 |
+
if os.path.exists(download_file_local):
|
| 234 |
+
h_md5 = generate_file_md5(download_file_local)
|
| 235 |
+
md5_check = h_md5 == video_md5_dict[scene]
|
| 236 |
+
if (md5_check):
|
| 237 |
+
ret_str = 'X'
|
| 238 |
+
else:
|
| 239 |
+
ret_str = '?'
|
| 240 |
+
else:
|
| 241 |
+
ret_str = ' '
|
| 242 |
+
return ret_str
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
def download_image_sets(pathname, scene, image_md5_dict, calc_md5):
|
| 246 |
+
scene_out_dir = pathname + 'image_sets'
|
| 247 |
+
download_file = scene + '.zip'
|
| 248 |
+
download_file_local = scene_out_dir + sep + scene + '.zip'
|
| 249 |
+
print('\ndownloading image set ' + download_file.split('/')[-1])
|
| 250 |
+
idd = id_download_dict[download_file]
|
| 251 |
+
download_file_from_google_drive(idd, download_file_local)
|
| 252 |
+
|
| 253 |
+
if (calc_md5):
|
| 254 |
+
h_md5 = generate_file_md5(download_file_local)
|
| 255 |
+
print('\nmd5 downloaded: ' + h_md5)
|
| 256 |
+
print('md5 original: ' + image_md5_dict[scene])
|
| 257 |
+
md5_check = h_md5 == image_md5_dict[scene]
|
| 258 |
+
|
| 259 |
+
if (md5_check):
|
| 260 |
+
if (unpack):
|
| 261 |
+
extr_dir = scene_out_dir
|
| 262 |
+
|
| 263 |
+
zip_file = scene_out_dir + sep + scene + '.zip'
|
| 264 |
+
if (zipfile.is_zipfile(zip_file)):
|
| 265 |
+
if not os.path.exists(extr_dir):
|
| 266 |
+
os.makedirs(extr_dir)
|
| 267 |
+
zip = zipfile.ZipFile(zip_file, 'r')
|
| 268 |
+
zip.extractall(extr_dir)
|
| 269 |
+
else:
|
| 270 |
+
print('\nWarning: MD5 does not match, delete file and restart' +
|
| 271 |
+
' download\n')
|
| 272 |
+
|
| 273 |
+
|
| 274 |
+
def check_image_sets(pathname, scene, image_md5_dict):
|
| 275 |
+
scene_out_dir = pathname + 'image_sets'
|
| 276 |
+
ret_str = ''
|
| 277 |
+
download_file_local = scene_out_dir + sep + scene + '.zip'
|
| 278 |
+
if os.path.exists(download_file_local):
|
| 279 |
+
h_md5 = generate_file_md5(download_file_local)
|
| 280 |
+
md5_check = h_md5 == image_md5_dict[scene]
|
| 281 |
+
if (md5_check):
|
| 282 |
+
ret_str = 'X'
|
| 283 |
+
else:
|
| 284 |
+
ret_str = '?'
|
| 285 |
+
else:
|
| 286 |
+
ret_str = ' '
|
| 287 |
+
return ret_str
|
| 288 |
+
|
| 289 |
+
|
| 290 |
+
def print_status(sequences, modality, pathname, intermediate_list,
|
| 291 |
+
advanced_list, training_list, image_md5_dict, video_md5_dict):
|
| 292 |
+
#print('intermediate Dataset \t\t\t Video \t\t\t image set')
|
| 293 |
+
print('\n\n data status: \n\n')
|
| 294 |
+
print('[X] - downloaded [ ] - missing [?] - being downloaded or ' +
|
| 295 |
+
'corrupted [n] - not checked')
|
| 296 |
+
|
| 297 |
+
if (sequences == 'intermediate' or sequences == 'both' or
|
| 298 |
+
sequences == 'all' or sequences == ''):
|
| 299 |
+
print('\n\n---------------------------------------------------------' +
|
| 300 |
+
'--------')
|
| 301 |
+
line_new = '%12s %12s %12s' % (' intermediate Dataset', 'Video',
|
| 302 |
+
'image set')
|
| 303 |
+
print(line_new)
|
| 304 |
+
print('-----------------------------------------------------------' +
|
| 305 |
+
'------')
|
| 306 |
+
for scene in intermediate_list:
|
| 307 |
+
line_new = '%12s %19s %10s' % (
|
| 308 |
+
scene, check_video(pathname, scene, video_md5_dict) if
|
| 309 |
+
(modality == 'video' or modality == 'both' or modality == '')
|
| 310 |
+
else 'n', check_image_sets(pathname, scene, image_md5_dict) if
|
| 311 |
+
(modality == 'image' or modality == 'both' or
|
| 312 |
+
modality == '') else 'n')
|
| 313 |
+
print(line_new)
|
| 314 |
+
|
| 315 |
+
if (sequences == 'advanced' or sequences == 'both' or sequences == 'all' or
|
| 316 |
+
sequences == ''):
|
| 317 |
+
print('\n\n------------------------------------------------------' +
|
| 318 |
+
'---------')
|
| 319 |
+
line_new = '%12s %16s %12s' % (' advanced Dataset', 'Video',
|
| 320 |
+
'image set')
|
| 321 |
+
print(line_new)
|
| 322 |
+
print('---------------------------------------------------------------')
|
| 323 |
+
for scene in advanced_list:
|
| 324 |
+
#print(scene + '\t\t\t X \t\t\t X')
|
| 325 |
+
line_new = '%12s %19s %10s' % (
|
| 326 |
+
scene, check_video(pathname, scene, video_md5_dict) if
|
| 327 |
+
(modality == 'video' or modality == 'both' or modality == '')
|
| 328 |
+
else 'n', check_image_sets(pathname, scene, image_md5_dict) if
|
| 329 |
+
(modality == 'image' or modality == 'both' or
|
| 330 |
+
modality == '') else 'n')
|
| 331 |
+
print(line_new)
|
| 332 |
+
|
| 333 |
+
if (sequences == 'training' or sequences == 'all' or sequences == ''):
|
| 334 |
+
print('\n\n------------------------------------------------------' +
|
| 335 |
+
'---------')
|
| 336 |
+
line_new = '%12s %16s %12s' % (' training Dataset', 'Video',
|
| 337 |
+
'image set')
|
| 338 |
+
print(line_new)
|
| 339 |
+
print('---------------------------------------------------------------')
|
| 340 |
+
for scene in training_list:
|
| 341 |
+
#print(scene + '\t\t\t X \t\t\t X')
|
| 342 |
+
line_new = '%12s %19s %10s' % (
|
| 343 |
+
scene, check_video(pathname, scene, video_md5_dict) if
|
| 344 |
+
(modality == 'video' or modality == 'both' or modality == '')
|
| 345 |
+
else 'n', check_image_sets(pathname, scene, image_md5_dict) if
|
| 346 |
+
(modality == 'image' or modality == 'both' or
|
| 347 |
+
modality == '') else 'n')
|
| 348 |
+
print(line_new)
|
| 349 |
+
|
| 350 |
+
|
| 351 |
+
if __name__ == "__main__":
|
| 352 |
+
intermediate_list = [
|
| 353 |
+
'Family', 'Francis', 'Horse', 'Lighthouse', 'M60', 'Panther',
|
| 354 |
+
'Playground', 'Train'
|
| 355 |
+
]
|
| 356 |
+
advanced_list = [
|
| 357 |
+
'Auditorium', 'Ballroom', 'Courtroom', 'Museum', 'Palace', 'Temple'
|
| 358 |
+
]
|
| 359 |
+
training_list = [
|
| 360 |
+
'Barn', 'Caterpillar', 'Church', 'Courthouse', 'Ignatius',
|
| 361 |
+
'Meetingroom', 'Truck'
|
| 362 |
+
]
|
| 363 |
+
|
| 364 |
+
args = parser.parse_args()
|
| 365 |
+
sequences = args.group
|
| 366 |
+
calc_md5 = args.calc_md5
|
| 367 |
+
|
| 368 |
+
if sequences == 'intermediate':
|
| 369 |
+
scene_list = intermediate_list
|
| 370 |
+
elif sequences == 'advanced':
|
| 371 |
+
scene_list = advanced_list
|
| 372 |
+
elif sequences == 'training':
|
| 373 |
+
scene_list = training_list
|
| 374 |
+
elif sequences == 'both':
|
| 375 |
+
scene_list = intermediate_list + advanced_list
|
| 376 |
+
elif sequences == 'all':
|
| 377 |
+
scene_list = intermediate_list + advanced_list + training_list
|
| 378 |
+
elif sequences == '':
|
| 379 |
+
scene_list = intermediate_list + advanced_list
|
| 380 |
+
else:
|
| 381 |
+
sys.exit('Error! Unknown group parameter, see help [-h]')
|
| 382 |
+
scene_list.sort()
|
| 383 |
+
|
| 384 |
+
modality = args.modality
|
| 385 |
+
unpack = args.unpack
|
| 386 |
+
status_print = args.status
|
| 387 |
+
pathname = args.pathname
|
| 388 |
+
if pathname:
|
| 389 |
+
pathname = pathname + sep
|
| 390 |
+
# download md5 checksum file and create md5 dict for image sets zip files:
|
| 391 |
+
image_md5_dict = {}
|
| 392 |
+
scene_out_dir = pathname + 'image_sets'
|
| 393 |
+
fname = scene_out_dir + sep + 'image_sets_md5.chk'
|
| 394 |
+
idd = id_download_dict['image_sets_md5.chk']
|
| 395 |
+
|
| 396 |
+
print('\ndownloading md5 sum file for image sets')
|
| 397 |
+
download_file_from_google_drive(idd, fname)
|
| 398 |
+
|
| 399 |
+
with open(fname) as f:
|
| 400 |
+
content = f.readlines()
|
| 401 |
+
content = [x.strip() for x in content]
|
| 402 |
+
for line in content:
|
| 403 |
+
md5 = line.split(' ')[0]
|
| 404 |
+
scene_name = line.split(' ')[-1][0:-4]
|
| 405 |
+
image_md5_dict.update({scene_name: md5})
|
| 406 |
+
# download md5 checksum file and create md5 dict for videos:
|
| 407 |
+
video_md5_dict = {}
|
| 408 |
+
scene_out_dir = pathname + 'videos'
|
| 409 |
+
fname = scene_out_dir + sep + 'video_set_md5.chk'
|
| 410 |
+
idd = id_download_dict['video_set_md5.chk']
|
| 411 |
+
|
| 412 |
+
print('\ndownloading md5 sum file for videos')
|
| 413 |
+
download_file_from_google_drive(idd, fname)
|
| 414 |
+
|
| 415 |
+
with open(fname) as f:
|
| 416 |
+
content = f.readlines()
|
| 417 |
+
content = [x.strip() for x in content]
|
| 418 |
+
for line in content:
|
| 419 |
+
md5 = line.split(' ')[0]
|
| 420 |
+
scene_name = line.split(' ')[-1][0:-4]
|
| 421 |
+
video_md5_dict.update({scene_name: md5})
|
| 422 |
+
if (len(sys.argv) == 1):
|
| 423 |
+
print_status('both', 'both', pathname, intermediate_list, advanced_list,
|
| 424 |
+
training_list, image_md5_dict, video_md5_dict)
|
| 425 |
+
elif status_print and (len(sys.argv) == 2):
|
| 426 |
+
print_status('both', 'both', pathname, intermediate_list, advanced_list,
|
| 427 |
+
training_list, image_md5_dict, video_md5_dict)
|
| 428 |
+
elif status_print:
|
| 429 |
+
print_status(sequences, modality, pathname, intermediate_list,
|
| 430 |
+
advanced_list, training_list, image_md5_dict,
|
| 431 |
+
video_md5_dict)
|
| 432 |
+
elif sequences or modality:
|
| 433 |
+
for scene in scene_list:
|
| 434 |
+
if modality == 'video':
|
| 435 |
+
download_video(pathname, scene, video_md5_dict, calc_md5)
|
| 436 |
+
elif modality == 'image':
|
| 437 |
+
download_image_sets(pathname, scene, image_md5_dict, calc_md5)
|
| 438 |
+
elif modality == 'both':
|
| 439 |
+
download_image_sets(pathname, scene, image_md5_dict, calc_md5)
|
| 440 |
+
download_video(pathname, scene, video_md5_dict, calc_md5)
|
| 441 |
+
else:
|
| 442 |
+
sys.exit('Error! Unknown modality parameter, see help [-h]')
|