本文整理汇总了Python中theano.tensor.ones方法的典型用法代码示例。如果您正苦于以下问题:Python tensor.ones方法的具体用法?Python tensor.ones怎么用?Python tensor.ones使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类theano.tensor
的用法示例。
在下文中一共展示了tensor.ones方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: path_probabs
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import ones [as 别名]
def path_probabs(cls, y, y_hat, y_mask, y_hat_mask, blank_symbol):
pred_y = cls.class_batch_to_labeling_batch(y, y_hat, y_hat_mask)
r2, r3 = cls.recurrence_relation(y, y_mask, blank_symbol)
def step(p_curr, p_prev):
# instead of dot product, we * first
# and then sum oven one dimension.
# objective: T.dot((p_prev)BxL, LxLxB)
# solusion: Lx1xB * LxLxB --> LxLxB --> (sumover)xLxB
dotproduct = (p_prev + tensor.dot(p_prev, r2) +
(p_prev.dimshuffle(1, 'x', 0) * r3).sum(axis=0).T)
return p_curr.T * dotproduct * y_mask.T # B x L
probabilities, _ = theano.scan(
step,
sequences=[pred_y],
outputs_info=[tensor.eye(y.shape[0])[0] * tensor.ones(y.T.shape)])
return probabilities, probabilities.shape
示例2: log_path_probabs
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import ones [as 别名]
def log_path_probabs(cls, y, y_hat, y_mask, y_hat_mask, blank_symbol):
pred_y = cls.class_batch_to_labeling_batch(y, y_hat, y_hat_mask)
r2, r3 = cls.recurrence_relation(y, y_mask, blank_symbol)
def step(log_p_curr, log_p_prev):
p1 = log_p_prev
p2 = cls.log_dot_matrix(p1, r2)
p3 = cls.log_dot_tensor(p1, r3)
p123 = cls.log_add(p3, cls.log_add(p1, p2))
return (log_p_curr.T +
p123 +
cls._epslog(y_mask.T))
log_probabilities, _ = theano.scan(
step,
sequences=[cls._epslog(pred_y)],
outputs_info=[cls._epslog(tensor.eye(y.shape[0])[0] *
tensor.ones(y.T.shape))])
return log_probabilities
示例3: create_probs_computer
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import ones [as 别名]
def create_probs_computer(self, return_alignment=False):
if not hasattr(self, 'probs_fn'):
logger.debug("Compile probs computer")
self.probs_fn = theano.function(
inputs=self.inputs,
outputs=[self.predictions.word_probs, self.alignment],
name="probs_fn")
def probs_computer(x, y):
x_mask = numpy.ones(x.shape[0], dtype="float32")
y_mask = numpy.ones(y.shape[0], dtype="float32")
probs, alignment = self.probs_fn(x[:, None], y[:, None],
x_mask[:, None], y_mask[:, None])
if return_alignment:
return probs, alignment
else:
return probs
return probs_computer
示例4: gen_hull
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import ones [as 别名]
def gen_hull(p, p_mask, f_encode, f_probi, options):
# p: n_sizes * n_samples * data_dim
n_sizes = p.shape[0]
n_samples = p.shape[1] if p.ndim == 3 else 1
hprev = f_encode(p_mask, p) # n_sizes * n_samples * data_dim
points = numpy.zeros((n_samples, n_sizes), dtype='int64')
h = hprev[-1]
c = numpy.zeros((n_samples, options['dim_proj']), dtype=config.floatX)
xi = numpy.zeros((n_samples,), dtype='int64')
xi_mask = numpy.ones((n_samples,), dtype=config.floatX)
for i in range(n_sizes):
h, c, probi = f_probi(p_mask[i], xi, h, c, hprev, p_mask, p)
xi = probi.argmax(axis=0)
xi *= xi_mask.astype(numpy.int64) # Avoid compatibility problem in numpy 1.10
xi_mask = (numpy.not_equal(xi, 0)).astype(config.floatX)
if numpy.equal(xi_mask, 0).all():
break
points[:, i] = xi
return points
示例5: Noise
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import ones [as 别名]
def Noise(hyp, X1, X2=None, all_pairs=True):
''' Noise kernel. Takes as an input a distance matrix D
and creates a new matrix as Kij = sn2 if Dij == 0 else 0'''
if X2 is None:
X2 = X1
sn2 = hyp**2
if all_pairs and X1 is X2:
# D = (X1[:,None,:] - X2[None,:,:]).sum(2)
K = tt.eye(X1.shape[0])*sn2
return K
else:
# D = (X1 - X2).sum(1)
if X1 is X2:
K = tt.ones((X1.shape[0],))*sn2
else:
K = 0
return K
# K = tt.eq(D,0)*sn2
# return K
示例6: pad
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import ones [as 别名]
def pad(x, padding, fill_value=0):
"""
applies padding to tensor
"""
input_shape = x.shape
output_shape = []
indices = []
for dim, pad in enumerate(padding):
try:
left_pad, right_pad = pad
except TypeError:
left_pad = right_pad = pad
output_shape.append(left_pad + input_shape[dim] + right_pad)
indices.append(slice(left_pad, left_pad + input_shape[dim]))
if fill_value:
out = T.ones(output_shape) * fill_value
else:
out = T.zeros(output_shape)
return T.set_subtensor(out[tuple(indices)], x)
示例7: get_output_for
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import ones [as 别名]
def get_output_for(self, inputs, **kwargs):
vals, ref = inputs
def filt(V, R):
if self.norm_type is not None:
o = tt.ones((1, V.shape[1], V.shape[2]), np.float32)
norm = gaussian_filter(R, o, self.kern_std, self.ref_dim)
norm = tt.sqrt(norm) if self.norm_type == "sym" else norm
norm += 1e-8
V = V / norm if self.norm_type in ["pre", "sym"] else V
F = gaussian_filter(R, V, self.kern_std)
return F / norm if self.norm_type in ["post", "sym"] else F
filtered = theano.scan(fn=filt, sequences=[vals, ref],
outputs_info=None)[0]
return filtered
示例8: _meshgrid
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import ones [as 别名]
def _meshgrid(height, width):
# This should be equivalent to:
# x_t, y_t = np.meshgrid(np.linspace(-1, 1, width),
# np.linspace(-1, 1, height))
# ones = np.ones(np.prod(x_t.shape))
# grid = np.vstack([x_t.flatten(), y_t.flatten(), ones])
x_t = T.dot(T.ones((height, 1)),
_linspace(-1.0, 1.0, width).dimshuffle('x', 0))
y_t = T.dot(_linspace(-1.0, 1.0, height).dimshuffle(0, 'x'),
T.ones((1, width)))
x_t_flat = x_t.reshape((1, -1))
y_t_flat = y_t.reshape((1, -1))
ones = T.ones_like(x_t_flat)
grid = T.concatenate([x_t_flat, y_t_flat, ones], axis=0)
return grid
示例9: project3Dto2D
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import ones [as 别名]
def project3Dto2D(self, Li, idxs):
"""
Project 3D point to 2D
:param Li: joints in normalized 3D
:param idxs: frames specified by subset
:return: 2D points, in normalized 2D coordinates
"""
if not isinstance(idxs, numpy.ndarray):
idxs = numpy.asarray([idxs])
# 3D -> 2D projection also shift by M to cropped window
Li_glob3D = (numpy.reshape(Li, (len(idxs), self.numJoints, 3))*self.Di_scale[idxs][:, None, None]+self.Di_off3D[idxs][:, None, :]).reshape((len(idxs)*self.numJoints, 3))
Li_glob3D_hom = numpy.concatenate([Li_glob3D, numpy.ones((len(idxs)*self.numJoints, 1), dtype='float32')], axis=1)
Li_glob2D_hom = numpy.dot(Li_glob3D_hom, self.cam_proj.T)
Li_glob2D = (Li_glob2D_hom[:, 0:3] / Li_glob2D_hom[:, 3][:, None]).reshape((len(idxs), self.numJoints, 3))
Li_img2D_hom = numpy.einsum('ijk,ikl->ijl', Li_glob2D, self.Di_trans2D[idxs])
Li_img2D = (Li_img2D_hom[:, :, 0:2] / Li_img2D_hom[:, :, 2][:, :, None]).reshape((len(idxs), self.numJoints*2))
Li_img2Dcrop = (Li_img2D - (self.Di.shape[3]/2.)) / (self.Di.shape[3]/2.)
return Li_img2Dcrop
示例10: _log_path_probs
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import ones [as 别名]
def _log_path_probs(y, y_mask, y_hat, y_hat_mask):
pred_y = _class_batch_to_labeling_batch(y, y_hat, y_hat_mask)
r2, r3 = _recurrence_relation(y, y_mask)
def step(log_p_curr, log_p_prev):
p1 = log_p_prev
p2 = _log_dot_matrix(p1, r2)
p3 = _log_dot_tensor(p1, r3)
p123 = _log_add(p3, _log_add(p1, p2))
return (log_p_curr.T +
p123 +
_epslog(y_mask.T))
log_probabilities, _ = theano.scan(
step,
sequences=[_epslog(pred_y)],
outputs_info=[_epslog(tensor.eye(y.shape[0])[0] *
tensor.ones(y.T.shape))])
return log_probabilities
示例11: _ctc_label_seq
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import ones [as 别名]
def _ctc_label_seq(y, y_mask):
blank_symbol = -1
# for y
y_extended = y.T.dimshuffle(0, 1, 'x')
blanks = tensor.zeros_like(y_extended) + blank_symbol
concat = tensor.concatenate([y_extended, blanks], axis=2)
res = concat.reshape((concat.shape[0],
concat.shape[1] * concat.shape[2])).T
beginning_blanks = tensor.zeros((1, res.shape[1])) + blank_symbol
blanked_y = tensor.concatenate([beginning_blanks, res], axis=0)
y_mask_extended = y_mask.T.dimshuffle(0, 1, 'x')
concat = tensor.concatenate([y_mask_extended,
y_mask_extended], axis=2)
res = concat.reshape((concat.shape[0],
concat.shape[1] * concat.shape[2])).T
beginning_blanks = tensor.ones((1, res.shape[1]),
dtype=theano.config.floatX)
blanked_y_mask = tensor.concatenate([beginning_blanks, res], axis=0)
return blanked_y, blanked_y_mask
示例12: log_path_probs
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import ones [as 别名]
def log_path_probs(y, y_mask, y_hat, y_hat_mask):
pred_y = class_batch_to_labeling_batch(y, y_hat, y_hat_mask)
r2, r3 = recurrence_relation(y, y_mask)
def step(log_p_curr, log_p_prev):
p1 = log_p_prev
p2 = _log_dot_matrix(p1, r2)
p3 = _log_dot_tensor(p1, r3)
p123 = _log_add(p3, _log_add(p1, p2))
return (log_p_curr.T +
p123 +
_epslog(y_mask.T))
log_probabilities, _ = theano.scan(
step,
sequences=[_epslog(pred_y)],
outputs_info=[_epslog(tensor.eye(y.shape[0])[0] *
tensor.ones(y.T.shape))])
return log_probabilities
示例13: theano_label_seq
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import ones [as 别名]
def theano_label_seq(y, y_mask):
blank_symbol = -1
# for y
y_extended = y.T.dimshuffle(0, 1, 'x')
blanks = tensor.zeros_like(y_extended) + blank_symbol
concat = tensor.concatenate([y_extended, blanks], axis=2)
res = concat.reshape((concat.shape[0],
concat.shape[1] * concat.shape[2])).T
beginning_blanks = tensor.zeros((1, res.shape[1])) + blank_symbol
blanked_y = tensor.concatenate([beginning_blanks, res], axis=0)
y_mask_extended = y_mask.T.dimshuffle(0, 1, 'x')
concat = tensor.concatenate([y_mask_extended,
y_mask_extended], axis=2)
res = concat.reshape((concat.shape[0],
concat.shape[1] * concat.shape[2])).T
beginning_blanks = tensor.ones((1, res.shape[1]),
dtype=theano.config.floatX)
blanked_y_mask = tensor.concatenate([beginning_blanks, res], axis=0)
return blanked_y, blanked_y_mask
示例14: create_full_unique
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import ones [as 别名]
def create_full_unique(cls, batch_size, num_node_ids, node_state_size, num_edge_types):
"""
Create a 'full unique' graph state (i.e. a graph state where every id has exactly one node) from a spec
batch_size: Number of batches
num_node_ids: An integer giving size of node id
node_state_size: An integer giving size of node state
num_edge_types: An integer giving number of edge types
"""
return cls( T.ones([batch_size, num_node_ids]),
T.tile(T.shape_padleft(T.eye(num_node_ids)), (batch_size,1,1)),
T.zeros([batch_size, num_node_ids, node_state_size]),
T.zeros([batch_size, num_node_ids, num_node_ids, num_edge_types]))
示例15: _transform_trans
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import ones [as 别名]
def _transform_trans(theta,input):
batch1, step1, dim1 = input.shape
input = K.reshape(input,(batch1,step1,dim1//3,3))
input = K.reshape(input,(batch1*step1,dim1//3,3))
input = K.permute_dimensions(input,[0,2,1])
add = T.ones((batch1*step1,1,dim1//3))
input= K.concatenate([input,add],axis=1)
output = K.batch_dot(theta,input)
output = K.permute_dimensions(output,[0,2,1])
output = K.reshape(output,(output.shape[0],dim1))
output = K.reshape(output,(batch1,step1,output.shape[1]))
return output
开发者ID:microsoft,项目名称:View-Adaptive-Neural-Networks-for-Skeleton-based-Human-Action-Recognition,代码行数:16,代码来源:transform_rnn.py