首先导包:
import torch
save_torch = torch.Tensor([[1, 2, 3, 4],
[2, 34, 5, 6]])
保存 tensor
torch.save(save_torch, 'test_save_tensor.pt')
读取 tensor
load_torch = torch.load('test_save_tensor.pt')
完整测试代码
import torch
save_torch = torch.Tensor([[1, 2, 3, 4],
[2, 34, 5, 6]])
print(save_torch)
torch.save(save_torch, 'test_save_tensor.pt') # 保存
load_torch = torch.load('test_save_tensor.pt') # 读取
print(load_torch)