-
Notifications
You must be signed in to change notification settings - Fork 30
/
down_resize_crop.py
48 lines (37 loc) · 1.13 KB
/
down_resize_crop.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
import wget
from PIL import Image
import os
import tarfile
import shutil
cwd = os.getcwd()
handbag_url = 'https://people.eecs.berkeley.edu/~tinghuiz/projects/pix2pix/datasets/edges2handbags.tar.gz'
shoes_url = 'https://people.eecs.berkeley.edu/~tinghuiz/projects/pix2pix/datasets/edges2shoes.tar.gz'
wget.download(handbag_url)
wget.download(shoes_url)
with tarfile.open('./edges2handbags.tar.gz') as tar:
tar.extractall()
tar.close()
with tarfile.open('./edges2shoes.tar.gz') as tar:
tar.extractall()
tar.close()
bag_dir = "/edges2handbags/train/"
shoe_dir = "/edges2shoes/train/"
bag_list = os.listdir("."+bag_dir)
shoe_list = os.listdir("."+shoe_dir)
os.mkdir("./bags")
os.mkdir("./shoes")
os.mkdir("./result")
for i in bag_list:
image = Image.open(cwd+bag_dir+i)
image = image.resize([128,64])
image = image.crop([64,0,128,64])
image.save("./bags/"+i)
for i in shoe_list:
image = Image.open(cwd+shoe_dir+i)
image = image.resize([128,64])
image = image.crop([64,0,128,64])
image.save("./shoes/"+i)
#shutil.rmtree("./edges2handbags")
#shutil.rmtree("./edges2shoes")
os.remove('./edges2handbags.tar.gz')
os.remove('./edges2shoes.tar.gz')