-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathmake_sprite.py
130 lines (93 loc) · 2.79 KB
/
make_sprite.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import os
import sys
import time
import json
import tensorflow as tf
import pdb
from tensorflow.python.ops import control_flow_ops
from datetime import datetime
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
from model.vaegan import DCGAN
from iohandler.datareader import img_reader
# datadir = '/home/jrm/proj/Hanzi/TWKai98_32x32'
datadir = 'sprite_imgs'
n = 100
coord = tf.train.Coordinator()
arch = json.load(open('architecture.json'))
imgs, info = img_reader(
datadir=datadir,
img_dims=(arch['img_h'], arch['img_w'], arch['img_c']),
batch_size=n*n,
rtype='tanh',
num_threads=1,
shuffle=False)
# imgs_NxD = tf.reshape(imgs, [-1, 32*32])
imgs_10kx32x32x1 = imgs
imgs = tf.reshape(imgs, [n, n, 32, 32])
imgs = tf.transpose(imgs, [0, 2, 1, 3])
imgs = tf.reshape(imgs, [32*n, 32*n])
sess = tf.Session()
# init = tf.initialize_all_variables()
init = tf.global_variables_initializer()
sess.run(init)
threads = tf.train.start_queue_runners(sess=sess, coord=coord)
imgs_np = sess.run(imgs_10kx32x32x1)
import pdb
pdb.set_trace()
imgs_np.tofile('sprite-10000x32x32x1')
# plt.figure()
# plt.imshow(images, cmap='gray')
# plt.savefig('sprite.jpeg')
# from PIL import Image
# i = (images / 2 + 0.5) * 255
# i = i.astype(np.uint8)
# im = Image.fromarray(i)
# im.save('sprite.png')
import shutil
import os
import numpy as np
from PIL import Image
images = sess.run(imgs)
i = (images / 2 + 0.5) * 255
i = i.astype(np.uint8)
im = Image.fromarray(i)
im.save('sprite.jpg')
# import numpy as np
# from PIL import Image
# from iohandler.datareader import find_files
# datadir = 'sprite_imgs'
# files = find_files(datadir, pattern='.*\.jpg')
# files = sorted(files)
# imgs = []
# for f in files:
# i = Image.open(f)
# i = np.reshape(i, [1, 32, 32])
# imgs.append(i)
# #
# img_dims = (32, 32, 1)
# with tf.variable_scope('input'):
# # [TODO] should I merge tf.train.string_input_producer with `find_files`?
# h, w, c = img_dims
# filename_queue = tf.train.string_input_producer(files)
# reader = tf.WholeFileReader()
# key, value = reader.read(filename_queue)
# img = decoder(value, channels=c)
# img = tf.image.crop_to_bounding_box(img, 0, 0, h, w)
# img = tf.to_float(img)
# if rtype == 'tanh':
# img = tf.div(img, 127.5) - 1.
# elif rtype == 'sigmoid':
# img = tf.div(img, 255.)
# else:
# raise ValueError(
# 'Unsupported range type: {:s}.'.format(rtype) +
# '(sigmoid or tanh)')
# img = tf.expand_dims(img, 0)
import shutil
from iohandler.datareader import find_files
datadir = '/home/jrm/proj/Hanzi/TWKai98_32x32'
files = find_files(datadir, pattern='.*\.jpg')
for i in range(10000):
shutil.copy(files[i], 'sprite_imgs/')