-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.py
More file actions
31 lines (26 loc) · 1.26 KB
/
common.py
File metadata and controls
31 lines (26 loc) · 1.26 KB
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
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import tensorflow as tf
import numpy as np
HParams = {'relu_leakiness': 0.1, 'num_classes': 1000, 'learning_rate': 1e-5, 'beta': 1e5, 'codec_dim': 96}
def add_relu(x, leakiness=0.0, scope=None):
with tf.variable_scope(scope or 'relu'):
return tf.where(tf.less(x, 0.0), leakiness * x, x, name='leaky_relu')
def add_sigmoid(x, scope=None):
with tf.variable_scope(scope or 'sigmoid'):
return tf.nn.sigmoid(x, name='nn_sigmoid')
def add_tanh(x, scope=None):
with tf.variable_scope(scope or 'tangent'):
return tf.nn.tanh(x, name='nn_tangent')
def add_conv2d(x, kernel_size, in_channels, out_channels, strides, scope=None):
with tf.variable_scope(scope or 'conv2d'):
n = kernel_size * kernel_size * in_channels
filter = tf.get_variable(
'filter', [kernel_size, kernel_size, in_channels, out_channels],
initializer=tf.random_normal_initializer(stddev=np.sqrt(2.0 / n)),
dtype=tf.float32)
conv = tf.nn.conv2d(x, filter, strides, padding='SAME')
biases = tf.get_variable('biases', [out_channels], dtype=tf.float32, initializer=tf.constant_initializer(0.0))
pre_activation = tf.nn.bias_add(conv, biases)
return pre_activation