-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlocalFunctions.py
47 lines (31 loc) · 1.16 KB
/
localFunctions.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
38
39
40
41
42
43
44
45
46
47
from __future__ import print_function
import tensorflow as tf
import numpy as np
import uuid
def heconstant(p):
def initializer(shape, dtype=None):
nlp = np.prod(shape[:-1])
a = np.sqrt(2 / nlp)
distribution = np.random.choice([-1., 1.], shape, p=[p, 1 - p])
return tf.Variable(a * distribution, dtype=dtype, name=uuid.uuid4().hex)
return initializer
def magnitude(a):
def initializer(shape, dtype=None):
return tf.Variable(a * np.ones(shape), dtype=dtype, name=uuid.uuid4().hex)
return initializer
def activate(x, activationtype):
if activationtype is None:
return x
if 'relu' == activationtype:
return tf.keras.activations.relu(x)
if 'softmax' in activationtype:
return tf.keras.activations.softmax(x)
if 'sigmoid' in activationtype:
return tf.keras.activations.sigmoid(x)
if 'swish' in activationtype:
return tf.keras.activations.sigmoid(x) * x
if "elu" in activationtype:
return tf.keras.activations.elu(x)
if "selu" in activationtype:
return tf.keras.activations.selu(x)
return x