Pytorch: best practice to save list of tensors?

AerysS

I use tensors to do transformation then I save it in a list. Later, I will make it a dataset using Dataset, then finally DataLoader to train my model. To do it, I can simply use:

l = [tensor1, tensor2, tensor3,...]
dataset = Dataset.TensorDataset(l)
dataloader = DataLoader(dataset)

I wonder what is the best practice doing so, to avoid RAM overflow if the size of l grows? Can something like Iterator avoid it?

vahvero

Save tensors

for idx, tensor in enumerate(dataloader0):
    torch.save(f"{my_folder}/tensor{idx}.pt")

Create dataset

class FolderDataset(Dataset):
   def __init__(self, folder):
       self.files = os.listdir(folder)
       self.folder = folder
   def __len__(self):
       return len(self.files)
   def __getitem__(self, idx):
       return torch.load(f"{self.folder}/{self.files[idx]}")

And then you can implement your own dataloader. If you can't hold the whole dataset in memory, some file system loading is required.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

converting list of tensors to tensors pytorch

From Dev

In the latest version of PyTorch, what is best practice to get all tensors to use a particular device by default?

From Dev

Pytorch merging list of tensors together

From Dev

Remove certain elements of all the tensors in a list of dictionary of tensors in pytorch

From Dev

slice Pytorch tensors which are saved in a list

From Dev

how to detach list of pytorch tensors to array

From Dev

How to share a list of tensors in PyTorch multiprocessing?

From Dev

List Comprehension Best Practice

From Dev

Best practice to save the uploaded images

From Dev

Best practice to pass PyTorch device name to model

From Dev

Pytorch specific operation for the finding dimension wise mean for a list of tensors

From Java

Best way to save a trained model in PyTorch?

From Dev

Compiling a list : python best practice

From Dev

Pytorch's packed_sequence/pad_sequence pads tensors vertically for list of tensors

From Dev

Best practice for calling save() many times

From Dev

Best practice save product image in laravel

From Dev

Azure IoT Hub - Save telemetry best practice

From Dev

List of tensors and just tensors

From Dev

list of tensors into tensors

From Dev

Is there a power function for tensors in pytorch?

From Dev

comparing two tensors in pytorch

From Dev

PyTorch: compare three tensors?

From Dev

Concat tensors in PyTorch

From Dev

Parsing CSV into Pytorch tensors

From Dev

Weighted Average of PyTorch Tensors

From Dev

dimension extension with pytorch tensors

From Dev

Reshape tensors in pytorch?

From Python

Pytorch tensor.save() produces huge files for small tensors from MNIST

From Dev

Best practice to expand a list (efficiency) in python

Related Related

  1. 1

    converting list of tensors to tensors pytorch

  2. 2

    In the latest version of PyTorch, what is best practice to get all tensors to use a particular device by default?

  3. 3

    Pytorch merging list of tensors together

  4. 4

    Remove certain elements of all the tensors in a list of dictionary of tensors in pytorch

  5. 5

    slice Pytorch tensors which are saved in a list

  6. 6

    how to detach list of pytorch tensors to array

  7. 7

    How to share a list of tensors in PyTorch multiprocessing?

  8. 8

    List Comprehension Best Practice

  9. 9

    Best practice to save the uploaded images

  10. 10

    Best practice to pass PyTorch device name to model

  11. 11

    Pytorch specific operation for the finding dimension wise mean for a list of tensors

  12. 12

    Best way to save a trained model in PyTorch?

  13. 13

    Compiling a list : python best practice

  14. 14

    Pytorch's packed_sequence/pad_sequence pads tensors vertically for list of tensors

  15. 15

    Best practice for calling save() many times

  16. 16

    Best practice save product image in laravel

  17. 17

    Azure IoT Hub - Save telemetry best practice

  18. 18

    List of tensors and just tensors

  19. 19

    list of tensors into tensors

  20. 20

    Is there a power function for tensors in pytorch?

  21. 21

    comparing two tensors in pytorch

  22. 22

    PyTorch: compare three tensors?

  23. 23

    Concat tensors in PyTorch

  24. 24

    Parsing CSV into Pytorch tensors

  25. 25

    Weighted Average of PyTorch Tensors

  26. 26

    dimension extension with pytorch tensors

  27. 27

    Reshape tensors in pytorch?

  28. 28

    Pytorch tensor.save() produces huge files for small tensors from MNIST

  29. 29

    Best practice to expand a list (efficiency) in python

HotTag

Archive