Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

test_utils_torch.py 1.0 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
  1. import torch
  2. import torch.nn as nn
  3. import torch.nn.functional as F
  4. from torch import sigmoid, tanh
  5. def test_tensordataset():
  6. a = torch.FloatTensor([[1, 2], [3, 4], [5, 6]]).to('cuda')
  7. b = torch.FloatTensor([[7, 8], [9, 10], [11, 12]]).to('cuda')
  8. complete_dataset = torch.utils.data.TensorDataset(a, b)
  9. print(len(complete_dataset))
  10. num_train = int(len(complete_dataset)*.9)
  11. num_test = len(complete_dataset) - num_train
  12. torch.manual_seed(0);
  13. train_dataset, test_dataset = torch.utils.data.random_split(complete_dataset, [num_train, num_test])
  14. train_loader = torch.utils.data.DataLoader(train_dataset,
  15. batch_size=1, shuffle=True) # create your dataloader
  16. # test_loader = torch.utils.data.DataLoader(test_dataset,
  17. # batch_size=3, shuffle=True) # create your dataloader
  18. print(train_loader)
  19. # print(test_loader)
  20. for batch_idx, (data, target) in enumerate(train_loader):
  21. print(batch_idx)
  22. print(data)
  23. print(target)
  24. test_tensordataset()
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...