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


Python basic.as_tensor_variable函数代码示例

本文整理汇总了Python中theano.tensor.basic.as_tensor_variable函数的典型用法代码示例。如果您正苦于以下问题:Python as_tensor_variable函数的具体用法?Python as_tensor_variable怎么用?Python as_tensor_variable使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: make_node

    def make_node(self, inp, out_grad, ws, stride=None, pad=None):
        ctx_name = infer_context_name(inp, out_grad)
        nd = self.ndim
        inp = as_gpuarray_variable(inp, ctx_name)
        assert (inp.ndim == nd + 2)
        out_grad = as_gpuarray_variable(out_grad, ctx_name)
        assert (out_grad.ndim == nd + 2)

        assert (out_grad.ndim == inp.ndim)

        if stride is None:
            stride = ws
        if pad is None:
            pad = (0,) * nd
        elif isinstance(pad, (tuple, list)):
            if max(pad) != 0 and not self.mode == 'average_exc_pad':
                raise ValueError('Padding must be zero for average_exc_pad')
        ws = as_tensor_variable(ws)
        stride = as_tensor_variable(stride)
        pad = as_tensor_variable(pad)
        assert ws.ndim == stride.ndim and ws.ndim == pad.ndim
        assert ws.ndim == 1
        if ws.dtype not in theano.tensor.int_dtypes:
            raise TypeError('Window shape parameters must be ints.')
        if stride.dtype not in theano.tensor.int_dtypes:
            raise TypeError('Stride parameters must be ints.')
        if pad.dtype not in theano.tensor.int_dtypes:
            raise TypeError('Padding parameters must be ints.')

        ws = theano.tensor.cast(ws, 'int64')
        stride = theano.tensor.cast(stride, 'int64')
        pad = theano.tensor.cast(pad, 'int64')

        return Apply(self, [inp, out_grad, ws, stride, pad], [inp.type()])
开发者ID:JesseLivezey,项目名称:Theano,代码行数:34,代码来源:pool.py

示例2: make_node

    def make_node(self, V, W, b, d):
        """
        Parameters
        ----------
        V
            Visible unit, input(batch,row,column,time,in channel)
        W
            Weights, filter(out channel,row,column,time,in channel)
        b
            bias, shape == (W.shape[0],)
        d
            strides when moving the filter over the input(dx,dy,dt)

        """

        V_ = T.as_tensor_variable(V)
        W_ = T.as_tensor_variable(W)
        b_ = T.as_tensor_variable(b)
        d_ = T.as_tensor_variable(d)

        bcast = (V_.broadcastable[0], False, False, False, W_.broadcastable[0])

        node = theano.Apply(self, inputs=[V_, W_, b_, d_],
                            outputs=[T.TensorType(V_.dtype, bcast)()])

        return node
开发者ID:ALISCIFP,项目名称:Segmentation,代码行数:26,代码来源:Conv3D.py

示例3: make_node

    def make_node(self, V, d, WShape, dCdH):
        V_ = T.as_tensor_variable(V)
        d_ = T.as_tensor_variable(d)
        WShape_ = T.as_tensor_variable(WShape)
        dCdH_ = T.as_tensor_variable(dCdH)

        return theano.Apply(self, inputs=[V_, d_, WShape_, dCdH_], outputs = [ T.TensorType(V_.dtype, (False,False,False,False,False))() ] )
开发者ID:errord,项目名称:Theano,代码行数:7,代码来源:ConvGrad3D.py

示例4: make_node

 def make_node(self, C, alpha, A, B, beta):
     alpha = as_tensor_variable(alpha)
     beta = as_tensor_variable(beta)
     A = as_gpuarray_variable(A)
     B = as_gpuarray_variable(B)
     C = as_gpuarray_variable(C)
     assert A.dtype == B.dtype == C.dtype
     return Apply(self, [C, alpha, A, B, beta], [C.type()])
开发者ID:caglar,项目名称:Theano,代码行数:8,代码来源:blas.py

示例5: make_node

 def make_node(self, y, alpha, A, x, beta):
     ctx_name = infer_context_name(y, A, x)
     A = as_gpuarray_variable(A, ctx_name)
     x = as_gpuarray_variable(x, ctx_name)
     y = as_gpuarray_variable(y, ctx_name)
     alpha = as_tensor_variable(alpha).astype('float64')
     beta = as_tensor_variable(beta).astype('float64')
     assert alpha.ndim == 0
     assert beta.ndim == 0
     assert A.ndim == 2
     assert x.ndim == 1
     assert y.ndim == 1
     assert A.dtype == x.dtype == y.dtype
     return Apply(self, [y, alpha, A, x, beta], [y.type()])
开发者ID:datascibox,项目名称:Theano,代码行数:14,代码来源:blas.py

示例6: make_node

    def make_node(self, indices, dims):
        indices = basic.as_tensor_variable(indices)
        dims = basic.as_tensor_variable(dims)

        if indices.dtype not in basic.int_dtypes:
            raise TypeError("'%s' object cannot be interpreted as an index" % str(indices.dtype))
        if dims.dtype not in basic.int_dtypes:
            raise TypeError("'%s' object cannot be interpreted as an index" % str(dims.dtype))
        if dims.ndim != 1:
            raise TypeError("dims must be a 1D array")

        return gof.Apply(
            self, [indices, dims],
            [basic.TensorType(dtype='int64', broadcastable=(False,) * indices.ndim)()
             for i in xrange(self.ndim)])
开发者ID:lamblin,项目名称:Theano,代码行数:15,代码来源:extra_ops.py

示例7: broadcast_like

def broadcast_like(value, template, fgraph, dtype=None):
    """
    Return a Variable with the same shape and dtype as the template,
    filled by broadcasting value through it. `value` will be cast as
    necessary.

    """
    value = T.as_tensor_variable(value)
    if value.type == template.type:
        return value
    if template not in fgraph.variables:
        raise NotImplementedError('broadcast_like currently requires the '
                                  'template Variable to be in the fgraph already')
    if hasattr(fgraph, 'shape_feature'):
        new_shape = fgraph.shape_feature.shape_of[template]
    else:
        new_shape = template.shape
    if dtype is None:
        dtype = template.dtype
    rval = T.alloc(T.cast(value, dtype), *new_shape)
    # the template may have 1s in its shape without being broadcastable
    if rval.broadcastable != template.broadcastable:
        rval = T.unbroadcast(rval, *[i for i in xrange(rval.ndim)
                                     if rval.broadcastable[i] and
                                     not template.broadcastable[i]])
    assert rval.type.dtype == dtype

    if rval.type.broadcastable != template.broadcastable:
        raise AssertionError("rval.type.broadcastable is " +
                             str(rval.type.broadcastable) +
                             " but template.broadcastable is" +
                             str(template.broadcastable))

    return rval
开发者ID:scauhua,项目名称:Theano,代码行数:34,代码来源:opt.py

示例8: make_node

 def make_node(self, x):
     x = basic.as_tensor_variable(x)
     self_axis = self.axis
     if self_axis is None:
         broadcastable = [False]
     else:
         if self_axis < 0:
             self_axis += len(x.broadcastable)
         if self_axis < 0 or self_axis >= len(x.broadcastable):
             raise RuntimeError(
                 "Unique axis `{}` is outside of input ndim = "
                 "{}.".format(self.axis, len(x.broadcastable))
                 )
         broadcastable = [b if axis != self_axis else False
                          for axis, b in enumerate(x.broadcastable)]
     outputs = [basic.TensorType(broadcastable=broadcastable,
                                 dtype=x.dtype)()]
     typ = basic.TensorType(broadcastable=[False], dtype='int64')
     if self.return_index:
         outputs.append(typ())
     if self.return_inverse:
         outputs.append(typ())
     if self.return_counts:
         outputs.append(typ())
     return theano.Apply(self, [x], outputs)
开发者ID:Theano,项目名称:Theano,代码行数:25,代码来源:extra_ops.py

示例9: make_node

 def make_node(self, x):
     x = tensor.as_tensor_variable(x)
     if x.type.ndim not in (1, 2) \
             or x.type.dtype not in tensor.float_dtypes:
         raise ValueError('x must be 1-d or 2-d tensor of floats. Got ', x.type)
     if x.ndim == 1:
         x = tensor.shape_padleft(x, n_ones=1)
     return Apply(self, [x], [x.type()])
开发者ID:Unbabel,项目名称:sparsemax,代码行数:8,代码来源:sparsemax_theano.py

示例10: make_node

    def make_node(self, x):
        x = basic.as_tensor_variable(x)
        out_type = x.type()

        if self.axis is None:
            out_type = theano.tensor.vector(dtype=x.dtype)  # Flatten

        return theano.Apply(self, [x], [out_type])
开发者ID:Dimitris0mg,项目名称:Theano,代码行数:8,代码来源:extra_ops.py

示例11: make_node

    def make_node(self, x):
        x = basic.as_tensor_variable(x)
        out_type = x.type()

        if self.axis is None:
            out_type = theano.tensor.vector(dtype=x.dtype)  # Flatten
        elif self.axis >= x.ndim or self.axis < -x.ndim:
            raise ValueError('axis(={0}) out of bounds'.format(self.axis))

        return theano.Apply(self, [x], [out_type])
开发者ID:souravsingh,项目名称:Theano,代码行数:10,代码来源:extra_ops.py

示例12: make_node

    def make_node(self, x, weights):
        warnings.warn((
            "Tile op is deprecated, use tile function instead."),
            stacklevel=3)

        x = basic.as_tensor_variable(x)

        if x.dtype not in BinCountOp.compatible_type:
            raise TypeError("Inputs dtype must be an integer.")

        # Some dtypes are not supported by numpy's implementation of bincount.
        # Until another one is available, we should fail at graph construction
        # time, not wait for execution.
        int_bitwidth = theano.gof.python_int_bitwidth()
        if int_bitwidth == 64:
            numpy_unsupported_dtypes = ('uint64',)
        if int_bitwidth == 32:
            numpy_unsupported_dtypes = ('uint32', 'int64', 'uint64')
        intp_bitwidth = theano.gof.local_bitwidth()
        if intp_bitwidth == 32:
            out_type = basic.ivector()
        elif intp_bitwidth == 64:
            out_type = basic.lvector()

        if x.dtype in numpy_unsupported_dtypes:
            raise TypeError(
                ("Input dtypes %s are not supported by numpy.bincount, "
                 % numpy_unsupported_dtypes), x.dtype)

        if x.ndim != 1:
            raise TypeError("Inputs must be of dimension 1.")

        if weights is None:
            weights = theano.gof.Constant(theano.gof.Generic(), None)
        else:
            weights = basic.as_tensor_variable(weights)
            out_type = basic.dvector()
            if weights.ndim != 1:
                raise TypeError("Weights cannot have a number of"
                                "dimension different of 1.")

        return theano.Apply(self, [x, weights], [out_type])
开发者ID:naisanza,项目名称:Theano,代码行数:42,代码来源:extra_ops.py

示例13: make_node

 def make_node(self, A, alpha, x, y):
     ctx_name = infer_context_name(A, x, y)
     A = as_gpuarray_variable(A, ctx_name)
     x = as_gpuarray_variable(x, ctx_name)
     y = as_gpuarray_variable(y, ctx_name)
     alpha = as_tensor_variable(alpha)
     assert alpha.ndim == 0
     assert A.ndim == 2
     assert x.ndim == 1
     assert y.ndim == 1
     assert A.dtype == x.dtype == y.dtype
     return Apply(self, [A, alpha, x, y], [A.type()])
开发者ID:12190143,项目名称:Theano,代码行数:12,代码来源:blas.py

示例14: make_node

    def make_node(self, W, b, d, H, RShape=None):
        """
        Parameters
        ----------
        W
            Weights, filter
        b
            Bias, shape == (W.shape[0],).
        d
            Strides when moving the filter over the input.
        H
            The output of Conv3D.

        """
        W_ = T.as_tensor_variable(W)
        b_ = T.as_tensor_variable(b)
        d_ = T.as_tensor_variable(d)
        H_ = T.as_tensor_variable(H)
        if RShape:
            RShape_ = T.as_tensor_variable(RShape)
        else:
            RShape_ = T.as_tensor_variable([-1, -1, -1])

        return theano.Apply(self,
                            inputs=[W_, b_, d_, H_, RShape_],
                            outputs=[T.TensorType(H_.dtype,
                                     (False, False, False, False, False))()])
开发者ID:ALISCIFP,项目名称:Segmentation,代码行数:27,代码来源:ConvTransp3D.py

示例15: multinomial

    def multinomial(self, size=None, n=1, pvals=None, ndim=None, dtype='int64', nstreams=None):
        if pvals is None:
            raise TypeError('You have to specify pvals')
        pvals = as_tensor_variable(pvals)
        if size is not None:
            if any([isinstance(i, int) and i <= 0 for i in size]):
                raise ValueError('The specified size contains a dimension with value <= 0', size)

        if n == 1 and pvals.ndim == 1:
            if ndim is not None:
                raise ValueError('Provided an ndim argument to ' +
                        'MRG_RandomStreams2.multinomial, which does not use ' +
                        'the ndim argument.')
            unis = self.uniform(size=size, ndim=2, nstreams=nstreams)
            op = MultinomialFromUniform2(dtype)
            return op(pvals, unis)
        else:
            raise NotImplementedError('MRG_RandomStreams2.multinomial only ' +
                ' implemented with n == 1 and pvals.ndim = 2')
开发者ID:hydercps,项目名称:hred-qs,代码行数:19,代码来源:theano_extensions.py


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