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

save_ckpt_test.py 1.8 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
  1. import unittest
  2. import os
  3. from super_gradients.training import Trainer, models
  4. from super_gradients.training.dataloaders.dataloaders import classification_test_dataloader
  5. from super_gradients.training.metrics import Accuracy, Top5
  6. from super_gradients.common.object_names import Models
  7. class SaveCkptListUnitTest(unittest.TestCase):
  8. def setUp(self):
  9. # Define Parameters
  10. train_params = {
  11. "max_epochs": 4,
  12. "lr_decay_factor": 0.1,
  13. "lr_updates": [4],
  14. "lr_mode": "StepLRScheduler",
  15. "lr_warmup_epochs": 0,
  16. "initial_lr": 0.1,
  17. "loss": "CrossEntropyLoss",
  18. "optimizer": "SGD",
  19. "optimizer_params": {"weight_decay": 1e-4, "momentum": 0.9},
  20. "save_ckpt_epoch_list": [1, 3],
  21. "loss": "CrossEntropyLoss",
  22. "train_metrics_list": [Accuracy(), Top5()],
  23. "valid_metrics_list": [Accuracy(), Top5()],
  24. "metric_to_watch": "Accuracy",
  25. "greater_metric_to_watch_is_better": True,
  26. }
  27. # Define Model
  28. trainer = Trainer("save_ckpt_test")
  29. # Build Model
  30. model = models.get(Models.RESNET18_CIFAR, arch_params={"num_classes": 10})
  31. # Train Model (and save ckpt_epoch_list)
  32. trainer.train(model=model, training_params=train_params, train_loader=classification_test_dataloader(), valid_loader=classification_test_dataloader())
  33. dir_path = trainer.checkpoints_dir_path
  34. self.file_names_list = [dir_path + f"/ckpt_epoch_{epoch}.pth" for epoch in train_params["save_ckpt_epoch_list"]]
  35. def test_save_ckpt_epoch_list(self):
  36. self.assertTrue(os.path.exists(self.file_names_list[0]))
  37. self.assertTrue(os.path.exists(self.file_names_list[1]))
  38. if __name__ == "__main__":
  39. unittest.main()
Tip!

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

Comments

Loading...