Skip to content

Instantly share code, notes, and snippets.

View glhfgg1024's full-sized avatar

glhfgg1024

View GitHub Profile
@glhfgg1024
glhfgg1024 / vgg16_fc_convolution.py
Created August 7, 2017 03:23
tensorflow convert fully connected layer to convolutional layer
def vgg16_fc_convolution(in_put, out_channel, layer_name, use_relu=True):
with tf.variable_scope(layer_name):
input_shape = in_put.get_shape()
assert len(input_shape) == 4
height, width, in_channel = input_shape[1:]
print(height, width, in_channel)
weights = tf.get_variable(name="weights", shape=[height*width*in_channel, out_channel])
biases = tf.get_variable(name="biases", shape=[out_channel])
reshape_weights = tf.reshape(weights,
shape=[tf.to_int32(height), tf.to_int32(width),