-
Notifications
You must be signed in to change notification settings - Fork 0
/
importing_data.py
36 lines (30 loc) · 1 KB
/
importing_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
%matplotlib inline
import os
import tarfile
import urllib
import shutil
import json
import random
import numpy as np
import boto3
import sagemaker
from tqdm import tqdm
from sagemaker.amazon.amazon_estimator import get_image_uri
from matplotlib import pyplot as plt
from xml.etree import ElementTree as ET
from PIL import Image, ImageDraw, ImageFont
urls = ['http://www.robots.ox.ac.uk/~vgg/data/pets/data/images.tar.gz',
'http://www.robots.ox.ac.uk/~vgg/data/pets/data/annotations.tar.gz']
def download_and_extract(data_dir, download_dir):
for url in urls:
target_file = url.split('/')[-1]
if target_file not in os.listdir(download_dir):
print('Downloading', url)
urllib.request.urlretrieve(url, os.path.join(download_dir, target_file))
tf = tarfile.open(url.split('/')[-1])
tf.extractall(data_dir)
else:
print('Already downloaded', url)
if not os.path.isdir('data'):
os.mkdir('data')
download_and_extract('data', '.')