-
Notifications
You must be signed in to change notification settings - Fork 65
/
ops.py
37 lines (29 loc) · 1.31 KB
/
ops.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
import math
import numpy as np
import tensorflow as tf
'''
some helper code borrowed from:
https://github.com/carpedm20/DCGAN-tensorflow
'''
def linear(input_, output_size, scope=None, stddev=1.0, bias_start=0.0, with_w=False):
shape = input_.get_shape().as_list()
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 = tf.get_variable("bias", [output_size],
initializer=tf.constant_initializer(bias_start))
if with_w:
return tf.matmul(input_, matrix) + bias, matrix, bias
else:
return tf.matmul(input_, matrix) + bias
def fully_connected(input_, output_size, scope=None, stddev=1.0, with_bias = True):
shape = input_.get_shape().as_list()
with tf.variable_scope(scope or "FC"):
matrix = tf.get_variable("Matrix", [shape[1], output_size], tf.float32,
tf.random_normal_initializer(stddev=stddev))
result = tf.matmul(input_, matrix)
if with_bias:
bias = tf.get_variable("bias", [1, output_size],
initializer=tf.random_normal_initializer(stddev=stddev))
result += bias*tf.ones([shape[0], 1], dtype=tf.float32)
return result