-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathm_inits.py
24 lines (17 loc) · 854 Bytes
/
m_inits.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
import numpy as np
import tensorflow as tf
def init_variable(size, dim, name=None):
std = np.sqrt(2/dim)
return tf.Variable(tf.random_uniform([size, dim], -std, std), name=name)
def glorot(shape, name=None):
"""Glorot & Bengio (AISTATS 2010) init."""
# init_range = np.sqrt(6.0/(shape[0]+shape[1]))
# initial = tf.random_uniform(shape, minval=-init_range, maxval=init_range, dtype=tf.float32)
# initial = tf.random_uniform(shape, stddev=0.1)
# return tf.Variable(tf.random_normal(shape, stddev=1.0))
return tf.Variable(tf.truncated_normal(shape=shape, stddev=0.1))
# return tf.Variable(tf.truncated_normal(shape=shape, stddev=np.sqrt(2/shape[0])))
def zeros(shape, name=None):
"""All zeros."""
initial = tf.zeros(shape, dtype=tf.float32)
return tf.Variable(initial, name=name)