-
Notifications
You must be signed in to change notification settings - Fork 1
/
meta_layers.py
37 lines (25 loc) · 1.13 KB
/
meta_layers.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
import tensorflow as tf
def conv3d(input_layer, weights, bias, strides=None, padding='VALID', activation=None, name=None):
with tf.variable_scope(name):
if strides is None:
strides = (1, 1)
strides = (1, ) + strides + (1, )
conv3d_out = tf.nn.conv3d(input_layer, weights, strides, padding=padding)
if activation is not None:
return activation(conv3d_out + bias)
return conv3d_out + bias
def conv2d(input_layer, weights, bias, strides=None, padding='VALID', activation=None, name=None):
with tf.variable_scope(name):
if strides is None:
strides = (1, 1)
strides = (1,) + strides + (1, )
conv2d_out = tf.nn.conv2d(input_layer, weights, strides, padding=padding)
if activation is not None:
return activation(conv2d_out) + bias
return conv2d_out + bias
def dense(input_layer, weights, bias, activation, name=None):
with tf.variable_scope(name):
dense_out = tf.matmul(input_layer, weights) + bias
if activation is not None:
return activation(dense_out)
return dense_out