当前位置: 首页>>代码示例>>Python>>正文


Python tensor.tensor3方法代码示例

本文整理汇总了Python中theano.tensor.tensor3方法的典型用法代码示例。如果您正苦于以下问题:Python tensor.tensor3方法的具体用法?Python tensor.tensor3怎么用?Python tensor.tensor3使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在theano.tensor的用法示例。


在下文中一共展示了tensor.tensor3方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: build_encoder_bi

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import tensor3 [as 别名]
def build_encoder_bi(tparams, options):
	"""
	build bidirectional encoder, given pre-computed word embeddings
	"""
	# word embedding (source)
	embedding = tensor.tensor3('embedding', dtype='float32')
	embeddingr = embedding[::-1]
	x_mask = tensor.matrix('x_mask', dtype='float32')
	xr_mask = x_mask[::-1]

	# encoder
	proj = get_layer(options['encoder'])[1](tparams, embedding, options,
											prefix='encoder',
											mask=x_mask)
	projr = get_layer(options['encoder'])[1](tparams, embeddingr, options,
											 prefix='encoder_r',
											 mask=xr_mask)

	ctx = tensor.concatenate([proj[0][-1], projr[0][-1]], axis=1)

	return embedding, x_mask, ctx


# some utilities 
开发者ID:hanzhanggit,项目名称:StackGAN,代码行数:26,代码来源:skipthoughts.py

示例2: __init__

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import tensor3 [as 别名]
def __init__(self, input_dim, output_dim,
                 init='glorot_uniform', inner_init='orthogonal', activation='sigmoid', weights=None,
                 truncate_gradient=-1, return_sequences=False):

        super(SimpleRNN, self).__init__()
        self.init = initializations.get(init)
        self.inner_init = initializations.get(inner_init)
        self.input_dim = input_dim
        self.output_dim = output_dim
        self.truncate_gradient = truncate_gradient
        self.activation = activations.get(activation)
        self.return_sequences = return_sequences
        self.input = T.tensor3()

        self.W = self.init((self.input_dim, self.output_dim))
        self.U = self.inner_init((self.output_dim, self.output_dim))
        self.b = shared_zeros((self.output_dim))
        self.params = [self.W, self.U, self.b]

        if weights is not None:
            self.set_weights(weights) 
开发者ID:lllcho,项目名称:CAPTCHA-breaking,代码行数:23,代码来源:recurrent.py

示例3: test_shape

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import tensor3 [as 别名]
def test_shape():
    input_var = T.tensor3('input')
    target_var = T.imatrix('target')
    output_var, _, _ = memory_augmented_neural_network(
        input_var, target_var,
        batch_size=16,
        nb_class=5,
        memory_shape=(128, 40),
        controller_size=200,
        input_size=20 * 20,
        nb_reads=4)

    posterior_fn = theano.function([input_var, target_var], output_var)

    test_input = np.random.rand(16, 50, 20 * 20)
    test_target = np.random.randint(5, size=(16, 50)).astype('int32')
    test_input_invalid_batch_size = np.random.rand(16 + 1, 50, 20 * 20)
    test_input_invalid_depth = np.random.rand(16, 50, 20 * 20 - 1)
    test_output = posterior_fn(test_input, test_target)

    assert test_output.shape == (16, 50, 5)
    with pytest.raises(ValueError) as e_info:
        posterior_fn(test_input_invalid_batch_size, test_target)
    with pytest.raises(ValueError) as e_info:
        posterior_fn(test_input_invalid_depth, test_target) 
开发者ID:tristandeleu,项目名称:ntm-one-shot,代码行数:27,代码来源:test_model.py

示例4: test_perform

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import tensor3 [as 别名]
def test_perform(self):
        x = tensor.matrix()
        y = tensor.scalar()
        f = function([x, y], fill_diagonal(x, y))
        for shp in [(8, 8), (5, 8), (8, 5)]:
            a = numpy.random.rand(*shp).astype(config.floatX)
            val = numpy.cast[config.floatX](numpy.random.rand())
            out = f(a, val)
            # We can't use numpy.fill_diagonal as it is bugged.
            assert numpy.allclose(numpy.diag(out), val)
            assert (out == val).sum() == min(a.shape)

        # test for 3d tensor
        a = numpy.random.rand(3, 3, 3).astype(config.floatX)
        x = tensor.tensor3()
        y = tensor.scalar()
        f = function([x, y], fill_diagonal(x, y))
        val = numpy.cast[config.floatX](numpy.random.rand() + 10)
        out = f(a, val)
        # We can't use numpy.fill_diagonal as it is bugged.
        assert out[0, 0, 0] == val
        assert out[1, 1, 1] == val
        assert out[2, 2, 2] == val
        assert (out == val).sum() == min(a.shape) 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:26,代码来源:test_extra_ops.py

示例5: setUp

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import tensor3 [as 别名]
def setUp(self):
        super(Test_local_elemwise_alloc, self).setUp()
        self.fast_run_mode = mode_with_gpu

        # self.vec = tensor.vector('vec', dtype=dtype)
        # self.mat = tensor.matrix('mat', dtype=dtype)
        # self.tens = tensor.tensor3('tens', dtype=dtype)

        # self.alloc_wo_dep = basic_ops.gpu_alloc(self.vec, 2, 2)
        # self.alloc_w_dep = basic_ops.gpu_alloc(self.vec, *self.mat.shape)

        self.alloc_wo_dep = basic_ops.gpu_alloc(self.vec, 2, 2)
        self.alloc_w_dep = basic_ops.gpu_alloc(self.vec, *self.mat.shape)
        self.alloc_w_dep_tens = basic_ops.gpu_alloc(
            self.vec,
            self.tens.shape[0],
            self.tens.shape[1]
        )
        self.tv_wo_dep = basic_ops.gpu_alloc(self.vec, 5, 5)
        self.tm_wo_dep = basic_ops.gpu_alloc(self.mat, 5, 5, 5)
        self.s = tensor.iscalar('s')
        self.tv_w_dep = basic_ops.gpu_alloc(self.vec, self.s, self.s)
        self.tm_w_dep = basic_ops.gpu_alloc(self.mat, 5, 5, 5)
        self.row = tensor.row(dtype=self.dtype)
        self.o = basic_ops.gpu_alloc(self.row, 5, 5) 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:27,代码来源:test_opt.py

示例6: test_correct_answer

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import tensor3 [as 别名]
def test_correct_answer(self):
        a = T.matrix()
        b = T.matrix()

        x = T.tensor3()
        y = T.tensor3()

        A = numpy.cast[theano.config.floatX](numpy.random.rand(5, 3))
        B = numpy.cast[theano.config.floatX](numpy.random.rand(7, 2))
        X = numpy.cast[theano.config.floatX](numpy.random.rand(5, 6, 1))
        Y = numpy.cast[theano.config.floatX](numpy.random.rand(1, 9, 3))

        make_list((3., 4.))
        c = make_list((a, b))
        z = make_list((x, y))
        fc = theano.function([a, b], c)
        fz = theano.function([x, y], z)
        self.assertTrue((m == n).all() for m, n in zip(fc(A, B), [A, B]))
        self.assertTrue((m == n).all() for m, n in zip(fz(X, Y), [X, Y])) 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:21,代码来源:test_basic.py

示例7: testConv1DLayer

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import tensor3 [as 别名]
def testConv1DLayer():

    rng = numpy.random.RandomState()

    input = T.tensor3('input')

    #windowSize = 3
    n_in = 4
    n_hiddens = [10,10,5]
    #convR = Conv1DR(rng, input, n_in, n_hiddens, windowSize/2)
    convLayer = Conv1DLayer(rng, input, n_in, 5, halfWinSize=1)
    
    #f = theano.function([input],convR.output)    
    #f = theano.function([input],[convLayer.output, convLayer.out2, convLayer.convout, convLayer.out3])    
    f = theano.function([input], convLayer.output)    

    numOfProfiles=6
    seqLen = 10
    profile = numpy.random.uniform(0,1, (numOfProfiles, seqLen,n_in))
    
    out = f(profile)
    print out.shape
    print out 
开发者ID:j3xugit,项目名称:RaptorX-Contact,代码行数:25,代码来源:Conv1d.py

示例8: TestMidpointFeature

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import tensor3 [as 别名]
def TestMidpointFeature():
    x = T.tensor3('x')
    y = MidpointFeature(x)
    f= theano.function([x], y)
    a = np.random.uniform(0, 1, (3, 10, 2)).astype(theano.config.floatX)
    b,c  = f(a)
    print c
    #return
    print '**********0*********'
    print a[0]
    print b[0][0]
    print '********4*******'
    print a[0]
    print b[0][4]
    print '**********9******'
    print a[0]
    print b[0][9] 
开发者ID:j3xugit,项目名称:RaptorX-Contact,代码行数:19,代码来源:utils.py

示例9: Compatible

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import tensor3 [as 别名]
def Compatible(list1, list2):
    if len(list1) != len(list2):
	return False

    for l1, l2 in zip(list1, list2):
	if type(l1.get_value()) != type(l2):
		return False

	if np.isscalar(l1.get_value()):
	    continue

	if l1.get_value().shape != l2.shape:
	    return False

    return True

##generate the tile of a small tensor x, the first 2 dims will be expanded
## x is a small matrix or tensor3 to be tiled, y is a tuple of 2 elements
## This function generates a tile of x by copying it y*y times
## The resultant matrix shall have dimension ( x.shape[0]*y, x.shape[1]*y), consisting of y*y copies of x 
开发者ID:j3xugit,项目名称:RaptorX-Contact,代码行数:22,代码来源:utils.py

示例10: __init__

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import tensor3 [as 别名]
def __init__(self, activation, dims=None, **kwargs):
        super(SpeechBottom, self).__init__(**kwargs)
        self.num_features = self.input_dims['recordings']

        if activation is None:
            activation = Tanh()

        if dims:
            child = MLP([activation] * len(dims),
                        [self.num_features] + dims,
                        name="bottom")
            self.output_dim = child.output_dim
        else:
            child = Identity(name='bottom')
            self.output_dim = self.num_features
        self.children.append(child)

        self.mask = tensor.matrix('recordings_mask')
        self.batch_inputs = {
            'recordings': tensor.tensor3('recordings')}
        self.single_inputs = {
            'recordings': tensor.matrix('recordings')} 
开发者ID:rizar,项目名称:attention-lvcsr,代码行数:24,代码来源:recognizer.py

示例11: test

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import tensor3 [as 别名]
def test(self):
        X = tensor.tensor3('X')
        out, H2, out_2, H = self.recurrent_example.apply(
            inputs=X, mask=None)

        x_val = numpy.ones((5, 1, 1), dtype=theano.config.floatX)

        h = H.eval({X: x_val})
        h2 = H2.eval({X: x_val})

        out_eval = out.eval({X: x_val})
        out_2_eval = out_2.eval({X: x_val})

        # This also implicitly tests that the initial states are zeros
        assert_allclose(h, x_val.cumsum(axis=0))
        assert_allclose(h2, .5 * (numpy.arange(5).reshape((5, 1, 1)) + 1))
        assert_allclose(h * 10, out_eval)
        assert_allclose(h2 * 10, out_2_eval) 
开发者ID:rizar,项目名称:attention-lvcsr,代码行数:20,代码来源:test_recurrent.py

示例12: test_saved_inner_graph

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import tensor3 [as 别名]
def test_saved_inner_graph():
    """Make sure that the original inner graph is saved."""
    x = tensor.tensor3()
    recurrent = SimpleRecurrent(dim=3, activation=Tanh())
    y = recurrent.apply(x)

    application_call = get_application_call(y)
    assert application_call.inner_inputs
    assert application_call.inner_outputs

    cg = ComputationGraph(application_call.inner_outputs)
    # Check that the inner scan graph is annotated
    # with `recurrent.apply`
    assert len(VariableFilter(applications=[recurrent.apply])(cg)) == 3
    # Check that the inner graph is equivalent to the one
    # produced by a stand-alone of `recurrent.apply`
    assert is_same_graph(application_call.inner_outputs[0],
                         recurrent.apply(*application_call.inner_inputs,
                                         iterate=False)) 
开发者ID:rizar,项目名称:attention-lvcsr,代码行数:21,代码来源:test_recurrent.py

示例13: test_super_in_recurrent_overrider

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import tensor3 [as 别名]
def test_super_in_recurrent_overrider():
    # A regression test for the issue #475
    class SimpleRecurrentWithContext(SimpleRecurrent):
        @application(contexts=['context'])
        def apply(self, context, *args, **kwargs):
            kwargs['inputs'] += context
            return super(SimpleRecurrentWithContext, self).apply(*args,
                                                                 **kwargs)

        @apply.delegate
        def apply_delegate(self):
            return super(SimpleRecurrentWithContext, self).apply

    brick = SimpleRecurrentWithContext(100, Tanh())
    inputs = tensor.tensor3('inputs')
    context = tensor.matrix('context').dimshuffle('x', 0, 1)
    brick.apply(context, inputs=inputs) 
开发者ID:rizar,项目名称:attention-lvcsr,代码行数:19,代码来源:test_recurrent.py

示例14: build_model

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import tensor3 [as 别名]
def build_model(tparams, options):
	alphaHiddenDimSize = options['alphaHiddenDimSize']
	betaHiddenDimSize = options['betaHiddenDimSize']

	x = T.tensor3('x', dtype=config.floatX)

	reverse_emb_t = x[::-1]
	reverse_h_a = gru_layer(tparams, reverse_emb_t, 'a', alphaHiddenDimSize)[::-1] * 0.5
	reverse_h_b = gru_layer(tparams, reverse_emb_t, 'b', betaHiddenDimSize)[::-1] * 0.5

	preAlpha = T.dot(reverse_h_a, tparams['w_alpha']) + tparams['b_alpha']
	preAlpha = preAlpha.reshape((preAlpha.shape[0], preAlpha.shape[1]))
	alpha = (T.nnet.softmax(preAlpha.T)).T

	beta = T.tanh(T.dot(reverse_h_b, tparams['W_beta']) + tparams['b_beta'])
	
	return x, alpha, beta 
开发者ID:mp2893,项目名称:retain,代码行数:19,代码来源:test_retain.py

示例15: build_encoder

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import tensor3 [as 别名]
def build_encoder(tparams, options):
	"""
	build an encoder, given pre-computed word embeddings
	"""
	# word embedding (source)
	embedding = tensor.tensor3('embedding', dtype='float32')
	x_mask = tensor.matrix('x_mask', dtype='float32')

	# encoder
	proj = get_layer(options['encoder'])[1](tparams, embedding, options,
											prefix='encoder',
											mask=x_mask)
	ctx = proj[0][-1]

	return embedding, x_mask, ctx 
开发者ID:hanzhanggit,项目名称:StackGAN,代码行数:17,代码来源:skipthoughts.py


注:本文中的theano.tensor.tensor3方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。