本文整理汇总了Python中torch.atan方法的典型用法代码示例。如果您正苦于以下问题:Python torch.atan方法的具体用法?Python torch.atan怎么用?Python torch.atan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类torch
的用法示例。
在下文中一共展示了torch.atan方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: forward
# 需要导入模块: import torch [as 别名]
# 或者: from torch import atan [as 别名]
def forward(self, input):
self.batchgrid = torch.zeros(torch.Size([input.size(0)]) + self.grid.size() )
#print(self.batchgrid.size())
for i in range(input.size(0)):
self.batchgrid[i,:,:,:] = self.grid
self.batchgrid = Variable(self.batchgrid)
#print(self.batchgrid.size())
input_u = input.view(-1,1,1,1).repeat(1,self.height, self.width,1)
#print(input_u.requires_grad, self.batchgrid)
output0 = self.batchgrid[:,:,:,0:1]
output1 = torch.atan(torch.tan(np.pi/2.0*(self.batchgrid[:,:,:,1:2] + self.batchgrid[:,:,:,2:] * input_u[:,:,:,:]))) /(np.pi/2)
#print(output0.size(), output1.size())
output = torch.cat([output0, output1], 3)
return output
示例2: tobin
# 需要导入模块: import torch [as 别名]
# 或者: from torch import atan [as 别名]
def tobin(self, target):
indxneg = target.data[:,0,:,:] < 0
eps = torch.zeros(target.data[:,0,:,:].size()).cuda()
epsind = target.data[:,0,:,:] == 0
eps[epsind] += 1e-5
angle = torch.atan(target.data[:,1,:,:] / (target.data[:,0,:,:] + eps))
angle[indxneg] += np.pi
angle += np.pi / 2 # 0 to 2pi
angle = torch.clamp(angle, 0, 2 * np.pi - 1e-3)
radius = torch.sqrt(target.data[:,0,:,:] ** 2 + target.data[:,1,:,:] ** 2)
radius = torch.clamp(radius, 0, self.fmax - 1e-3)
quantized_angle = torch.floor(self.abins * angle / (2 * np.pi))
if self.quantize_strategy == 'linear':
quantized_radius = torch.floor(self.rbins * radius / self.fmax)
elif self.quantize_strategy == 'quadratic':
quantized_radius = torch.floor(self.rbins * torch.sqrt(radius / self.fmax))
else:
raise Exception("No such quantize strategy: {}".format(self.quantize_strategy))
quantized_target = torch.autograd.Variable(torch.cat([torch.unsqueeze(quantized_angle, 1), torch.unsqueeze(quantized_radius, 1)], dim=1))
return quantized_target.type(torch.cuda.LongTensor)
示例3: forward
# 需要导入模块: import torch [as 别名]
# 或者: from torch import atan [as 别名]
def forward(self, input):
self.batchgrid = torch.zeros(
torch.Size([input.size(0)]) + self.grid.size())
# print(self.batchgrid.size())
for i in range(input.size(0)):
self.batchgrid[i, :, :, :] = self.grid
self.batchgrid = Variable(self.batchgrid)
# print(self.batchgrid.size())
input_u = input.view(-1, 1, 1, 1).repeat(1, self.height, self.width, 1)
# print(input_u.requires_grad, self.batchgrid)
output0 = self.batchgrid[:, :, :, 0:1]
output1 = torch.atan(torch.tan(
np.pi / 2.0 * (
self.batchgrid[:, :, :, 1:2] + self.batchgrid[:, :, :,
2:] * input_u[:, :, :,
:]))) / (
np.pi / 2)
# print(output0.size(), output1.size())
output = torch.cat([output0, output1], 3)
return output
示例4: forward
# 需要导入模块: import torch [as 别名]
# 或者: from torch import atan [as 别名]
def forward(self, inputs, context=None):
outputs = (1 / np.pi) * torch.atan(inputs) + 0.5
logabsdet = utils.sum_except_batch(
- np.log(np.pi) - torch.log(1 + inputs ** 2)
)
return outputs, logabsdet