-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeedforward_network_camera.py
More file actions
executable file
·66 lines (53 loc) · 2.31 KB
/
feedforward_network_camera.py
File metadata and controls
executable file
·66 lines (53 loc) · 2.31 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import numpy as np
import tensorflow as tf
'''
OLD NETWORK:
inp x 500 --> 1x500
500 x 500 --> 1x500
500 x out --> 1xout
NEW NETWORK:
inp x 500 --> 1x500
(501*5) x 500 --> 1x500
500 x out --> 1xout
fused:
([u 1]' [v 1]).ravel
(501*5)
'''
def feedforward_network(inputState, inputSize, outputSize, num_fc_layers, depth_fc_layers, tf_datatype, tiled_onehots):
#vars
intermediate_size= 200 #########depth_fc_layers
reuse= False
initializer = tf.contrib.layers.xavier_initializer(uniform=False, seed=None, dtype=tf_datatype)
flatten = tf.contrib.layers.flatten
fc = tf.contrib.layers.fully_connected
#1st hidden layer
fc_1 = fc(inputState, num_outputs=intermediate_size, activation_fn=None,
weights_initializer=initializer, biases_initializer=initializer, reuse=reuse, trainable=True)
h_1 = tf.nn.relu(fc_1)
#pass onehot in through some small fc layers
this_size = 32
oh_1 = fc(tiled_onehots, num_outputs=this_size, activation_fn=None,
weights_initializer=initializer, biases_initializer=initializer, reuse=reuse, trainable=True)
oh_1 = tf.nn.relu(oh_1)
oh_2 = fc(oh_1, num_outputs=this_size, activation_fn=None,
weights_initializer=initializer, biases_initializer=initializer, reuse=reuse, trainable=True)
oh_2 = tf.nn.relu(oh_2)
oh_3 = fc(oh_2, num_outputs=int(tiled_onehots.shape[1]), activation_fn=None,
weights_initializer=initializer, biases_initializer=initializer, reuse=reuse, trainable=True)
v = tf.nn.relu(oh_3)
#fuse
#h_1 is [bs x 500]
#tiled_onehots is [bs x 4]
u= tf.transpose(h_1)
u_batch = tf.expand_dims(u, 2) #[500 x bs x 1]
u_batch = tf.transpose(u_batch, [1, 0, 2]) #[bs x 500 x 1]
v_batch = tf.expand_dims(v, 1) #[bs x 1 x 4]
fuse = flatten(tf.matmul(u_batch, v_batch)) #[bs x 500 x 4] --> [bs x 2000]
#2nd hidden layer
fc_2 = fc(fuse, num_outputs=intermediate_size, activation_fn=None,
weights_initializer=initializer, biases_initializer=initializer, reuse=reuse, trainable=True)
h_2 = tf.nn.relu(fc_2)
# make output layer
z=fc(h_2, num_outputs=outputSize, activation_fn=None, weights_initializer=initializer,
biases_initializer=initializer, reuse=reuse, trainable=True)
return z