PyTorch torch.load function
PyTorch torch reference manual
torch.load is a function in PyTorch used to load. It loads a serialized object from a file.
Function definition
torch.load(f, map_location=None, weights_only=False)
Usage examples
Example
import
torch
Save a tensor
x
=
torch.
tensor
(
[
1
,
2
,
3
,
4
,
5
]
)
torch.
save
(
x
,
'tensor.pt'
)
Load a tensor
loaded_x
=
torch.
load
(
'tensor.pt'
)
(
f
"Loaded tensor: {loaded_x}"
)