本文整理汇总了Python中theano.tensor.dtensor4函数的典型用法代码示例。如果您正苦于以下问题:Python dtensor4函数的具体用法?Python dtensor4怎么用?Python dtensor4使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dtensor4函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_conv_no_bias
def test_conv_no_bias(self):
images = T.dtensor4('input_conv')
weights = T.dtensor4('weights')
images_internal = U2IConv(imshp=(12, 3, 256, 256), kshp=(12, 3, 3, 3))(images)
convOut = Conv2D(imshp=(12, 3, 256, 256), kshp=(12, 3, 3, 3), filter_flip=False)(images_internal, weights)
convOut_user = I2U()(convOut)
convOutLoss = T.mean(convOut_user)
conv_op_di = T.grad(convOutLoss, images)
conv_op_dk = T.grad(convOutLoss, weights)
convOutBack = [conv_op_di, conv_op_dk]
ival = numpy.random.rand(12, 3, 256, 256).astype(numpy.float64)
wval = numpy.random.rand(12, 3, 3, 3).astype(numpy.float64)
fopt = theano.function(inputs=[images, weights], outputs=convOutBack, mode=mode_with_mkl)
new_out = fopt(ival, wval)
convOut = conv2d(images, weights, input_shape=(12, 3, 256, 256), filter_shape=(12, 3, 3, 3), filter_flip=False)
convOutLoss = T.mean(convOut)
conv_op_di = T.grad(convOutLoss, images)
conv_op_dk = T.grad(convOutLoss, weights)
convOutBack = [conv_op_di, conv_op_dk]
fori = theano.function(inputs=[images, weights], outputs=convOutBack, mode=mode_without_mkl)
old_out = fori(ival, wval)
assert len(fopt.maker.fgraph.toposort()) != len(fori.maker.fgraph.toposort())
assert numpy.allclose(old_out[0], new_out[0])
assert new_out[0].dtype == 'float64'
开发者ID:pcs-theano,项目名称:Theano,代码行数:31,代码来源:test_conv.py
示例2: test_infer_shape
def test_infer_shape(self):
image = tensor.dtensor4()
maxout = tensor.dtensor4()
gz = tensor.dtensor4()
rng = numpy.random.RandomState(utt.fetch_seed())
maxpoolshps = ((1, 1), (2, 2), (3, 3), (2, 3), (3, 2))
image_val = rng.rand(4, 6, 7, 9)
out_shapes = [[[4, 6, 7, 9], [4, 6, 7, 9]],
[[4, 6, 3, 4], [4, 6, 4, 5]],
[[4, 6, 2, 3], [4, 6, 3, 3]],
[[4, 6, 3, 3], [4, 6, 4, 3]],
[[4, 6, 2, 4], [4, 6, 3, 5]]]
for i, maxpoolshp in enumerate(maxpoolshps):
for j, ignore_border in enumerate([True, False]):
# checking shapes generated by DownsampleFactorMax
self._compile_and_check([image],
[DownsampleFactorMax(maxpoolshp,
ignore_border=ignore_border)(image)],
[image_val], DownsampleFactorMax)
# checking shapes generated by DownsampleFactorMaxGrad
maxout_val = rng.rand(*out_shapes[i][j])
gz_val = rng.rand(*out_shapes[i][j])
self._compile_and_check([image, maxout, gz],
[DownsampleFactorMaxGrad(maxpoolshp,
ignore_border=ignore_border)(image, maxout, gz)],
[image_val, maxout_val, gz_val],
DownsampleFactorMaxGrad)
开发者ID:errord,项目名称:Theano,代码行数:31,代码来源:test_downsample.py
示例3: test_relu_grad
def test_relu_grad(self):
seed = utt.fetch_seed()
rng = numpy.random.RandomState(seed)
imgsize_list = ((5, 5), (6, 6), (6, 6), (8, 8))
n, c = 4, 2
axis = 1
image = T.dtensor4('image')
image1 = T.dtensor4('image1')
for imgsize in imgsize_list:
imval = rng.rand(n, c, imgsize[0], imgsize[1])
out = T.concatenate([image, image1], axis)
sum_ref = T.sum(out)
gx_ref = T.grad(sum_ref, [image, image1])
f_ref = theano.function([image, image1], outputs=gx_ref, mode=mode_without_mkl)
output_ref = f_ref(imval, imval)
out_mkl = self.mkl_concatenate_func(axis, image, image1)
sum_mkl = T.sum(out_mkl)
gx_mkl = T.grad(sum_mkl, [image, image1])
f_mkl = theano.function([image, image1], outputs=gx_mkl)
output_mkl = f_mkl(imval, imval)
utt.assert_allclose(output_mkl, output_ref)
开发者ID:pcs-theano,项目名称:Theano,代码行数:27,代码来源:test_concatenate.py
示例4: test_infer_shape_gradI
def test_infer_shape_gradI(self):
def rand(*shape):
r = numpy.asarray(numpy.random.rand(*shape), dtype='float64')
return r * 2 - 1
corrMM = corr.CorrMM
gradI = corr.CorrMM_gradInputs
adtens = T.dtensor4()
bdtens = T.dtensor4()
aivec_vals = [[1, 5, 6, 3], [8, 2, 7, 3], [1, 6, 9, 4],
[9, 6, 8, 5], [9, 1, 6, 8]]
bivec_vals = [[7, 5, 3, 1], [4, 2, 5, 3], [12, 6, 3, 2],
[5, 6, 1, 3], [7, 1, 3, 4]]
modes = ['valid', 'full', 'half', (1, 1), (2, 1), (1, 2), 1]
subsamples = [(1, 1), (2, 1), (1, 2)]
for aivec_val, bivec_val in zip(aivec_vals, bivec_vals):
adtens_val = rand(*aivec_val)
bdtens_val = rand(*bivec_val)
for mode in modes:
for subsample in subsamples:
# CorrMM
cdtens = corrMM(border_mode=mode, subsample=subsample)(adtens, bdtens)
f = theano.function([adtens, bdtens], cdtens)
cdtens_val = f(adtens_val, bdtens_val)
# CorrMM_gradInputs
shape = (theano.shared(aivec_val[2]), theano.shared(aivec_val[3]))
adtens_g = gradI(border_mode=mode,
subsample=subsample)(bdtens, cdtens, shape=shape)
self._compile_and_check([bdtens, cdtens],
[adtens_g],
[bdtens_val, cdtens_val], gradI,
warn=False)
开发者ID:5730279821-TA,项目名称:Theano,代码行数:34,代码来源:test_corr.py
示例5: test_conv_with_bias
def test_conv_with_bias(self):
images = T.dtensor4('inputs')
weights = T.dtensor4('weights')
bias = T.dvector('bias')
ishape = [(8, 3, 256, 256), (16, 3, 256, 256), (32, 3, 256, 256), (64, 3, 256, 256)]
wshape = [(8, 3, 3, 3), (16, 3, 3, 3), (32, 3, 3, 3), (64, 3, 3, 3)]
for i, ish in enumerate(ishape):
wsh = wshape[i]
images_internal = U2IConv(imshp=ish, kshp=wsh)(images)
convOutBias_internal = Conv2D(imshp=ish, kshp=wsh, filter_flip=False)(images_internal, weights, bias)
convOutBias_user = I2U()(convOutBias_internal)
ival = numpy.random.rand(*ish).astype(numpy.float64)
wval = numpy.random.rand(*wsh).astype(numpy.float64)
bval = numpy.random.rand(wsh[0]).astype(numpy.float64)
fopt = theano.function(inputs=[images, weights, bias], outputs=convOutBias_user, mode=mode_with_mkl)
new_old = fopt(ival, wval, bval)
convOut = conv2d(images, weights, input_shape=ish, filter_shape=wsh, filter_flip=False)
convOutBias = convOut + bias.dimshuffle('x', 0, 'x', 'x')
fori = theano.function(inputs=[images, weights, bias], outputs=convOutBias, mode=mode_without_mkl)
old_out = fori(ival, wval, bval)
assert str(fopt.maker.fgraph.toposort()) != str(fori.maker.fgraph.toposort())
assert numpy.allclose(old_out, new_old)
开发者ID:pcs-theano,项目名称:Theano,代码行数:28,代码来源:test_conv.py
示例6: test_infer_shape_gradW
def test_infer_shape_gradW(self):
if theano.config.mode == "FAST_COMPILE":
raise SkipTest("CorrMM don't work in FAST_COMPILE")
def rand(*shape):
r = numpy.asarray(numpy.random.rand(*shape), dtype="float64")
return r * 2 - 1
corrMM = corr.CorrMM
gradW = corr.CorrMM_gradWeights
adtens = T.dtensor4()
bdtens = T.dtensor4()
aivec_vals = [[1, 5, 6, 3], [8, 2, 7, 3], [1, 6, 9, 4], [9, 6, 8, 5], [9, 1, 6, 8]]
bivec_vals = [[7, 5, 3, 1], [4, 2, 5, 3], [12, 6, 3, 2], [5, 6, 1, 3], [11, 1, 3, 3]]
modes = ["valid", "full", "half", (1, 1), (2, 1), (1, 2), 1]
subsamples = [(1, 1), (2, 1), (1, 2)]
for aivec_val, bivec_val in zip(aivec_vals, bivec_vals):
adtens_val = rand(*aivec_val)
bdtens_val = rand(*bivec_val)
for mode in modes:
for subsample in subsamples:
# CorrMM
cdtens = corrMM(border_mode=mode, subsample=subsample)(adtens, bdtens)
f = theano.function([adtens, bdtens], cdtens)
cdtens_val = f(adtens_val, bdtens_val)
# CorrMM_gradWeights
shape = (theano.shared(bivec_val[2]), theano.shared(bivec_val[3]))
bdtens_g = gradW(border_mode=mode, subsample=subsample)(adtens, cdtens, shape=shape)
self._compile_and_check([adtens, cdtens], [bdtens_g], [adtens_val, cdtens_val], gradW, warn=False)
开发者ID:ChinaQuants,项目名称:Theano,代码行数:31,代码来源:test_corr.py
示例7: test_concatenate
def test_concatenate(self):
def ref(*inputs):
axis = inputs[0]
tensors = inputs[1:]
return numpy.concatenate(tensors, axis)
seed = utt.fetch_seed()
rng = numpy.random.RandomState(seed)
imgsize_list = ((5, 5), (6, 6), (6, 6), (8, 8))
n, c = 4, 2
axis = 1
image = T.dtensor4('image')
image1 = T.dtensor4('image1')
for imgsize in imgsize_list:
imval = rng.rand(n, c, imgsize[0], imgsize[1])
output_ref = ref(axis, imval, imval)
Opout = self.mkl_concatenate_func(axis, image, image1)
f = function([image, image1], [Opout, ])
output_mkl = f(imval, imval)
utt.assert_allclose(output_mkl, output_ref)
开发者ID:pcs-theano,项目名称:Theano,代码行数:27,代码来源:test_concatenate.py
示例8: test_infer_shape_forward
def test_infer_shape_forward(self):
if theano.config.mode == "FAST_COMPILE":
raise SkipTest("CorrMM don't work in FAST_COMPILE")
def rand(*shape):
r = numpy.asarray(numpy.random.rand(*shape), dtype='float64')
return r * 2 - 1
corrMM = corr.CorrMM
adtens = T.dtensor4()
bdtens = T.dtensor4()
aivec_vals = [[4, 5, 6, 3], [6, 2, 8, 3], [3, 6, 7, 5],
[3, 6, 7, 5], [5, 2, 4, 3]]
bivec_vals = [[7, 5, 3, 2], [4, 2, 5, 3], [5, 6, 3, 2],
[5, 6, 2, 3], [6, 2, 4, 3]]
modes = ['valid', 'full', 'half', (1, 1), (2, 1), (1, 2), 1]
subsamples = [(1, 1), (2, 1), (1, 2)]
for aivec_val, bivec_val in zip(aivec_vals, bivec_vals):
adtens_val = rand(*aivec_val)
bdtens_val = rand(*bivec_val)
for mode in modes:
for subsample in subsamples:
# CorrMM
cdtens = corrMM(border_mode=mode, subsample=subsample)(adtens, bdtens)
self._compile_and_check([adtens, bdtens],
[cdtens],
[adtens_val, bdtens_val], corrMM,
warn=False)
开发者ID:HHiroki,项目名称:Theano,代码行数:29,代码来源:test_corr.py
示例9: setUp
def setUp(self):
super (TestConv2D, self).setUp()
self.input = T.dtensor4('input')
self.input.name = 'default_V'
self.filters = T.dtensor4('filters')
self.filters.name = 'default_filters'
if not conv.imported_scipy_signal and theano.config.cxx == "":
raise SkipTest("conv2d tests need SciPy or a c++ compiler")
开发者ID:Donghuan,项目名称:Theano,代码行数:8,代码来源:test_conv.py
示例10: test_infer_shape
def test_infer_shape(self):
image = tensor.dtensor4()
maxout = tensor.dtensor4()
gz = tensor.dtensor4()
rng = numpy.random.RandomState(utt.fetch_seed())
maxpoolshps = ((1, 1), (2, 2), (3, 3), (2, 3), (3, 2))
image_val = rng.rand(4, 6, 7, 9)
out_shapes = [[[[4, 6, 7, 9], [4, 6, 7, 9]],
[[4, 6, 3, 4], [4, 6, 4, 5]],
[[4, 6, 2, 3], [4, 6, 3, 3]],
[[4, 6, 3, 3], [4, 6, 4, 3]],
[[4, 6, 2, 4], [4, 6, 3, 5]]],
[[None, None],
[[4, 6, 4, 5], None],
[[4, 6, 3, 3], None],
[[4, 6, 4, 3], None],
[[4, 6, 3, 5], None]],
[[None, None],
[None, None],
[[4, 6, 3, 4], None],
[[4, 6, 4, 4], None],
[None, None]]]
for i, maxpoolshp in enumerate(maxpoolshps):
for j, ignore_border in enumerate([True, False]):
for k, padding in enumerate([(0, 0), (1, 1), (1, 2)]):
if out_shapes[k][i][j] is None:
continue
# checking shapes generated by DownsampleFactorMax
self._compile_and_check([image],
[DownsampleFactorMax(maxpoolshp,
ignore_border=ignore_border,
padding=padding)(image)],
[image_val], DownsampleFactorMax)
# checking shapes generated by MaxPoolGrad
maxout_val = rng.rand(*out_shapes[k][i][j])
gz_val = rng.rand(*out_shapes[k][i][j])
self._compile_and_check([image, maxout, gz],
[MaxPoolGrad(maxpoolshp,
ignore_border=ignore_border,
padding=padding)
(image, maxout, gz)],
[image_val, maxout_val, gz_val],
MaxPoolGrad,
warn=False)
# checking with broadcastable input
image = tensor.tensor(dtype='float64',
broadcastable=(False, False, True, True))
image_val = rng.rand(4, 6, 1, 1)
self._compile_and_check(
[image],
[DownsampleFactorMax((2, 2),
ignore_border=True,
padding=(0, 0))(image)],
[image_val], DownsampleFactorMax)
开发者ID:hhoareau,项目名称:Theano,代码行数:57,代码来源:test_downsample.py
示例11: test_no_shape
def test_no_shape(self):
images = T.dtensor4('inputs')
weights = T.dtensor4('weights')
convOut = conv2d(images, weights, filter_shape=(12, 3, 3, 3), filter_flip=False)
fopt = theano.function(inputs=[images, weights], outputs=convOut, mode=mode_with_mkl)
fori = theano.function(inputs=[images, weights], outputs=convOut, mode=mode_without_mkl)
# No optimization for the case image shape is None
assert all([not isinstance(n, (Conv2D, U2IConv, I2U)) for n in fopt.maker.fgraph.toposort()])
assert str(fopt.maker.fgraph.toposort()) == str(fori.maker.fgraph.toposort())
开发者ID:pcs-theano,项目名称:Theano,代码行数:13,代码来源:test_conv.py
示例12: test_pool_stride_padding
def test_pool_stride_padding(self):
rng = numpy.random.RandomState(utt.fetch_seed())
# generate random images
ds_list = ((3, 3), (4, 4), (3, 4), (5, 5))
st_list = ((1, 1), (2, 2), (3, 3), (1, 2))
pad_list = ((1, 1), (0, 0), (1, 1), (1, 1))
imgsize_list = ((5, 5), (6, 6), (6, 6), (8, 8))
n = 4
c = 2
images = T.dtensor4()
for idx, ignore_border, mode in product(numpy.arange(len(ds_list)),
[False],
['max',
'average_exc_pad']):
imgsize = imgsize_list[idx]
imval = rng.rand(n, c, imgsize[0], imgsize[1])
ds = ds_list[idx]
st = st_list[idx]
pad = pad_list[idx]
# Pure Numpy computation
numpy_output_val = self.numpy_pool_2d_stride_padding(imval, ds,
ignore_border, st,
pad, mode)
# MKL Ops
output = self.mkl_pool_func(images, ignore_border, mode, ds, st, pad)
f = function([images, ], [output, ])
output_val = f(imval)
utt.assert_allclose(output_val, numpy_output_val)
开发者ID:intel,项目名称:theano,代码行数:33,代码来源:test_pool.py
示例13: __init__
def __init__(self, minibatch_size=128, epochs=1, learn_rate=1e-3,
bottleneck_width=10, **kwargs):
'''Initialize a ready-to-train convolutional autoencoder.'''
super(IBDPairConvAe, self).__init__(self)
# Shapes are given as (batch, depth, height, width)
nchannels = kwargs.get('nchannels', 4)
weighted = kwargs.get('weighted_cost', False)
self.minibatch_shape = (minibatch_size, nchannels, 8, 24)
self.minibatch_size = minibatch_size
self.image_shape = self.minibatch_shape[1:-1]
self.num_features = reduce(mul, self.image_shape)
self.epochs = epochs
self.learn_rate = learn_rate
self.bottleneck_width = bottleneck_width
self.input_var = T.dtensor4('input')
self.network = self._setup_network()
self.train_prediction = self._setup_prediction(deterministic=False)
self.test_prediction = self._setup_prediction(deterministic=True)
self.train_cost = self._setup_cost(deterministic=False,
weighted=weighted)
self.test_cost = self._setup_cost(deterministic=True, array=True)
self.optimizer = self._setup_optimizer()
self.train_once = theano.function([self.input_var],
[self.train_cost], updates=self.optimizer)
self.predict_fn = theano.function([self.input_var],
[self.test_cost, self.test_prediction])
开发者ID:NERSC,项目名称:dayabay-learn,代码行数:26,代码来源:LasagneConv.py
示例14: test_gauntlet
def test_gauntlet(self):
maxpoolshps = ((1, 1), (3, 3), (5, 3),)
stridesizes = ((1, 1), (3, 3), (5, 7),)
# generate random images
imval = self.rng.rand(4, 10, 16, 16)
images = T.dtensor4()
for index_type, index_scope, maxpoolshp, stride, ignore_border in product(['flattened',
'array'],
['local',
'global'],
maxpoolshps,
stridesizes,
[True, False]):
# Pool op
max_pool_op = Pool(ds=maxpoolshp,
ignore_border=ignore_border,
st=stride, mode='max')(images)
max_pool_f = theano.function([images], max_pool_op)
maxpool_output_val = max_pool_f(imval)
maxpoolswitch_op = MaxPoolSwitch(ds = maxpoolshp,
ignore_border=ignore_border,
st=stride, index_type=index_type,
index_scope=index_scope)(images)
f = theano.function([images], maxpoolswitch_op, mode='DebugMode')
output_val = f(imval)
self.check_max_and_switches(imval, output_val, maxpool_output_val,
maxpoolshp, ignore_border, stride, None,
index_type, index_scope)
开发者ID:bokorn,项目名称:Keras-and-Theano-layers-for-Switched-Pooling,代码行数:30,代码来源:test_switched_pooling.py
示例15: _make_graph
def _make_graph(self):
if not self.twod_inputs:
self._inputs = TT.dtensor4("inputs")
layer_outputs = self._inputs
else:
self._inputs = TT.matrix("inputs")
layer_outputs = self._inputs.reshape(self.img_shape)
for i in range(0, len(self.conv_weights)):
# Perform the convolution.
conv_out = conv.conv2d(layer_outputs, self.conv_weights[i],
filter_shape = self.filter_shapes[i],
image_shape = self.layer_shapes[i])
# Downsample the feature maps.
pooled_out = downsample.max_pool_2d(conv_out, self.pool_sizes[i],
ignore_border = True)
# Account for the bias. Since it is a vector, we first need to reshape it
# to (1, n_filters, 1, 1).
layer_outputs = self.activation_func(pooled_out + \
self.conv_biases[i].dimshuffle("x", 0, "x", "x"))
# Concatenate output maps into one big matrix where each row is the
# concatenation of all the feature maps from one item in the batch.
next_shape = self.layer_shapes[i + 1]
new_shape = (next_shape[0], reduce(mul, next_shape[1:], 1))
print "New Shape: " + str(new_shape)
self.x = layer_outputs.reshape(new_shape)
开发者ID:djpetti,项目名称:dec-meg-2014,代码行数:29,代码来源:weight_sharing.py
示例16: test_DownsampleFactorMax
def test_DownsampleFactorMax(self):
rng = numpy.random.RandomState(utt.fetch_seed())
# generate random images
maxpoolshps = ((1, 1), (2, 2), (3, 3), (2, 3))
imval = rng.rand(4, 2, 16, 16)
images = tensor.dtensor4()
for maxpoolshp, ignore_border, mode in product(
maxpoolshps, [True, False], ["max", "sum", "average_inc_pad", "average_exc_pad"]
):
# print 'maxpoolshp =', maxpoolshp
# print 'ignore_border =', ignore_border
# Pure Numpy computation
numpy_output_val = self.numpy_max_pool_2d(imval, maxpoolshp, ignore_border, mode=mode)
output = pool_2d(images, maxpoolshp, ignore_border, mode=mode)
f = function([images], [output])
output_val = f(imval)
utt.assert_allclose(output_val, numpy_output_val)
# Pool op
maxpool_op = Pool(maxpoolshp, ignore_border=ignore_border, mode=mode)(images)
output_shape = Pool.out_shape(imval.shape, maxpoolshp, ignore_border=ignore_border)
utt.assert_allclose(numpy.asarray(output_shape), numpy_output_val.shape)
f = function([images], maxpool_op)
output_val = f(imval)
utt.assert_allclose(output_val, numpy_output_val)
开发者ID:Tintin-C,项目名称:Theano,代码行数:27,代码来源:test_pool.py
示例17: cnn
def cnn(train_x, train_y, learning_rate=0.05, batch=100, epochs=100):
train_x = train_x.reshape(-1, 1, 100, 100)
X = T.dtensor4()
Y = T.fmatrix()
w1 = init_weights((8, 1, 3, 3))
w2 = init_weights((4, 8, 3, 3))
w = init_weights((196, 62))
b = init_bias(62)
l = model(X, w1, w2, w, b)
y_pred = T.argmax(l, axis=1)
cost = T.mean(T.nnet.categorical_crossentropy(l, Y))
params = [w1, w2, w, b]
update = sgd(cost, params, learning_rate)
train = theano.function(inputs=[X, Y], outputs=cost, updates=update, allow_input_downcast=True)
predict = theano.function(inputs=[X], outputs=y_pred, allow_input_downcast=True)
now = time.strftime("%X", time.localtime())
print "[%s] Start training" % (now)
for epoch in range(epochs):
hit = 0.0
for start, end in zip(range(0, train_x.shape[0], batch), range(batch, train_x.shape[0], batch)):
cost = train(train_x[start:end, :], train_y[start:end, :])
hit = hit + np.sum(np.argmax(train_y[start:end, :], axis=1) == predict(train_x[start:end, :]))
accuracy = hit / train_x.shape[0]
now = time.strftime("%X", time.localtime())
print "[%s] epoch %d, accuracy = %.4f" % (now, epoch + 1, accuracy)
if accuracy > 0.9950:
break
f = open("model.txt", "w")
lists1 = w1.get_value(borrow=True)
for i in lists1:
for j in i:
for k in j:
for l in k:
f.write((str)(l) + "\t")
f.write("\n")
lists2 = w2.get_value(borrow=True)
for i in lists2:
for j in i:
for k in j:
for l in k:
f.write((str)(l) + "\t")
f.write("\n")
lists3 = w.get_value(borrow=True)
for i in lists3:
for l in i:
f.write((str)(l) + "\t")
f.write("\n")
lists4 = b.get_value(borrow=True)
for i in lists4:
f.write((str)(i) + "\t")
f.write("\n")
f.close()
开发者ID:xwj95,项目名称:Airwriting,代码行数:60,代码来源:cnn.py
示例18: test_DownsampleFactorMax
def test_DownsampleFactorMax(self):
rng = numpy.random.RandomState(utt.fetch_seed())
# generate random images
maxpoolshps = ((1, 1), (2, 2), (3, 3), (2, 3))
imval = rng.rand(4, 10, 64, 64)
images = tensor.dtensor4()
for maxpoolshp in maxpoolshps:
for ignore_border in [True, False]:
#print 'maxpoolshp =', maxpoolshp
#print 'ignore_border =', ignore_border
# Pure Numpy computation
numpy_output_val = self.numpy_max_pool_2d(imval, maxpoolshp,
ignore_border)
output = max_pool_2d(images, maxpoolshp, ignore_border)
f = function([images, ], [output, ])
output_val = f(imval)
assert numpy.all(output_val == numpy_output_val)
#DownsampleFactorMax op
maxpool_op = DownsampleFactorMax(maxpoolshp,
ignore_border=ignore_border)(images)
f = function([images], maxpool_op)
output_val = f(imval)
assert (numpy.abs(output_val - numpy_output_val) < 1e-5).all()
开发者ID:errord,项目名称:Theano,代码行数:26,代码来源:test_downsample.py
示例19: test_DownsampleFactorMaxStride
def test_DownsampleFactorMaxStride(self):
rng = numpy.random.RandomState(utt.fetch_seed())
maxpoolshps = ((1, 1), (3, 3), (5, 3))
stridesizes = ((1, 1), (3, 3), (5, 7))
# generate random images
imval = rng.rand(4, 10, 16, 16)
outputshps = ((4, 10, 16, 16), (4, 10, 6, 6), (4, 10, 4, 3),
(4, 10, 16, 16), (4, 10, 6, 6), (4, 10, 4, 3),
(4, 10, 14, 14), (4, 10, 5, 5), (4, 10, 3, 2),
(4, 10, 14, 14), (4, 10, 6, 6), (4, 10, 4, 3),
(4, 10, 12, 14), (4, 10, 4, 5), (4, 10, 3, 2),
(4, 10, 12, 14), (4, 10, 5, 6), (4, 10, 4, 3))
images = tensor.dtensor4()
indx = 0
for maxpoolshp in maxpoolshps:
for ignore_border in [True, False]:
for stride in stridesizes:
outputshp = outputshps[indx]
indx += 1
#DownsampleFactorMax op
numpy_output_val = \
self.numpy_max_pool_2d_stride(imval, maxpoolshp,
ignore_border, stride)
assert numpy_output_val.shape == outputshp, (
"outshape is %s, calculated shape is %s"
% (outputshp, numpy_output_val.shape))
maxpool_op = \
DownsampleFactorMax(maxpoolshp,
ignore_border=ignore_border,
st=stride)(images)
f = function([images], maxpool_op)
output_val = f(imval)
utt.assert_allclose(output_val, numpy_output_val)
开发者ID:gyenney,项目名称:Tools,代码行数:33,代码来源:test_downsample.py
示例20: cnn
def cnn(input):
input.shape = (1, 1, 28, 28)
x = T.dtensor4('x')
classifer = CNN(input=x)
get_p_y = theano.function(inputs=[x], outputs=classifer.outputs)
pred_y = theano.function(inputs=[x], outputs=classifer.pred)
return (get_p_y(input), pred_y(input))
开发者ID:royxue,项目名称:DeepLearningModel,代码行数:7,代码来源:lenet5.py
注:本文中的theano.tensor.dtensor4函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论