本文整理汇总了Python中torch.int32方法的典型用法代码示例。如果您正苦于以下问题:Python torch.int32方法的具体用法?Python torch.int32怎么用?Python torch.int32使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块torch的用法示例。
在下文中一共展示了torch.int32方法的24个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: normalize_wav
点赞 6
# 需要导入模块: import torch [as 别名]
# 或者: from torch import int32 [as 别名]
def normalize_wav(tensor: torch.Tensor) -> torch.Tensor:
if tensor.dtype == torch.float32:
pass
elif tensor.dtype == torch.int32:
tensor = tensor.to(torch.float32)
tensor[tensor > 0] /= 2147483647.
tensor[tensor < 0] /= 2147483648.
elif tensor.dtype == torch.int16:
tensor = tensor.to(torch.float32)
tensor[tensor > 0] /= 32767.
tensor[tensor < 0] /= 32768.
elif tensor.dtype == torch.uint8:
tensor = tensor.to(torch.float32) - 128
tensor[tensor > 0] /= 127.
tensor[tensor < 0] /= 128.
return tensor
开发者ID:pytorch,项目名称:audio,代码行数:18,
示例2: generate_iters_indices
点赞 6
# 需要导入模块: import torch [as 别名]
# 或者: from torch import int32 [as 别名]
def generate_iters_indices(self, num_of_iters):
from_iter = len(self.iter_indices_per_iteration)
for iter_num in range(from_iter, from_iter+num_of_iters):
# Get random number of samples per task (according to iteration distribution)
tsks = Categorical(probs=self.tasks_probs_over_iterations[iter_num]).sample(torch.Size([self.samples_in_batch]))
# Generate samples indices for iter_num
iter_indices = torch.zeros(0, dtype=torch.int32)
for task_idx in range(self.num_of_tasks):
if self.tasks_probs_over_iterations[iter_num][task_idx] > 0:
num_samples_from_task = (tsks == task_idx).sum().item()
self.samples_distribution_over_time[task_idx].append(num_samples_from_task)
# Randomize indices for each task (to allow creation of random task batch)
tasks_inner_permute = np.random.permutation(len(self.tasks_samples_indices[task_idx]))
rand_indices_of_task = tasks_inner_permute[:num_samples_from_task]
iter_indices = torch.cat([iter_indices, self.tasks_samples_indices[task_idx][rand_indices_of_task]])
else:
self.samples_distribution_over_time[task_idx].append(0)
self.iter_indices_per_iteration.append(iter_indices.tolist())
开发者ID:igolan,项目名称:bgd,代码行数:21,
示例3: compute_logits
点赞 6
# 需要导入模块: import torch [as 别名]
# 或者: from torch import int32 [as 别名]
def compute_logits(self, token_ids: torch.Tensor) -> torch.Tensor:
"""
Implements a language model, where each output is conditional on the current
input and inputs processed so far.
Args:
inputs: int32 tensor of shape [B, T], storing integer IDs of tokens.
Returns:
torch.float32 tensor of shape [B, T, V], storing the distribution over output symbols
for each timestep for each batch element.
"""
# TODO 5# 1) Embed tokens
# TODO 5# 2) Run RNN on embedded tokens
# TODO 5# 3) Project RNN outputs onto the vocabulary to obtain logits.
return rnn_output_logits
开发者ID:microsoft,项目名称:machine-learning-for-programming-samples,代码行数:18,
示例4: test_one_hot
点赞 6
# 需要导入模块: import torch [as 别名]
# 或者: from torch import int32 [as 别名]
def test_one_hot(self):
"""
Tests a torch one hot function.
"""
if get_backend() == "pytorch":
# Flat action array.
inputs = torch.tensor([0, 1], dtype=torch.int32)
one_hot = pytorch_one_hot(inputs, depth=2)
expected = torch.tensor([[1., 0.], [0., 1.]])
recursive_assert_almost_equal(one_hot, expected)
# Container space.
inputs = torch.tensor([[0, 3, 2],[1, 2, 0]], dtype=torch.int32)
one_hot = pytorch_one_hot(inputs, depth=4)
expected = torch.tensor([[[1, 0, 0, 0],[0, 0, 0, 1],[0, 0, 1, 0]],[[0, 1, 0, 0],[0, 0, 1, 0],[1, 0, 0, 0,]]],
dtype=torch.int32)
recursive_assert_almost_equal(one_hot, expected)
开发者ID:rlgraph,项目名称:rlgraph,代码行数:21,
示例5: _graph_fn_call
点赞 6
# 需要导入模块: import torch [as 别名]
# 或者: from torch import int32 [as 别名]
def _graph_fn_call(self, inputs):
if self.backend == "python" or get_backend() == "python":
if isinstance(inputs, list):
inputs = np.asarray(inputs)
return inputs.astype(dtype=util.convert_dtype(self.to_dtype, to="np"))
elif get_backend() == "pytorch":
torch_dtype = util.convert_dtype(self.to_dtype, to="pytorch")
if torch_dtype == torch.float or torch.float32:
return inputs.float()
elif torch_dtype == torch.int or torch.int32:
return inputs.int()
elif torch_dtype == torc