def LeNetConvPoolLayer(inps, feature_map, batch, length, window, dim, prefix, params, names):
fan_in = window * dim
fan_out = feature_map * window * dim / (length - window + 1)
filter_shape = (feature_map, 1, window, dim)
image_shape = (batch, 1, length, dim)
pool_size = (length - window + 1, 1)
#if non_linear=="none" or non_linear=="relu":
# conv_W = theano.shared(0.2 * numpy.random.uniform(low=-1.0,high=1.0,\
# size=filter_shape).astype(theano.config.floatX))
#else:
# W_bound = numpy.sqrt(6. / (fan_in + fan_out))
# conv_W = theano.shared(numpy.random.uniform(low=-W_bound,high=W_bound,\
# size=filter_shape).astype(theano.config.floatX))
W_bound = numpy.sqrt(6. / (fan_in + fan_out))
conv_W = theano.shared(numpy.random.uniform(low=-W_bound,high=W_bound,\
size=filter_shape).astype(theano.config.floatX))
conv_b = theano.shared(numpy.zeros(filter_shape[0], dtype=theano.config.floatX))
# bundle
params += [ conv_W, conv_b ]
names += [ prefix + '_conv_W_' + str(window), prefix + '_conv_b_' + str(window) ]
conv_out = conv.conv2d(input=inps, filters=conv_W, filter_shape=filter_shape, image_shape=image_shape)
conv_out_act = T.tanh(conv_out + conv_b.dimshuffle('x', 0, 'x', 'x'))
conv_output = downsample.max_pool_2d(input=conv_out_act, ds=pool_size, ignore_border=True)
return conv_output.flatten(2)
评论列表
文章目录