def fully_connected(bottom, n_out, name, reuse=DO_SHARE):
shape = bottom.get_shape().as_list()
with tf.variable_scope(name, reuse = reuse):
# need to flattent he final result, find the dimension that is to be flattened
dim = 1
for d in shape[1:]:
dim *= d
# print(dim)
x = tf.reshape(bottom, [-1, dim])
weights = tf.get_variable('weights', [dim, n_out], tf.float32, xavier_initializer())
biases = tf.get_variable('bias', [n_out], tf.float32, tf.constant_initializer(0.0))
logits = tf.nn.bias_add(tf.matmul(x, weights), biases)
return tf.nn.relu(logits)
评论列表
文章目录