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
  1. import unittest
  2. import os
  3. from super_gradients.training import SgModel
  4. from super_gradients.training.datasets.dataset_interfaces.dataset_interface import ClassificationTestDatasetInterface
  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. "loss_logging_items_names": ["Loss"], "metric_to_watch": "Accuracy",
  16. "greater_metric_to_watch_is_better": True}
  17. # Define Model
  18. model = SgModel("save_ckpt_test", model_checkpoints_location='local')
  19. # Connect Dataset
  20. dataset = ClassificationTestDatasetInterface()
  21. model.connect_dataset_interface(dataset, data_loader_num_workers=8)
  22. # Build Model
  23. model.build_model("resnet18_cifar", load_checkpoint=False)
  24. # Train Model (and save ckpt_epoch_list)
  25. model.train(training_params=train_params)
  26. dir_path = model.checkpoints_dir_path
  27. self.file_names_list = [dir_path + f'/ckpt_epoch_{epoch}.pth' for epoch in train_params["save_ckpt_epoch_list"]]
  28. def test_save_ckpt_epoch_list(self):
  29. self.assertTrue(os.path.exists(self.file_names_list[0]))
  30. self.assertTrue(os.path.exists(self.file_names_list[1]))
  31. if __name__ == '__main__':
  32. unittest.main()
Tip!

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

Comments

Loading...