Created
February 13, 2020 03:25
-
-
Save lzhbrian/1275a50a36fefc6c4c2b28a7d6aca505 to your computer and use it in GitHub Desktop.
download vggface2 dataset from commandline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this is from | |
# https://github.com/ox-vgg/vgg_face2/issues/2#issuecomment-461684945 | |
import requests | |
import getpass | |
import sys | |
LOGIN_URL = "http://zeus.robots.ox.ac.uk/vgg_face2/login/" | |
FILE_URL = "http://zeus.robots.ox.ac.uk/vgg_face2/get_file?fname=vggface2_test.tar.gz" | |
print('Please enter your VGG Face 2 credentials:') | |
user_string = input(' User: ') | |
password_string = getpass.getpass(prompt=' Password: ') | |
payload = { | |
'username': user_string, | |
'password': password_string | |
} | |
session = requests.session() | |
r = session.get(LOGIN_URL) | |
if 'csrftoken' in session.cookies: | |
csrftoken = session.cookies['csrftoken'] | |
elif 'csrf' in session.cookies: | |
csrftoken = session.cookies['csrf'] | |
else: | |
raise ValueError("Unable to locate CSRF token.") | |
payload['csrfmiddlewaretoken'] = csrftoken | |
r = session.post(LOGIN_URL, data=payload) | |
filename = FILE_URL.split('=')[-1] | |
with open(filename, "wb") as f: | |
print(f"Downloading file: `{filename}`") | |
r = session.get(FILE_URL, data=payload, stream=True) | |
bytes_written = 0 | |
for data in r.iter_content(chunk_size=4096): | |
f.write(data) | |
bytes_written += len(data) | |
MiB = bytes_written / (1024 * 1024) | |
sys.stdout.write(f"\r{MiB:0.2f} MiB downloaded...") | |
sys.stdout.flush() | |
print("\nDone.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment