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
  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. class SaveCkptListUnitTest(unittest.TestCase):
  7. def setUp(self):
  8. # Define Parameters
  9. train_params = {"max_epochs": 4, "lr_decay_factor": 0.1, "lr_updates": [4], "lr_mode": "step",
  10. "lr_warmup_epochs": 0, "initial_lr": 0.1, "loss": "cross_entropy", "optimizer": "SGD",
  11. "criterion_params": {}, "optimizer_params": {"weight_decay": 1e-4, "momentum": 0.9},
  12. "save_ckpt_epoch_list": [1, 3],
  13. "loss": "cross_entropy", "train_metrics_list": [Accuracy(), Top5()],
  14. "valid_metrics_list": [Accuracy(), Top5()],
  15. "metric_to_watch": "Accuracy",
  16. "greater_metric_to_watch_is_better": True}
  17. # Define Model
  18. trainer = Trainer("save_ckpt_test")
  19. # Build Model
  20. model = models.get("resnet18_cifar", arch_params={"num_classes": 10})
  21. # Train Model (and save ckpt_epoch_list)
  22. trainer.train(model=model, training_params=train_params,
  23. train_loader=classification_test_dataloader(),
  24. valid_loader=classification_test_dataloader())
  25. dir_path = trainer.checkpoints_dir_path
  26. self.file_names_list = [dir_path + f'/ckpt_epoch_{epoch}.pth' for epoch in train_params["save_ckpt_epoch_list"]]
  27. def test_save_ckpt_epoch_list(self):
  28. self.assertTrue(os.path.exists(self.file_names_list[0]))
  29. self.assertTrue(os.path.exists(self.file_names_list[1]))
  30. if __name__ == '__main__':
  31. unittest.main()
Tip!

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

Comments

Loading...