This repository was archived by the owner on Jul 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathlayers.py
More file actions
43 lines (34 loc) · 1.26 KB
/
layers.py
File metadata and controls
43 lines (34 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
32
33
34
35
36
37
38
39
40
41
42
43
import tensorflow as tf
from utils import get_layer_uid
class Layer(object):
def __init__(self, nonlin=tf.identity, N=1, name=None, logging=False):
self.N = N
if name is None:
layer = self.__class__.__name__.lower()
name = layer + '_' + str(get_layer_uid(layer))
self.name = name
self.logging = logging
self.nonlinearity = nonlin
self.build()
print 'Logging: {}'.format(self.logging)
def __call__(self, x, sample=True, **kwargs):
with tf.name_scope(self.name):
if self.logging:
tf.summary.histogram(self.name + '/inputs', x)
output = self.call(x, sample=sample, **kwargs)
if self.logging:
tf.summary.histogram(self.name + '/outputs', output)
outputs = self.nonlinearity(output)
return outputs
def call(self, x, sample=True, **kwargs):
raise NotImplementedError()
def build(self):
raise NotImplementedError()
def f(self, x, sampling=True, **kwargs):
raise NotImplementedError()
def get_reg(self):
return - (1. / self.N) * self.kldiv()
def kldiv(self):
raise NotImplementedError
from dense_layers import *
from conv_layers import *