Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pedropro committed Jun 9, 2019
1 parent effdb72 commit 56bdab8
Show file tree
Hide file tree
Showing 3 changed files with 1,234 additions and 0 deletions.
1 change: 1 addition & 0 deletions data/annotations.json

Large diffs are not rendered by default.

1,180 changes: 1,180 additions & 0 deletions demo.ipynb

Large diffs are not rendered by default.

53 changes: 53 additions & 0 deletions download.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'''
This script downloads TACO's images from Flickr given an annotation json file
Code written by Pedro F. Proenza, 2019
'''

import os.path
import argparse
import json
from PIL import Image
import requests
from io import BytesIO
import sys

parser = argparse.ArgumentParser(description='')
parser.add_argument('--dataset_path', required=False, default= '../data_download/annotations.json', help='Path to annotations')
args = parser.parse_args()

dataset_dir = os.path.dirname(args.dataset_path)

print('Note. If for any reason this stops. Just call me again and I will start where I left.')

# Load annotations
with open(args.dataset_path, 'r') as f:
annotations = json.loads(f.read())

nr_images = len(annotations['images'])
for i in range(nr_images):

image = annotations['images'][i]

file_name = image['file_name']
url_original = image['flickr_url']
url_resized = image['flickr_640_url']

file_path = os.path.join(dataset_dir, file_name)

# Create subdir if necessary
subdir = os.path.dirname(file_path)
if not os.path.isdir(subdir):
os.mkdir(subdir)

if not os.path.isfile(file_path):
# Load and Save Image
response = requests.get(url_original)
img = Image.open(BytesIO(response.content))
img.save(file_path)

# Show loading bar
bar_size = 30
x = int(bar_size * i / nr_images)
sys.stdout.write("%s[%s%s] - %i/%i\r" % ('Loading: ', "=" * x, "." * (bar_size - x), i, nr_images))
sys.stdout.flush()
i+=1

0 comments on commit 56bdab8

Please # to comment.