-
Notifications
You must be signed in to change notification settings - Fork 33
/
prepare_dcgan_dataset.py
77 lines (61 loc) · 1.72 KB
/
prepare_dcgan_dataset.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import os
import sys
from shutil import copyfile
import movies_dataset as movies
min_year = 0
max_year = 2017
ratio = 50
genres_white_list = []
genres_black_list = []
genres = []
path = 'dcgan_movies_posters'
# parse arguments
for arg in sys.argv:
if arg.startswith('-min_year='):
min_year = int(arg.split('=')[1])
if arg.startswith('-max_year='):
max_year = int(arg.split('=')[1])
if arg.startswith('-ratio='):
ratio = int(arg.split('=')[1])
if arg.startswith('-include_genres='):
genres_white_list = arg.split('=')[1].split(',')
if arg.startswith('-exclude_genres='):
genres_black_list = arg.split('=')[1].split(',')
# filter genres
if len(genres_white_list) > 0:
genres = genres_white_list
else:
genres = list(set(movies.list_genres(14)) - set(genres_black_list))
genres.sort()
# log
print()
print('min_year:', min_year)
print('max_year:', max_year)
print('genres:', genres)
print('ratio:', ratio)
print()
# collect movies
all_movies = []
for year in reversed(range(min_year, max_year + 1)):
all_movies += movies.list_movies(year=year, genres=genres)
print('movies collected:', len(all_movies))
# create folder if doesn't exist
if not os.path.isdir(path):
os.makedirs(path)
# delete content if any
for the_file in os.listdir(path):
file_path = os.path.join(path, the_file)
try:
if os.path.isfile(file_path):
os.unlink(file_path)
except Exception as e:
print(e)
# copy files
for movie in all_movies:
if movie.poster_file_exists():
copyfile(movie.poster_file_path(ratio), path + '/' + movie.poster_file_name())
# TODO: not very clean
# convert all to RGB
command = './convert_to_RGB.sh'
print(command)
os.system(command)