本文整理汇总了Python中theano.tensor.nnet.conv2d函数的典型用法代码示例。如果您正苦于以下问题:Python conv2d函数的具体用法?Python conv2d怎么用?Python conv2d使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了conv2d函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _backward_negative_z
def _backward_negative_z(inputs, weights, normed_relevances, bias=None):
inputs_plus = inputs * T.gt(inputs, 0)
weights_plus = weights * T.gt(weights, 0)
inputs_minus = inputs * T.lt(inputs, 0)
weights_minus = weights * T.lt(weights, 0)
# Compute weights+ * inputs- and weights- * inputs+
negative_part_a = conv2d(
normed_relevances, weights_plus.dimshuffle(1, 0, 2, 3)[:, :, ::-1, ::-1], border_mode="full"
)
negative_part_a *= inputs_minus
negative_part_b = conv2d(
normed_relevances, weights_minus.dimshuffle(1, 0, 2, 3)[:, :, ::-1, ::-1], border_mode="full"
)
negative_part_b *= inputs_plus
together = negative_part_a + negative_part_b
if bias is not None:
bias_negative = bias * T.lt(bias, 0)
bias_relevance = bias_negative.dimshuffle("x", 0, "x", "x") * normed_relevances
# Divide bias by weight size before convolving back
# mean across channel, 0, 1 dims (hope this is correct?)
fraction_bias = bias_relevance / T.prod(weights.shape[1:]).astype(theano.config.floatX)
bias_rel_in = conv2d(
fraction_bias, T.ones_like(weights).dimshuffle(1, 0, 2, 3)[:, :, ::-1, ::-1], border_mode="full"
)
together += bias_rel_in
return together
开发者ID:robintibor,项目名称:braindecode,代码行数:27,代码来源:heatmap.py
示例2: relevance_conv_z
def relevance_conv_z(out_relevances, inputs, weights, bias=None):
norms_for_relevances = conv2d(inputs, weights)
if bias is not None:
norms_for_relevances += bias.dimshuffle("x", 0, "x", "x")
# stabilize
# prevent division by 0 and division by small numbers
eps = 1e-4
norms_for_relevances += T.sgn(norms_for_relevances) * eps
norms_for_relevances += T.eq(norms_for_relevances, 0) * eps
normed_relevances = out_relevances / norms_for_relevances
# upconv
in_relevances = conv2d(normed_relevances, weights.dimshuffle(1, 0, 2, 3)[:, :, ::-1, ::-1], border_mode="full")
in_relevances_proper = in_relevances * inputs
if bias is not None:
bias_relevance = bias.dimshuffle("x", 0, "x", "x") * normed_relevances
# Divide bias by weight size before convolving back
# mean across channel, 0, 1 dims (hope this is correct?)
fraction_bias = bias_relevance / T.prod(weights.shape[1:]).astype(theano.config.floatX)
bias_rel_in = conv2d(
fraction_bias, T.ones_like(weights).dimshuffle(1, 0, 2, 3)[:, :, ::-1, ::-1], border_mode="full"
)
in_relevances_proper += bias_rel_in
return in_relevances_proper
开发者ID:robintibor,项目名称:braindecode,代码行数:27,代码来源:heatmap.py
示例3: convolutional_model
def convolutional_model(X, w_1, w_2, w_3, w_4, w_5, w_6, p_1, p_2, p_3, p_4, p_5):
l1 = dropout(T.tanh( max_pool_2d(T.maximum(conv2d(X, w_1, border_mode='full'),0.), (2, 2),ignore_border=True) + b_1.dimshuffle('x', 0, 'x', 'x') ), p_1)
l2 = dropout(T.tanh( max_pool_2d(T.maximum(conv2d(l1, w_2), 0.), (2, 2),ignore_border=True) + b_2.dimshuffle('x', 0, 'x', 'x') ), p_2)
l3 = dropout(T.flatten(T.tanh( max_pool_2d(T.maximum(conv2d(l2, w_3), 0.), (2, 2),ignore_border=True) + b_3.dimshuffle('x', 0, 'x', 'x') ), outdim=2), p_3)# flatten to switch back to 1d layers
l4 = dropout(T.maximum(T.dot(l3, w_4), 0.), p_4)
l5 = dropout(T.maximum(T.dot(l4, w_5), 0.), p_5)
return T.dot(l5, w_6)
开发者ID:mjasek114,项目名称:w207-Kaggle-Facial-Keypoint-Detection,代码行数:7,代码来源:ConvoNN_V3.py
示例4: lecun_lcn
def lecun_lcn(self, X, kernel_size=7, threshold = 1e-4, use_divisor=False):
"""
Yann LeCun's local contrast normalization
Orginal code in Theano by: Guillaume Desjardins
"""
filter_shape = (1, 1, kernel_size, kernel_size)
filters = gaussian_filter(kernel_size).reshape(filter_shape)
filters = shared(_asarray(filters, dtype=floatX), borrow=True)
convout = conv2d(X, filters=filters, filter_shape=filter_shape,
border_mode='full')
# For each pixel, remove mean of kernel_sizexkernel_size neighborhood
mid = int(floor(kernel_size/2.))
new_X = X - convout[:,:,mid:-mid,mid:-mid]
if use_divisor:
# Scale down norm of kernel_sizexkernel_size patch
sum_sqr_XX = conv2d(T.sqr(T.abs_(X)), filters=filters,
filter_shape=filter_shape, border_mode='full')
denom = T.sqrt(sum_sqr_XX[:,:,mid:-mid,mid:-mid])
per_img_mean = denom.mean(axis=[2,3])
divisor = T.largest(per_img_mean.dimshuffle(0,1,'x','x'), denom)
divisor = T.maximum(divisor, threshold)
new_X /= divisor
return new_X#T.cast(new_X, floatX)
开发者ID:Tgaaly,项目名称:Theano-3D-ConvNet,代码行数:30,代码来源:convnet3d.py
示例5: relevance_conv_z_plus
def relevance_conv_z_plus(out_relevances, inputs, weights, bias=None):
if bias is not None:
log.warning("Bias not respected for conv z_plus")
# hack for negative inputs
# inputs = T.abs_(inputs)
weights_plus = weights * T.gt(weights, 0)
norms_for_relevances = conv2d(inputs, weights_plus)
# prevent division by 0...
# adds 1 to every entry that is 0 -> sets 0s to 1
relevances_are_0 = T.eq(norms_for_relevances, 0)
norms_for_relevances += relevances_are_0 * 1
normed_relevances = out_relevances / norms_for_relevances
# upconv
in_relevances = conv2d(normed_relevances, weights_plus.dimshuffle(1, 0, 2, 3)[:, :, ::-1, ::-1], border_mode="full")
in_relevances_proper = in_relevances * inputs
# Correct for those parts where all inputs of a relevance were
# zero, spread relevance equally them
pool_ones = T.ones(weights_plus.shape, dtype=np.float32)
# mean across channel, 0, 1 dims (hope this is correct?)
pool_fractions = pool_ones / T.prod(weights_plus.shape[1:]).astype(theano.config.floatX)
in_relevances_from_0 = conv2d(
out_relevances * relevances_are_0, pool_fractions.dimshuffle(1, 0, 2, 3), subsample=(1, 1), border_mode="full"
)
in_relevances_proper += in_relevances_from_0
return in_relevances_proper
开发者ID:robintibor,项目名称:braindecode,代码行数:30,代码来源:heatmap.py
示例6: theano_kernel_derivative
def theano_kernel_derivative(imshp,kshp,featshp,stride=1):
features = T.tensor4(dtype=theano.config.floatX)
kernel = T.tensor4(dtype=theano.config.floatX)
image = T.tensor4(dtype=theano.config.floatX)
# Need to transpose first two dimensions of kernel, and reverse index kernel image dims (for correlation)
kernel_rotated = T.transpose(kernel[:,:,::-1,::-1],axes=[1,0,2,3])
featshp_logical = (featshp[0],featshp[1],featshp[2]*stride,featshp[3]*stride)
kshp_rotated = (kshp[1], kshp[0], kshp[2], kshp[3])
image_estimate = conv2d(features,kernel_rotated,border_mode='full',
image_shape=featshp,filter_shape=kshp_rotated,
imshp_logical=featshp_logical[1:],kshp_logical=kshp[2:])
image_error = image - image_estimate
image_error_rot = T.transpose(image_error,[1,0,2,3])[:,:,::-1,::-1]
imshp_rot = (imshp[1],imshp[0],imshp[2],imshp[3])
featshp_rot = (featshp[1],featshp[0],featshp[2],featshp[3])
features_rot = T.transpose(features,[1,0,2,3])
featshp_rot_logical = (featshp_rot[0],featshp_rot[1],featshp_rot[2]*stride,featshp_rot[3]*stride)
kernel_grad_rot = -conv2d(image_error_rot,features_rot,
image_shape=imshp_rot,filter_shape=featshp_rot,
imshp_logical=imshp_rot[1:],kshp_logical=featshp_rot_logical[2:])
kernel_grad = T.transpose(kernel_grad_rot,[1,0,2,3])
return function(inputs=[image,features,kernel],outputs=kernel_grad)
开发者ID:baylabs,项目名称:hdl,代码行数:29,代码来源:conv_models.py
示例7: model
def model(X, params, featMaps, pieces, pDropConv, pDropHidden):
lnum = 0 # conv: (32, 32) pool: (16, 16)
layer = conv2d(X, params[lnum][0], border_mode='half') + \
params[lnum][1].dimshuffle('x', 0, 'x', 'x')
layer = maxout(layer, featMaps[lnum], pieces[lnum])
layer = pool_2d(layer, (2, 2), st=(2, 2), ignore_border=False, mode='max')
layer = basicUtils.dropout(layer, pDropConv)
lnum += 1 # conv: (16, 16) pool: (8, 8)
layer = conv2d(layer, params[lnum][0], border_mode='half') + \
params[lnum][1].dimshuffle('x', 0, 'x', 'x')
layer = maxout(layer, featMaps[lnum], pieces[lnum])
layer = pool_2d(layer, (2, 2), st=(2, 2), ignore_border=False, mode='max')
layer = basicUtils.dropout(layer, pDropConv)
lnum += 1 # conv: (8, 8) pool: (4, 4)
layer = conv2d(layer, params[lnum][0], border_mode='half') + \
params[lnum][1].dimshuffle('x', 0, 'x', 'x')
layer = maxout(layer, featMaps[lnum], pieces[lnum])
layer = pool_2d(layer, (2, 2), st=(2, 2), ignore_border=False, mode='max')
layer = basicUtils.dropout(layer, pDropConv)
lnum += 1
layer = T.flatten(layer, outdim=2)
layer = T.dot(layer, params[lnum][0]) + params[lnum][1].dimshuffle('x', 0)
layer = relu(layer, alpha=0)
layer = basicUtils.dropout(layer, pDropHidden)
lnum += 1
layer = T.dot(layer, params[lnum][0]) + params[lnum][1].dimshuffle('x', 0)
layer = relu(layer, alpha=0)
layer = basicUtils.dropout(layer, pDropHidden)
lnum += 1
return softmax(T.dot(layer, params[lnum][0]) + params[lnum][1].dimshuffle('x', 0)) # 如果使用nnet中的softmax训练产生NAN
开发者ID:ifenghao,项目名称:myDeepLearning,代码行数:30,代码来源:Maxoutconv1.py
示例8: relevance_conv_a_b_abs
def relevance_conv_a_b_abs(inputs, weights, out_relevances, a, b, bias=None):
assert a is not None
assert b is not None
assert a - b == 1
weights_plus = weights * T.gt(weights, 0)
weights_neg = weights * T.lt(weights, 0)
plus_norm = conv2d(T.abs_(inputs), weights_plus)
# stabilize, prevent division by 0
eps = 1e-4
plus_norm += T.eq(plus_norm, 0) * eps
plus_rel_normed = out_relevances / plus_norm
in_rel_plus = conv2d(plus_rel_normed, weights_plus.dimshuffle(1, 0, 2, 3)[:, :, ::-1, ::-1], border_mode="full")
in_rel_plus *= T.abs_(inputs)
# minuses to get positive outputs, since will be subtracted
# at end of function
neg_norm = -conv2d(T.abs_(inputs), weights_neg)
neg_norm += T.eq(neg_norm, 0) * eps
neg_rel_normed = out_relevances / neg_norm
in_rel_neg = -conv2d(neg_rel_normed, weights_neg.dimshuffle(1, 0, 2, 3)[:, :, ::-1, ::-1], border_mode="full")
in_rel_neg *= T.abs_(inputs)
in_relevance = a * in_rel_plus - b * in_rel_neg
return in_relevance
开发者ID:robintibor,项目名称:braindecode,代码行数:25,代码来源:heatmap.py
示例9: metaOp1
def metaOp1(i, j, X, w1, w2, b1, b2):
# (n,1,r,c)**(16,1,3,3)=(n,16,r,c)
hiddens = conv2d(X[:, j, :, :, :], w1[i, j, :, :, :, :], border_mode='half') + b1[i, j, :, :, :, :]
hiddens = relu(hiddens, alpha=0)
# (n,16,r,c)**(1,16,1,1)=(n,1,r,c)
outputs = conv2d(hiddens, w2[i, j, :, :, :, :], border_mode='valid') + b2[i, j, :, :, :, :]
outputs = relu(outputs, alpha=0)
return outputs
开发者ID:ifenghao,项目名称:myDeepLearning,代码行数:8,代码来源:rowfccolfcv1.py
示例10: metaOp
def metaOp(i, j, X, w1, w2, b1, b2):
# (n,1,r,c)**(16,1,3,3)=(n,16,r,c)
hiddens = conv2d(X[:, j, :, :, :], w1[i, j, :, :, :, :], border_mode='half') + b1[i, j, :, :, :, :]
hiddens = relu(hiddens, alpha=0)
# 在元操作中就需要包含relu激活
# return conv2d(hiddens, w2[i, j, :, :, :, :], border_mode='valid') + b2[i, j, :, :, :, :]
# (n,16,r,c)**(1,16,1,1)=(n,1,r,c)
outputs = conv2d(hiddens, w2[i, j, :, :, :, :], border_mode='valid') + b2[i, j, :, :, :, :]
return T.nnet.relu(outputs)
开发者ID:ifenghao,项目名称:myDeepLearning,代码行数:9,代码来源:NINfclayer.py
示例11: connect_through
def connect_through(self, alm1_in=None, Pl=None, Ll=None):
""" connect_through
@note Note that I made connect_through a separate class method, separate from the automatic initialization,
because you can then make changes to the "layer units" or "nodes" before "connecting the layers"
"""
if alm1_in is not None:
self.alm1 = alm1_in
self.Pl = Pl
alm1 = self.alm1
c = self.c
C_lm1,C_l = self.C_ls
Wl = self.Wl
filter_shape = (C_l,C_lm1)+Wl
assert len(filter_shape) == (2+len(Wl))
# convolve input feature maps with filters
if Ll is not None:
batch_size = alm1.shape[0] # This is m, number of input examples
# image_shape = (batch_size,C_lm1)+Ll
image_shape = (None,C_lm1)+Ll
conv_out = conv2d(
input=alm1,
filters=c,
filter_shape=filter_shape,
input_shape=image_shape)
else:
conv_out = conv2d(
input=alm1,
filters=c,
filter_shape=filter_shape)
# pool each feature map individually, using maxpooling
if Pl is not None:
pooled_out = pool.pool_2d(
input=conv_out,
ws=Pl,
ignore_border=True)
# add bias term
if self.psi is None:
self.al = pooled_out + self.b.dimshuffle('x',0,'x','x')
else:
self.al = self.psi( pooled_out + self.b.dimshuffle('x',0,'x','x') )
else:
# add bias term
if self.psi is None:
self.al = conv_out + self.b.dimshuffle('x',0,'x','x')
else:
self.al = self.psi( conv_out + self.b.dimshuffle('x',0,'x','x') )
return self.al
开发者ID:ernestyalumni,项目名称:MLgrabbag,代码行数:57,代码来源:CNN.py
示例12: CNN
def CNN(x,c_l1,c_l2,f_l1,f_l2):
conv1=tensor.nnet.relu(conv2d(x,c_l1)) #default stride=1 --subsample=(1,1)
pool1=pool_2d(conv1,(2,2),st=(2,2),ignore_border=True) #default maxpool
conv2=tensor.nnet.relu(conv2d(pool1,c_l2))
pool2=pool_2d(conv2,(2,2),st=(2,2),ignore_border=True)
fpool2=tensor.flatten(pool2,outdim=2)
full1=tensor.nnet.relu(tensor.dot(fpool2,f_l1))
pyx=tensor.nnet.sigmoid(tensor.dot(full1,f_l2))
return c_l1, c_l2, f_l1, f_l2, pyx
开发者ID:yunjieliu,项目名称:Machine-Learning,代码行数:10,代码来源:FR_CNN.py
示例13: predict_custom_image
def predict_custom_image(params, testImgFilename='own_0.png', activation= activation_convmlp, testImgFilenameDir = '../data/custom/'):
test_img_value = filter(str.isdigit, testImgFilename)
test_img = fli.processImg(testImgFilenameDir, testImgFilename)
nkerns = [20, 50]
batch_size = 1
poolsize = (2, 2)
layer0_input = test_img.reshape((batch_size, 1, 28, 28)).astype(numpy.float32)
conv_out_0 = conv2d(
input=layer0_input,
filters=params[6],
input_shape=(batch_size, 1, 28, 28),
filter_shape=(nkerns[0], 1, 5, 5)
)
# downsample each feature map individually, using maxpooling
pooled_out_0 = downsample.max_pool_2d(
input=conv_out_0,
ds=poolsize,
ignore_border=True
)
output_0 = activation(pooled_out_0 + params[7].dimshuffle('x', 0, 'x', 'x'))
conv_out_1 = conv2d(
input=output_0,
filters=params[4],
input_shape=(batch_size, nkerns[0], 12, 12),
filter_shape=(nkerns[1], nkerns[0], 5, 5),
)
# downsample each feature map individually, using maxpooling
pooled_out_1 = downsample.max_pool_2d(
input=conv_out_1,
ds=poolsize,
ignore_border=True
)
output_1 = activation(pooled_out_1 + params[5].dimshuffle('x', 0, 'x', 'x'))
output_2 = activation(T.dot(output_1.flatten(2), params[2]) + params[3])
final_output = T.dot(output_2, params[0]) + params[1]
p_y_given_x = T.nnet.softmax(final_output)
y_pred = T.argmax(p_y_given_x, axis=1)
testfunc = theano.function([], [y_pred[0]])
prediction = testfunc()[0]
correct = (int(test_img_value) == prediction)
print('The prediction ' + str(testfunc()[0]) + ' for ' + testImgFilename + ' is ' + str(correct) + '.')
return correct
开发者ID:laputian,项目名称:dml,代码行数:53,代码来源:convolutional_mlp_modified.py
示例14: _forward_negative_z
def _forward_negative_z(inputs, weights, bias=None):
inputs_plus = inputs * T.gt(inputs, 0)
weights_plus = weights * T.gt(weights, 0)
inputs_minus = inputs * T.lt(inputs, 0)
weights_minus = weights * T.lt(weights, 0)
negative_part_a = conv2d(inputs_plus, weights_minus)
negative_part_b = conv2d(inputs_minus, weights_plus)
together = negative_part_a + negative_part_b
if bias is not None:
bias_negative = bias * T.lt(bias, 0)
together += bias_negative.dimshuffle("x", 0, "x", "x")
return together
开发者ID:robintibor,项目名称:braindecode,代码行数:13,代码来源:heatmap.py
示例15: conv2d_test_sets
def conv2d_test_sets():
def _convert(input, kernel, output, kwargs):
return [theano.shared(floatX(input)), floatX(kernel), output, kwargs]
input = np.random.random((3, 1, 16, 16))
kernel = np.random.random((16, 1, 3, 3))
output = conv2d(input, kernel).eval()
yield _convert(input, kernel, output, {})
input = np.random.random((3, 3, 16, 16))
kernel = np.random.random((16, 3, 3, 3))
output = conv2d(input, kernel).eval()
yield _convert(input, kernel, output, {})
开发者ID:dimatura,项目名称:nntools,代码行数:13,代码来源:test_conv.py
示例16: modelFlow
def modelFlow(X, params):
lconv1 = relu(conv2d(X, params[0][0], border_mode='full') +
params[0][1].dimshuffle('x', 0, 'x', 'x'))
lds1 = pool_2d(lconv1, (2, 2))
lconv2 = relu(conv2d(lds1, params[1][0]) +
params[1][1].dimshuffle('x', 0, 'x', 'x'))
lds2 = pool_2d(lconv2, (2, 2))
lconv3 = relu(conv2d(lds2, params[2][0]) +
params[2][1].dimshuffle('x', 0, 'x', 'x'))
lds3 = pool_2d(lconv3, (2, 2))
return X, lconv1, lds1, lconv2, lds2, lconv3, lds3
开发者ID:ifenghao,项目名称:myDeepLearning,代码行数:13,代码来源:visualize.py
示例17: nin2
def nin2(X, param, shape):
w1, w2 = param
map0 = []
for i in xrange(shape[0]):
map1 = []
for j in xrange(shape[1]):
Xj = X[:, j, :, :].dimshuffle(0, 'x', 1, 2)
w1ij = w1[i, j, :, :, :].dimshuffle(0, 'x', 1, 2)
w2ij = w2[i, j, :].dimshuffle('x', 0, 'x', 'x')
tmp = conv2d(Xj, w1ij, border_mode='valid')
tmp = relu(tmp, alpha=0)
map1.append(conv2d(tmp, w2ij, border_mode='valid'))
map0.append(relu(T.sum(map1, axis=0), alpha=0))
return T.concatenate(map0, axis=1)
开发者ID:ifenghao,项目名称:myDeepLearning,代码行数:14,代码来源:scanloopcompare.py
示例18: __init__
def __init__(self, input, filter_shape, image_shape, f_params_w, f_params_b, lrn=False, t_style=None, t_content=None, convstride=1, padsize =0, group=1, poolsize = 3, poolstride = 1):
self.input = input
#theano.shared(np.asarray(np.input))
if t_style is not None:
self.t_style = np.asarray(np.load(t_style),dtype=theano.config.floatX)
if t_content is not None:
self.t_content = np.asarray(np.load(t_content),dtype=theano.config.floatX)
if lrn is True:
self.lrn_func = CrossChannelNormalization()
#if padsize==(0,0):
#padsize='valid'
if group == 1:
self.W = theano.shared(np.asarray(np.transpose(np.load(os.path.join(params_path,f_params_w)),(3,0,1,2)),dtype=theano.config.floatX), borrow=True)
self.b = theano.shared(np.asarray(np.load(os.path.join(params_path,f_params_b)),dtype=theano.config.floatX), borrow=True)
conv_out = conv2d(input=self.input,filters=self.W,filter_shape=filter_shape,border_mode = padsize,subsample=(convstride, convstride),filter_flip=True)
#self.params = [self.W, self.b]
elif group == 2:
self.filter_shape = np.asarray(filter_shape)
self.image_shape = np.asarray(image_shape)
self.filter_shape[0] = self.filter_shape[0] / 2
self.filter_shape[1] = self.filter_shape[1] / 2
#self.image_shape[0] = self.image_shape[0] / 2
self.image_shape[1] = self.image_shape[1] / 2
self.W0 = theano.shared(np.asarray(np.transpose(np.load(os.path.join(params_path,f_params_w[0])),(3,0,1,2)),dtype=theano.config.floatX), borrow=True)
self.W1 = theano.shared(np.asarray(np.transpose(np.load(os.path.join(params_path,f_params_w[1])),(3,0,1,2)),dtype=theano.config.floatX), borrow=True)
self.b0 = theano.shared(np.asarray(np.load(os.path.join(params_path,f_params_b[0])),dtype=theano.config.floatX), borrow=True)
self.b1 = theano.shared(np.asarray(np.load(os.path.join(params_path,f_params_b[1])),dtype=theano.config.floatX), borrow=True)
conv_out0 = conv2d(input=self.input[:,:self.image_shape[1],:,:],filters=self.W0,filter_shape=tuple(self.filter_shape),border_mode = padsize,subsample=(convstride, convstride),filter_flip=True) + self.b0.dimshuffle('x', 0, 'x', 'x')
conv_out1 = conv2d(input=self.input[:,self.image_shape[1]:,:,:],filters=self.W1,filter_shape=tuple(self.filter_shape),border_mode = padsize,subsample=(convstride, convstride),filter_flip=True) + self.b1.dimshuffle('x', 0, 'x', 'x')
conv_out = T.concatenate([conv_out0, conv_out1],axis=1)
#self.params = [self.W0, self.b0, self.W1, self.b1]
else:
raise AssertionError()
relu_out = T.maximum(conv_out, 0)
if poolsize != 1:
self.output = pool.pool_2d(input=relu_out,ds=(poolsize,poolsize),ignore_border=True, st=(poolstride,poolstride),mode='average_exc_pad')
#self.output = downsample.max_pool_2d(input=relu_out,ds=(poolsize,poolsize),ignore_border=True, st=(poolstride,poolstride))
else:
self.output = relu_out
if lrn is True:
# lrn_input = gpu_contiguous(self.output)
self.output = self.lrn_func(self.output)
开发者ID:lsh-verity,项目名称:theano_artistic_cnn,代码行数:50,代码来源:artistic_alexnet_train.py
示例19: lecun_lcn
def lecun_lcn(self, X, kernel_size=9, threshold = 1e-4, use_divisor=True, border=False):
"""
Yann LeCun's local contrast normalization
Orginal code in Theano by: Guillaume Desjardins
"""
filter_shape = (1, 1, kernel_size, kernel_size)
filters = gaussian_filter(kernel_size).reshape(filter_shape)
filters = shared(_asarray(filters, dtype=floatX), borrow=True)
mid = int(floor(kernel_size/2.))
if border:
r = (kernel_size-1)/2
up = X[:,:,0:1,:].repeat(r,axis=2)
down = X[:,:,-1:,:].repeat(r,axis=2)
X_ = T.concatenate([up,X,down],axis=2)
left = X_[:,:,:,0:1].repeat(r,axis=3)
right = X_[:,:,:,-1:].repeat(r,axis=3)
X_ = T.concatenate([left,X_,right],axis=3)
convout = conv2d(X_, filters=filters, filter_shape=filter_shape,
border_mode='valid')
centered_X = X - convout
else:
convout = conv2d(X, filters=filters, filter_shape=filter_shape,
border_mode='full')
# For each pixel, remove mean of kernel_sizexkernel_size neighborhood
centered_X = X - convout[:,:,mid:-mid,mid:-mid]
if use_divisor:
# Scale down norm of kernel_sizexkernel_size patch
sum_sqr_XX = conv2d(T.sqr(X), filters=filters,
filter_shape=filter_shape, border_mode='full')
sum_sqr_XX = sum_sqr_XX[:,:,mid:-mid,mid:-mid]
sum_sqr_XX = T.maximum(sum_sqr_XX, threshold)
denom = T.sqrt(sum_sqr_XX)
# denom = abs(centered_X)
per_img_mean = denom.mean(axis=[2,3])
divisor = T.largest(per_img_mean.dimshuffle(0,1,'x','x'), denom)
divisor = T.maximum(divisor, threshold)
new_X = centered_X / divisor
return new_X
else:
return centered_X
开发者ID:lpigou,项目名称:chalearn2014,代码行数:49,代码来源:convnet3d.py
示例20: conv1d_mc0
def conv1d_mc0(input, filters, input_shape=None, filter_shape=None,
border_mode='valid', subsample=(1,)):
"""
Using conv2d with width == 1.
"""
image_shape = input_shape
if image_shape is None:
image_shape_mc0 = None
else:
# (b, c, i0) to (b, c, 1, i0)
image_shape_mc0 = (image_shape[0], image_shape[1], 1, image_shape[2])
if filter_shape is None:
filter_shape_mc0 = None
else:
filter_shape_mc0 = (filter_shape[0], filter_shape[1], 1,
filter_shape[2])
input_mc0 = input.dimshuffle(0, 1, 'x', 2)
filters_mc0 = filters.dimshuffle(0, 1, 'x', 2)
conved = conv2d(
input_mc0, filters_mc0, input_shape=image_shape_mc0,
filter_shape=filter_shape_mc0, subsample=(1, subsample[0]),
border_mode=border_mode)
return conved[:, :, 0, :] # drop the unused dimension
开发者ID:zbxzc35,项目名称:OpenDeep,代码行数:26,代码来源:conv1d_implementations.py
注:本文中的theano.tensor.nnet.conv2d函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论