Skip to content

Commit ac59257

Browse files
committed
smapler error fixes
1 parent 00031e9 commit ac59257

File tree

5 files changed

+30
-18
lines changed

5 files changed

+30
-18
lines changed

Diff for: model.png renamed to DCGAN.png

File renamed without changes.

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ DCGAN in Tensorflow
33

44
Tensorflow implementation of [Deep Convolutional Generative Adversarial Networks](http://arxiv.org/abs/1511.06434). The referenced torch code can be found [here](https://github.com/soumith/dcgan.torch).
55

6-
![alt tag](model.png)
6+
![alt tag](DCGAN.png)
77

88

99
Prerequisites

Diff for: model.py

+17-16
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def build_model(self):
5959
self.z = tf.placeholder(tf.float32, [None, self.z_dim])
6060

6161
self.image_ = self.generator(self.z)
62-
self.sampler = self.generator(self.z)
62+
self.sampler = self.sampler(self.z)
6363

6464
self.D = self.discriminator(self.image)
6565
self.D_ = self.discriminator(self.image_, reuse=True)
@@ -207,36 +207,37 @@ def generator(self, z, y=None):
207207
def sampler(self, z, y=None):
208208
tf.get_variable_scope().reuse_variables()
209209

210-
if y:
210+
if self.y_dim:
211211
yb = tf.reshape(y, [None, 1, 1, self.y_dim])
212212
z = tf.concat(1, [z, y])
213213

214-
h0 = tf.nn.relu(self.bn0(linear(z, self.gfc_dim, 's_h0_lin')))
214+
h0 = tf.nn.relu(self.bn0(linear(z, self.gfc_dim, 'g_h0_lin')))
215215
h0 = tf.concat(1, [h0, y])
216216

217-
h1 = tf.nn.relu(self.g_bn1(linear(z, self.gf_dim*2*7*7, 's_h1_lin')))
217+
h1 = tf.nn.relu(self.g_bn1(linear(z, self.gf_dim*2*7*7, 'g_h1_lin')))
218218
h1 = tf.reshape(h1, [None, 7, 7, self.gf_dim * 2])
219219
h1 = conv_cond_concat(h1, yb)
220220

221-
h2 = tf.nn.relu(self.bn2(deconv2d(h1, self.gf_dim, name='h2')))
221+
h2 = tf.nn.relu(self.bn2(deconv2d(h1, self.gf_dim, name='g_h2')))
222222
h2 = conv_cond_concat(h2, yb)
223223

224-
return tf.nn.sigmoid(deconv2d(h2, self.c_dim, name='h3'))
224+
return tf.nn.sigmoid(deconv2d(h2, self.c_dim, name='g_h3'))
225225
else:
226-
h0 = tf.nn.relu(self.g_bn0(linear(z, self.gf_dim*8*4*4, 's_h0_lin'),
227-
train=False))
228-
h0 = tf.reshape(h1, [None, 4, 4, self.gf_dim * 8])
226+
# project `z` and reshape
227+
h0 = tf.reshape(linear(z, self.gf_dim*8*4*4, 'g_h0_lin'),
228+
[-1, 4, 4, self.gf_dim * 8])
229+
h0 = tf.nn.relu(self.g_bn0(h0, train=False))
229230

230-
h1 = deconv2d(h0, [None, 8, 8, self.gf_dim*4], name='h1')
231-
h1 = tf.relu(self.g_bn1(h1, train=False))
231+
h1 = deconv2d(h0, [self.batch_size, 8, 8, self.gf_dim*4], name='g_h1')
232+
h1 = tf.nn.relu(self.g_bn1(h1, train=False))
232233

233-
h2 = deconv2d(h1, [None, 16, 16, self.gf_dim*2], name='h2')
234-
h2 = tf.relu(self.g_bn2(h2, train=False))
234+
h2 = deconv2d(h1, [self.batch_size, 16, 16, self.gf_dim*2], name='g_h2')
235+
h2 = tf.nn.relu(self.g_bn2(h2, train=False))
235236

236-
h3 = deconv2d(h2, [None, 16, 16, self.gf_dim*1], name='h3')
237-
h3 = tf.relu(self.g_bn3(h3, train=False))
237+
h3 = deconv2d(h2, [self.batch_size, 16, 16, self.gf_dim*1], name='g_h3')
238+
h3 = tf.nn.relu(self.g_bn3(h3, train=False))
238239

239-
h4 = deconv2d(h3, [None, 64, 64, 3], name='h4')
240+
h4 = deconv2d(h3, [None, 64, 64, 3], name='g_h4')
240241

241242
return tf.nn.tanh(h4)
242243

Diff for: ops.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ def __call__(self, x, train=True):
5454
return tf.nn.batch_norm_with_global_normalization(x,
5555
mean,
5656
variance,
57-
self.beta, self.gamma,
57+
self.beta,
58+
self.gamma,
5859
self.epsilon, True)
5960

6061
def binary_cross_entropy_with_logits(logits, targets, name=None):

Diff for: utils.py

+10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ def get_image(image_path):
1515
def imread(path):
1616
return scipy.misc.imread(path).astype(np.float)
1717

18+
def imsave(images, size, path):
19+
h, w = images.shape[1], images.shape[2]
20+
img = np.zeros((h * size[0], w * size[1], 3))
21+
22+
for idx, image in enumerate(images):
23+
i = idx % size[1]
24+
j = idx / size[1]
25+
img[j*h:j*h+h, i*w:i*w+w, :] = image
26+
return scipy.misc.imsave(path, img)
27+
1828
def center_crop(x, ph, pw=None):
1929
if pw is None:
2030
pw = ph

0 commit comments

Comments
 (0)