-
Notifications
You must be signed in to change notification settings - Fork 0
/
inits.py
34 lines (25 loc) · 951 Bytes
/
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
25
26
27
28
29
30
31
32
33
34
import numpy as np
import tensorflow as tf
def uniform(shape, scale=0.05, name=None):
"""Uniform init."""
initial = tf.random.uniform(shape,
minval=-scale,
maxval=scale,
dtype=tf.float32)
return tf.Variable(initial, 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)
return tf.Variable(initial, name=name)
def zeros(shape, name=None):
"""All zeros."""
initial = tf.zeros(shape, dtype=tf.float32)
return tf.Variable(initial, name=name)
def ones(shape, name=None):
"""All ones."""
initial = tf.ones(shape, dtype=tf.float32)
return tf.Variable(initial, name=name)