def __init__(self, input, filter_shape, image_shape, padding=(0, 0),
stride=(1, 1), activation_fn=None, seed=3235):
assert image_shape[1] == filter_shape[1]
# rng = np.random.RandomState(seed)
self.input = input
self.filter_shape = filter_shape
self.image_shape = image_shape
self.activation_fn = activation_fn
fan_in = np.prod(filter_shape[1:])
fan_out = filter_shape[0]*np.prod(filter_shape[2:]) // 2
W_bound = np.sqrt(6/(fan_in+fan_out))
w = np.random.uniform(low=-W_bound, high=W_bound, size=filter_shape)
b_vals = np.random.uniform(size=filter_shape[0])
# Initiliaze weights with random variables
self.W = theano.shared(name='weights',
value=w.astype(theano.config.floatX),
borrow=True)
self.b = theano.shared(name='bias',
value=b_vals.astype(theano.config.floatX),
borrow=True)
conv_out = conv2d(input=input, filters=self.W, border_mode=padding,
subsample=stride, filter_shape=filter_shape,
input_shape=image_shape)
l_output = conv_out + self.b.dimshuffle(('x', 0, 'x', 'x'))
self.output = (l_output if activation_fn is None
else activation_fn(l_output))
# Parameters of the model
self.params = [self.W, self.b]
评论列表
文章目录