def BinarizedWeightOnlySpatialConvolution(nOutputPlane, kW, kH, dW=1, dH=1,
padding='VALID', bias=True, reuse=None, name='BinarizedWeightOnlySpatialConvolution'):
'''
This function is used only at the first layer of the model as we dont want to binarized the RGB images
'''
def bc_conv2d(x, is_training=True):
nInputPlane = x.get_shape().as_list()[3]
with tf.variable_op_scope([x], None, name, reuse=reuse):
w = tf.get_variable('weight', [kH, kW, nInputPlane, nOutputPlane],
initializer=tf.contrib.layers.xavier_initializer_conv2d())
bin_w = binarize(w)
out = tf.nn.conv2d(x, bin_w, strides=[1, dH, dW, 1], padding=padding)
if bias:
b = tf.get_variable('bias', [nOutputPlane],initializer=tf.zeros_initializer)
out = tf.nn.bias_add(out, b)
return out
return bc_conv2d
评论列表
文章目录