Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyTorch torch.load function

PyTorch torch.load function


PyTorch torch reference manual 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'

)

print

(

f

"Loaded tensor: {loaded_x}"

)


PyTorch torch reference manual PyTorch torch reference manual