Skip to content

Commit

Permalink
update bias addition
Browse files Browse the repository at this point in the history
  • Loading branch information
carpedm20 committed Feb 4, 2016
1 parent bd1fe09 commit a5c7dfa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ data
samples
*.zip
logs
test*

web/js/gen_layers.js

Expand Down
6 changes: 4 additions & 2 deletions model.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,12 @@ def build_model(self):

self.d_loss_real_sum = tf.scalar_summary("d_loss_real", self.d_loss_real)
self.d_loss_fake_sum = tf.scalar_summary("d_loss_fake", self.d_loss_fake)
self.g_loss_sum = tf.scalar_summary("g_loss", self.g_loss)

self.d_loss = self.d_loss_real + self.d_loss_fake

self.g_loss_sum = tf.scalar_summary("g_loss", self.g_loss)
self.d_loss_sum = tf.scalar_summary("d_loss", self.d_loss)

t_vars = tf.trainable_variables()

self.d_vars = [var for var in t_vars if 'd_' in var.name]
Expand All @@ -115,7 +117,7 @@ def train(self, config):
self.saver = tf.train.Saver()
self.g_sum = tf.merge_summary([self.z_sum, self.d__sum,
self.G_sum, self.d_loss_fake_sum, self.g_loss_sum])
self.d_sum = tf.merge_summary([self.z_sum, self.d_sum, self.d_loss_real_sum])
self.d_sum = tf.merge_summary([self.z_sum, self.d_sum, self.d_loss_real_sum, self.d_loss_sum])
self.writer = tf.train.SummaryWriter("./logs", self.sess.graph_def)

sample_z = np.random.uniform(-1, 1, size=(self.sample_size , self.z_dim))
Expand Down
16 changes: 7 additions & 9 deletions ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,8 @@ def conv2d(input_, output_dim,
initializer=tf.truncated_normal_initializer(stddev=stddev))
conv = tf.nn.conv2d(input_, w, strides=[1, d_h, d_w, 1], padding='SAME')

biases = tf.Variable(tf.constant(0.0, shape=[output_dim], dtype=tf.float32),
trainable=True, name='biases')
bias = tf.reshape(tf.nn.bias_add(conv, biases), conv.get_shape())
biases = tf.get_variable('biases', [output_dim], initializer=tf.constant_initializer(0.0))
conv = tf.reshape(tf.nn.bias_add(conv, biases), conv.get_shape())

return conv

Expand All @@ -80,8 +79,8 @@ def deconv2d(input_, output_shape,
deconv = tf.nn.deconv2d(input_, w, output_shape=output_shape,
strides=[1, d_h, d_w, 1])

biases = tf.Variable([0.0] * output_shape[-1], name='biases')
bias = tf.reshape(tf.nn.bias_add(deconv, biases), deconv.get_shape())
biases = tf.get_variable('biases', [output_shape[-1]], initializer=tf.constant_initializer(0.0))
deconv = tf.reshape(tf.nn.bias_add(deconv, biases), deconv.get_shape())

if with_w:
return deconv, w, biases
Expand All @@ -100,10 +99,9 @@ def linear(input_, output_size, scope=None, stddev=0.02, bias_start=0.0, with_w=
with tf.variable_scope(scope or "Linear"):
matrix = tf.get_variable("Matrix", [shape[1], output_size], tf.float32,
tf.random_normal_initializer(stddev=stddev))
bias_term = tf.get_variable(
"Bias", [output_size],
bias = tf.get_variable("bias", [output_size],
initializer=tf.constant_initializer(bias_start))
if with_w:
return tf.matmul(input_, matrix) + bias_term, matrix, bias_term
return tf.matmul(input_, matrix) + bias, matrix, bias
else:
return tf.matmul(input_, matrix) + bias_term
return tf.matmul(input_, matrix) + bias

0 comments on commit a5c7dfa

Please sign in to comment.