本文整理汇总了Python中torchbearer.Model._deep_to方法的典型用法代码示例。如果您正苦于以下问题:Python Model._deep_to方法的具体用法?Python Model._deep_to怎么用?Python Model._deep_to使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类torchbearer.Model
的用法示例。
在下文中一共展示了Model._deep_to方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_deep_to_tensor
# 需要导入模块: from torchbearer import Model [as 别名]
# 或者: from torchbearer.Model import _deep_to [as 别名]
def test_deep_to_tensor(self):
tensor = MagicMock()
new_dtype = torch.float16
new_device = 'cuda:1'
Model._deep_to(tensor, new_device, new_dtype)
self.assertTrue(tensor.to.call_args[0][0] == new_device)
self.assertTrue(tensor.to.call_args[0][1] == new_dtype)
示例2: test_deep_to_tensor_int_dtype
# 需要导入模块: from torchbearer import Model [as 别名]
# 或者: from torchbearer.Model import _deep_to [as 别名]
def test_deep_to_tensor_int_dtype(self):
tensor = MagicMock()
tensor.dtype = torch.uint8
new_device = 'cuda:1'
new_dtype = torch.uint8
Model._deep_to(tensor, new_device, new_dtype)
self.assertTrue(tensor.to.call_args[0][0] == new_device)
self.assertTrue(len(tensor.to.call_args[0]) == 1)
示例3: test_deep_to_list
# 需要导入模块: from torchbearer import Model [as 别名]
# 或者: from torchbearer.Model import _deep_to [as 别名]
def test_deep_to_list(self):
tensor_1 = MagicMock()
tensor_2 = MagicMock()
tensors = [tensor_1, tensor_2]
new_dtype = torch.float16
new_device = 'cuda:1'
Model._deep_to(tensors, new_device, new_dtype)
for tensor in tensors:
self.assertTrue(tensor.to.call_args[0][0] == new_device)
self.assertTrue(tensor.to.call_args[0][1] == new_dtype)