Skip to content

Commit

Permalink
Merge pull request vanhuyz#20 from dereklh4/support_all_image_sizes
Browse files Browse the repository at this point in the history
Support all image sizes
  • Loading branch information
vanhuyz authored May 23, 2017
2 parents d0318d9 + 5dfd64c commit 166cdc9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __call__(self, input):
u64 = ops.uk(res_output, 2*self.ngf, is_training=self.is_training, norm=self.norm,
reuse=self.reuse, name='u64') # (?, w/2, h/2, 64)
u32 = ops.uk(u64, self.ngf, is_training=self.is_training, norm=self.norm,
reuse=self.reuse, name='u32') # (?, w, h, 32)
reuse=self.reuse, name='u32', output_size=self.image_size) # (?, w, h, 32)

# conv layer
# Note: the paper said that ReLU and _norm were used
Expand Down
2 changes: 1 addition & 1 deletion model.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __init__(self,
self.G = Generator('G', self.is_training, ngf=ngf, norm=norm, image_size=image_size)
self.D_Y = Discriminator('D_Y',
self.is_training, norm=norm, use_sigmoid=use_sigmoid)
self.F = Generator('F', self.is_training, norm=norm)
self.F = Generator('F', self.is_training, norm=norm, image_size=image_size)
self.D_X = Discriminator('D_X',
self.is_training, norm=norm, use_sigmoid=use_sigmoid)

Expand Down
6 changes: 4 additions & 2 deletions ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def n_res_blocks(input, reuse, norm='instance', is_training=True, n=6):
input = output
return output

def uk(input, k, reuse=False, norm='instance', is_training=True, name=None):
def uk(input, k, reuse=False, norm='instance', is_training=True, name=None, output_size=None):
""" A 3x3 fractional-strided-Convolution-BatchNorm-ReLU layer
with k filters, stride 1/2
Args:
Expand All @@ -104,6 +104,7 @@ def uk(input, k, reuse=False, norm='instance', is_training=True, name=None):
is_training: boolean or BoolTensor
reuse: boolean
name: string, e.g. 'c7sk-32'
output_size: integer, desired output size of layer
Returns:
4D tensor
"""
Expand All @@ -113,7 +114,8 @@ def uk(input, k, reuse=False, norm='instance', is_training=True, name=None):
weights = _weights("weights",
shape=[3, 3, k, input_shape[3]])

output_size = input_shape[1]*2
if not output_size:
output_size = input_shape[1]*2
output_shape = [input_shape[0], output_size, output_size, k]
fsconv = tf.nn.conv2d_transpose(input, weights,
output_shape=output_shape,
Expand Down

0 comments on commit 166cdc9

Please sign in to comment.