本文整理汇总了Python中theano.tensor.ftensor4函数的典型用法代码示例。如果您正苦于以下问题:Python ftensor4函数的具体用法?Python ftensor4怎么用?Python ftensor4使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ftensor4函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: create_back_conv_z_plus_fn
def create_back_conv_z_plus_fn():
inputs = T.ftensor4()
weights = T.ftensor4()
out_relevances = T.ftensor4()
in_relevances = relevance_conv_z_plus(out_relevances, inputs, weights)
back_relevance_conv_fn = theano.function([out_relevances, inputs, weights], in_relevances)
return back_relevance_conv_fn
开发者ID:robintibor,项目名称:braindecode,代码行数:7,代码来源:heatmap.py
示例2: test_dnn_conv_merge
def test_dnn_conv_merge():
# This test that we merge correctly multiple dnn_conv.
if not dnn.dnn_available(test_ctx_name):
raise SkipTest(dnn.dnn_available.msg)
img_shp = [2, 5, 6, 8]
kern_shp = [3, 5, 5, 6]
img = T.ftensor4('img')
kern = T.ftensor4('kern')
out = T.ftensor4('out')
desc = dnn.GpuDnnConvDesc(
border_mode='valid')(kern.shape)
# Test forward op
o1 = dnn.dnn_conv(img, kern)
o2 = dnn.dnn_conv(img, kern)
f = theano.function([img, kern], [o1, o2], mode=mode_with_gpu)
d1, d2 = f(numpy.random.rand(*img_shp).astype('float32'),
numpy.random.rand(*kern_shp).astype('float32'))
topo = f.maker.fgraph.toposort()
assert len([n for n in topo if isinstance(n.op, dnn.GpuDnnConv)]) == 1
# Test grad w op
o1 = dnn.GpuDnnConvGradW()(img, kern, out, desc)
o2 = dnn.GpuDnnConvGradW()(img, kern, out, desc)
f = theano.function([img, kern, out], [o1, o2], mode=mode_with_gpu)
topo = f.maker.fgraph.toposort()
assert len([n for n in topo if isinstance(n.op, dnn.GpuDnnConvGradW)]) == 1
# Test grad i op
o1 = dnn.GpuDnnConvGradI()(img, kern, out, desc)
o2 = dnn.GpuDnnConvGradI()(img, kern, out, desc)
f = theano.function([img, kern, out], [o1, o2], mode=mode_with_gpu)
topo = f.maker.fgraph.toposort()
assert len([n for n in topo if isinstance(n.op, dnn.GpuDnnConvGradI)]) == 1
开发者ID:nke001,项目名称:Theano,代码行数:34,代码来源:test_dnn.py
示例3: test_grad_types
def test_grad_types(self):
# This function simply tests the behaviour of the AbstractConv
# Ops, not their optimizations
cpu_input = tensor.ftensor4()
cpu_filters = tensor.ftensor4()
cpu_topgrad = tensor.ftensor4()
gpu_input = gpu_ftensor4()
gpu_filters = gpu_ftensor4()
gpu_topgrad = gpu_ftensor4()
out_shape = tensor.lvector()
# Check the gradient of the forward conv2d
for input, filters in itertools.product((cpu_input, gpu_input), (cpu_filters, gpu_filters)):
output = conv.conv2d(input, filters)
grad_input, grad_filters = theano.grad(output.sum(), wrt=(input, filters))
assert grad_input.type == input.type, (grad_input, grad_input.type, input, input.type)
assert grad_filters.type == filters.type, (grad_filters, grad_filters.type, filters, filters.type)
# Check the gradient of gradweight
for input, topgrad in itertools.product((cpu_input, gpu_input), (cpu_topgrad, gpu_topgrad)):
grad_filters = conv.AbstractConv2d_gradWeights()(input, topgrad, out_shape)
grad_input, grad_topgrad = theano.grad(grad_filters.sum(), wrt=(input, topgrad))
assert grad_input.type == input.type, (grad_input, grad_input.type, input, input.type)
assert grad_topgrad.type == topgrad.type, (grad_topgrad, grad_topgrad.type, topgrad, topgrad.type)
# Check the gradient of gradinputs
for filters, topgrad in itertools.product((cpu_filters, gpu_filters), (cpu_topgrad, gpu_topgrad)):
grad_input = conv.AbstractConv2d_gradInputs()(filters, topgrad, out_shape)
grad_filters, grad_topgrad = theano.grad(grad_input.sum(), wrt=(filters, topgrad))
assert grad_filters.type == filters.type, (grad_filters, grad_filters.type, filters, filters.type)
assert grad_topgrad.type == topgrad.type, (grad_topgrad, grad_topgrad.type, topgrad, topgrad.type)
开发者ID:emillynge,项目名称:Theano,代码行数:34,代码来源:test_abstractconv.py
示例4: test_conv
def test_conv(self):
img = T.ftensor4('img')
kerns = T.ftensor4('kerns')
img_val = numpy.asarray(
numpy.random.rand(3, 4, 5, 6),
dtype='float32'
)
kern_vals = numpy.asarray(
numpy.random.rand(3, 4, 5, 6),
dtype='float32'
)
for params in product(
['valid', 'full'],
[(1, 1), (2, 2)],
['conv', 'cross']
):
desc = dnn.GpuDnnConvDesc(
border_mode=params[0],
subsample=params[1],
conv_mode=params[2]
)(img.shape, kerns.shape)
conv = dnn.GpuDnnConv()(img_val, kern_vals, desc)
self._compile_and_check(
[img, kerns],
[conv],
[img_val, kern_vals],
dnn.GpuDnnConv
)
开发者ID:gotomypc,项目名称:Theano,代码行数:29,代码来源:test_dnn.py
示例5: test_conv_gradw
def test_conv_gradw(self):
if not dnn.dnn_available():
raise SkipTest(dnn.dnn_available.msg)
img = T.ftensor4("img")
kerns = T.ftensor4("kerns")
out = T.ftensor4("out")
img_val = numpy.asarray(numpy.random.rand(2, 5, 6, 8), dtype="float32")
kern_vals = numpy.asarray(numpy.random.rand(2, 1, 5, 6), dtype="float32")
out_vals = numpy.zeros((3, 3, 1, 1), dtype="float32")
for params in product(["valid", "full"], [(1, 1)], ["conv", "cross"]): # strides besides (1, 1)
temp_img = img.dimshuffle(1, 0, 2, 3)
temp_kerns = kerns
if params[2] == "conv":
temp_kerns = temp_kerns[:, :, ::-1, ::-1]
temp_kerns = temp_kerns.dimshuffle(1, 0, 2, 3)
shape = (
kern_vals.shape[1],
img_val.shape[1],
img_val.shape[2] - kern_vals.shape[2] + 1,
img_val.shape[3] - kern_vals.shape[3] + 1,
)
out_vals = numpy.zeros(shape, dtype="float32")
desc = dnn.GpuDnnConvDesc(border_mode=params[0], subsample=params[1], conv_mode=params[2])(
temp_img.shape, out.shape
)
conv_grad_w = dnn.GpuDnnConvGradW()(temp_img, temp_kerns, out, desc)
self._compile_and_check(
[temp_img, temp_kerns, out], [conv_grad_w], [img_val, kern_vals, out_vals], dnn.GpuDnnConvGradW
)
开发者ID:dapeng2018,项目名称:Theano,代码行数:30,代码来源:test_dnn.py
示例6: test_upsample_pool
def test_upsample_pool():
pool_size = (1,2)
pool_stride = (1,2)
out = T.ftensor4()
inputs = T.ftensor4()
actual_in = upsample_pool(out, inputs, pool_size, pool_stride)
upsample_pool_fn = theano.function([out, inputs], actual_in)
# needs pool size, stride= 1,2
output = np.float32([[[[5,4,1]]]])
inputs = np.float32([[[[3,0,8,4,5,6]]]])
upsampled = upsample_pool_fn(output, inputs)
assert np.allclose([[[[ 5., 0., 4., 0., 0., 1.]]]],
upsampled)
# Test for pooling across several channels
pool_size = (1,2)
pool_stride = (1,2)
out = T.ftensor4()
inputs = T.ftensor4()
actual_in = upsample_pool(out, inputs, pool_size, pool_stride)
upsample_pool_fn = theano.function([out, inputs], actual_in)
# needs pool size, stride= 1,2
output = np.float32([[[[-3,5,2]],[[5,4,1]]]])
inputs = np.float32([[[[2,1,3,4,1,-7]], [[3,0,8,4,5,6]]]])
upsampled = upsample_pool_fn(output, inputs)
assert np.allclose([[[[ -3., 0., 0., 5., 2., 0.]],
[[ 5., 0., 4., 0., 0., 1.]]]],
upsampled)
开发者ID:robintibor,项目名称:braindecode,代码行数:30,代码来源:test_patterns.py
示例7: test_conv_gradi
def test_conv_gradi(self):
if not dnn.dnn_available():
raise SkipTest(dnn.dnn_available.msg)
img = T.ftensor4("img")
kerns = T.ftensor4("kerns")
out = T.ftensor4("out")
img_val = numpy.asarray(numpy.random.rand(3, 4, 5, 6), dtype="float32")
kern_vals = numpy.asarray(numpy.random.rand(3, 4, 5, 6), dtype="float32")
for params in product(["valid"], [(1, 1)], ["conv", "cross"]): # Should this work for 'full'?
temp_kerns = kerns.dimshuffle(1, 0, 2, 3)
shape = (
img_val.shape[0],
kern_vals.shape[1],
img_val.shape[2] + kern_vals.shape[2] - 1,
img_val.shape[3] + kern_vals.shape[3] - 1,
)
out_vals = numpy.zeros(shape, dtype="float32")
desc = dnn.GpuDnnConvDesc(border_mode=params[0], subsample=params[1], conv_mode=params[2])(
out.shape, temp_kerns.shape
)
conv_grad_i = dnn.GpuDnnConvGradI()(temp_kerns, img, out, desc)
self._compile_and_check(
[temp_kerns, img, out], [conv_grad_i], [kern_vals, img_val, out_vals], dnn.GpuDnnConvGradI
)
开发者ID:dapeng2018,项目名称:Theano,代码行数:25,代码来源:test_dnn.py
示例8: test_logical_shapes
def test_logical_shapes(self):
seed_rng()
for stride in range(1, 4):
kshp = (10, 2, 10, 10)
featshp = (3, 10, 11, 11)
a = tensor.ftensor4()
A = tensor.ftensor4()
# Need to transpose first two dimensions of kernel, and reverse
# index kernel image dims (for correlation)
kernel_rotated = tensor.transpose(A, 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])
#print featshp, kshp_rotated, featshp_logical[1:], kshp[2:]
image_estimate = tensor.nnet.conv2d(a, kernel_rotated,
border_mode='full',
image_shape=featshp,
filter_shape=kshp_rotated,
imshp_logical=featshp_logical[1:],
kshp_logical=kshp[2:])
func = theano.function([a, A], image_estimate, mode=theano_mode)
#theano.printing.debugprint(func,)
assert any([isinstance(node.op, theano.sandbox.cuda.blas.GpuConv)
for node in func.maker.fgraph.toposort()])
a_in = numpy.random.randn(*featshp).astype("float32")
A_in = numpy.random.randn(*kshp).astype("float32")
func(a_in, A_in)
开发者ID:JoeGlobal2014,项目名称:Theano,代码行数:33,代码来源:test_conv_cuda_ndarray.py
示例9: create_back_conv_z_b_fn
def create_back_conv_z_b_fn(min_in, max_in):
inputs = T.ftensor4()
weights = T.ftensor4()
out_relevances = T.ftensor4()
in_relevances = relevance_conv_z_b(out_relevances, inputs, weights, min_in, max_in)
back_relevance_conv_fn = theano.function([out_relevances, inputs, weights], in_relevances)
return back_relevance_conv_fn
开发者ID:robintibor,项目名称:braindecode,代码行数:7,代码来源:heatmap.py
示例10: test_dnn_conv_merge
def test_dnn_conv_merge():
if not cuda.dnn.dnn_available():
raise SkipTest(cuda.dnn.dnn_available.msg)
img = T.ftensor4()
kern = T.ftensor4()
out = T.ftensor4()
b = 1
c = 4
f = 3
ih = 5
iw = 8
kh = 2
kw = 6
img_val = numpy.random.random((b, c, ih, iw)).astype("float32")
kern_val = numpy.random.random((f, c, kh, kw)).astype("float32")
out_val = numpy.random.random((b, f, ih - kh + 1, iw - kw + 1)).astype("float32")
conv = dnn.dnn_conv(img, kern)
gw = theano.grad(conv.sum(), kern)
gi = theano.grad(conv.sum(), img)
lr = numpy.asarray(0.05, dtype="float32")
if cuda.dnn.version() == -1:
# Can't merge alpha with cudnn v1
fr = conv + out
wr = kern + gw
ir = img + gi
else:
fr = lr * (conv + out)
wr = kern + lr * gw
ir = img + lr * gi
f1 = theano.function([img, kern, out], [fr, wr, ir], mode=mode_with_gpu)
assert isinstance(f1.maker.fgraph.outputs[0].owner.inputs[0].owner.op, dnn.GpuDnnConv)
assert isinstance(f1.maker.fgraph.outputs[1].owner.inputs[0].owner.op, dnn.GpuDnnConvGradW)
assert isinstance(f1.maker.fgraph.outputs[2].owner.inputs[0].owner.op, dnn.GpuDnnConvGradI)
mode = mode_with_gpu
mode = mode.excluding("local_dnn_conv_alpha_merge")
mode = mode.excluding("local_dnn_convw_alpha_merge")
mode = mode.excluding("local_dnn_convi_alpha_merge")
mode = mode.excluding("local_dnn_conv_output_merge")
mode = mode.excluding("local_dnn_convw_output_merge")
mode = mode.excluding("local_dnn_convi_output_merge")
f2 = theano.function([img, kern, out], [fr, wr, ir], mode=mode)
assert not isinstance(f2.maker.fgraph.outputs[0].owner.inputs[0].owner.op, dnn.GpuDnnConv)
assert not isinstance(f2.maker.fgraph.outputs[1].owner.inputs[0].owner.op, dnn.GpuDnnConvGradW)
assert not isinstance(f2.maker.fgraph.outputs[2].owner.inputs[0].owner.op, dnn.GpuDnnConvGradI)
out_f1 = f1(img_val, kern_val, out_val)
out_f2 = f2(img_val, kern_val, out_val)
assert len(out_f1) == len(out_f2)
for v1, v2 in zip(out_f1, out_f2):
utt.assert_allclose(v1, v2)
开发者ID:dapeng2018,项目名称:Theano,代码行数:60,代码来源:test_dnn.py
示例11: test_infer_shape
def test_infer_shape(self):
shape = (100, 40, 6, 3)
images = numpy.ones(shape).astype('float32')
x = T.ftensor4()
f = self._compile_and_check([x],
[images2neibs(
x, neib_shape=(2, 1),
mode='valid')],
[images],
Images2Neibs
)
f = self._compile_and_check([x],
[images2neibs(
x, neib_shape=(2, 3),
mode='valid')],
[images],
Images2Neibs
)
shape = (100, 40, 5, 4)
images = numpy.ones(shape).astype('float32')
x = T.ftensor4()
f = self._compile_and_check([x],
[images2neibs(
x, neib_shape=(2, 1),
mode='ignore_borders')],
[images],
Images2Neibs
)
shape = (100, 40, 5, 3)
images = numpy.ones(shape).astype('float32')
x = T.ftensor4()
f = self._compile_and_check([x],
[images2neibs(
x, neib_shape=(2, 3),
mode='ignore_borders')],
[images],
Images2Neibs
)
shape = (100, 40, 6, 7)
images = numpy.ones(shape).astype('float32')
x = T.ftensor4()
f = self._compile_and_check([x],
[images2neibs(
x, neib_shape=(2, 2),
mode='ignore_borders')],
[images],
Images2Neibs
)
shape = (100, 40, 5, 10)
images = numpy.ones(shape).astype('float32')
x = T.ftensor4()
f = self._compile_and_check([x],
[images2neibs(
x, neib_shape=(3, 3),
mode='wrap_centered')],
[images],
Images2Neibs
)
开发者ID:12190143,项目名称:Theano,代码行数:59,代码来源:test_neighbours.py
示例12: test_conv_gradw
def test_conv_gradw(self, border_mode, conv_mode):
self._test_conv_gradw(T.ftensor4('img'),
T.ftensor4('kerns'),
T.ftensor4('out'),
numpy.random.rand(2, 5, 6, 8),
numpy.random.rand(2, 1, 5, 6),
border_mode,
conv_mode,
(1, 1))
开发者ID:nke001,项目名称:Theano,代码行数:9,代码来源:test_dnn.py
示例13: test_dnn_conv_border_mode
def test_dnn_conv_border_mode():
if not cuda.dnn.dnn_available():
raise SkipTest(cuda.dnn.dnn_available.msg)
img = T.ftensor4()
kern = T.ftensor4()
dnn.dnn_conv(img, kern, border_mode=1)
dnn.dnn_conv(img, kern, border_mode=(2, 3))
dnn.dnn_conv(img, kern, border_mode='full')
dnn.dnn_conv(img, kern, border_mode='valid')
开发者ID:ChienliMa,项目名称:Theano,代码行数:10,代码来源:test_dnn.py
示例14: test_dnn_conv_border_mode
def test_dnn_conv_border_mode():
if not dnn.dnn_available(test_ctx_name):
raise SkipTest(dnn.dnn_available.msg)
img = T.ftensor4()
kern = T.ftensor4()
dnn.dnn_conv(img, kern, border_mode=1)
dnn.dnn_conv(img, kern, border_mode=(2, 3))
dnn.dnn_conv(img, kern, border_mode="full")
dnn.dnn_conv(img, kern, border_mode="valid")
开发者ID:huamichaelchen,项目名称:Theano,代码行数:10,代码来源:test_dnn.py
示例15: test_local_lift_abstractconv_gpu_shape
def test_local_lift_abstractconv_gpu_shape():
prev = theano.config.on_opt_error
try:
theano.config.on_opt_error = "raise"
s = tensor.ivector()
a = tensor.ftensor4()
b = tensor.ftensor4()
c = tensor.nnet.abstract_conv.AbstractConv2d_gradWeights()(a, b, s)
theano.function([s, a, b], c, mode=mode_with_gpu)
finally:
theano.config.on_opt_error = prev
开发者ID:ip01,项目名称:Theano,代码行数:11,代码来源:test_opt.py
示例16: test_conv_no_bias
def test_conv_no_bias(self):
images = T.ftensor4('inputs')
weights = T.ftensor4('weights')
convOut = conv2d(images, weights, input_shape=(12, 3, 256, 256), filter_shape=(12, 3, 3, 3), filter_flip=False)
theano.printing.pydotprint(convOut, outfile="Conv_before_opt.png", var_with_name_simple=True)
fopt = theano.function(inputs=[images, weights], outputs=convOut, mode=mode_with_mkl)
theano.printing.pydotprint(fopt, outfile="Conv_OPT_after_opt.png", var_with_name_simple=True)
fori = theano.function(inputs=[images, weights], outputs=convOut, mode=mode_without_mkl)
theano.printing.pydotprint(fori, outfile="Conv_Original_after_opt.png", var_with_name_simple=True)
开发者ID:intel,项目名称:theano,代码行数:11,代码来源:gen_conv_graph.py
示例17: setup
def setup(self, bottom, top):
if len(bottom) != 2:
raise Exception("The layer needs two inputs!")
probs = T.ftensor4()
labels = T.ftensor4()
count = T.sum(labels, axis=(1, 2, 3), keepdims=True)
loss_balanced = -T.mean(T.sum(labels * T.log(probs), axis=(1, 2, 3), keepdims=True) / count)
self.forward_theano = theano.function([probs, labels], loss_balanced)
self.backward_theano = theano.function([probs, labels], T.grad(loss_balanced, probs))
开发者ID:kolesman,项目名称:SEC,代码行数:12,代码来源:pylayers.py
示例18: test_conv
def test_conv(self, algo, border_mode, conv_mode):
if algo == 'winograd' and dnn.version(raises=False) < 5000:
raise SkipTest(dnn.dnn_available.msg)
self._test_conv(T.ftensor4('img'),
T.ftensor4('kerns'),
T.ftensor4('out'),
numpy.random.rand(7, 2, 8, 4),
numpy.random.rand(8, 2, 4, 3),
border_mode,
conv_mode,
[(1, 1), (2, 2)],
algo)
开发者ID:nke001,项目名称:Theano,代码行数:13,代码来源:test_dnn.py
示例19: test_local_abstractconv_gemm
def test_local_abstractconv_gemm():
""" We test it here as this is the optimization only that we test.
This test gh-4036"""
image = tensor.ftensor4()
W = tensor.ftensor4()
conv = tensor.nnet.conv2d(image,
W,
input_shape=(1, 32, 32, 32),
filter_shape=(32, 32, 3, 3),
border_mode='half')
f = theano.function([image, W], [conv], mode=mode_with_gpu)
f(numpy.random.rand(1, 32, 32, 32).astype('float32'),
numpy.random.rand(32, 32, 3, 3).astype('float32'))
开发者ID:Abioy,项目名称:Theano,代码行数:13,代码来源:test_opt.py
示例20: test_tensor4_roc_auc_scores
def test_tensor4_roc_auc_scores():
true = np.random.binomial(n=1, p=.5, size=(20, 30, 40, 50)).astype('float32')
predicted = np.random.random((20, 30, 40, 50)).astype('float32')
yt, yp = T.ftensor4('yt'), T.ftensor4('yp')
refscore = tmetrics.classification.last_axis_roc_auc_scores(true, predicted)
roc_auc_scores = tmetrics.classification.roc_auc_scores(yt, yp)
f = theano.function([yt, yp], roc_auc_scores)
score = f(true, predicted)
print 'refscore'
print refscore
print 'score'
print score
assert np.allclose(refscore, score, equal_nan=True)
开发者ID:jonathanstrong,项目名称:tmetrics,代码行数:13,代码来源:tmetrics_tests.py
注:本文中的theano.tensor.ftensor4函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论