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
49
  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": "step",
  15. "lr_warmup_epochs": 0,
  16. "initial_lr": 0.1,
  17. "loss": "cross_entropy",
  18. "optimizer": "SGD",
  19. "criterion_params": {},
  20. "optimizer_params": {"weight_decay": 1e-4, "momentum": 0.9},
  21. "save_ckpt_epoch_list": [1, 3],
  22. "loss": "cross_entropy",
  23. "train_metrics_list": [Accuracy(), Top5()],
  24. "valid_metrics_list": [Accuracy(), Top5()],
  25. "metric_to_watch": "Accuracy",
  26. "greater_metric_to_watch_is_better": True,
  27. }
  28. # Define Model
  29. trainer = Trainer("save_ckpt_test")
  30. # Build Model
  31. model = models.get(Models.RESNET18_CIFAR, arch_params={"num_classes": 10})
  32. # Train Model (and save ckpt_epoch_list)
  33. trainer.train(model=model, training_params=train_params, train_loader=classification_test_dataloader(), valid_loader=classification_test_dataloader())
  34. dir_path = trainer.checkpoints_dir_path
  35. self.file_names_list = [dir_path + f"/ckpt_epoch_{epoch}.pth" for epoch in train_params["save_ckpt_epoch_list"]]
  36. def test_save_ckpt_epoch_list(self):
  37. self.assertTrue(os.path.exists(self.file_names_list[0]))
  38. self.assertTrue(os.path.exists(self.file_names_list[1]))
  39. if __name__ == "__main__":
  40. unittest.main()
Tip!

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

Comments

Loading...