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

lr_test.py 2.1 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
50
51
52
53
54
55
56
57
  1. import shutil
  2. import unittest
  3. import os
  4. from super_gradients.common.object_names import Models
  5. from super_gradients.training import models
  6. from super_gradients import Trainer
  7. from super_gradients.training.dataloaders.dataloaders import classification_test_dataloader
  8. from super_gradients.training.metrics import Accuracy, Top5
  9. class LRTest(unittest.TestCase):
  10. @classmethod
  11. def setUp(cls):
  12. # NAMES FOR THE EXPERIMENTS TO LATER DELETE
  13. cls.folder_name = "lr_test"
  14. cls.training_params = {
  15. "max_epochs": 1,
  16. "silent_mode": True,
  17. "initial_lr": 0.1,
  18. "loss": "CrossEntropyLoss",
  19. "train_metrics_list": [Accuracy(), Top5()],
  20. "valid_metrics_list": [Accuracy(), Top5()],
  21. "metric_to_watch": "Accuracy",
  22. "greater_metric_to_watch_is_better": True,
  23. }
  24. @classmethod
  25. def tearDownClass(cls) -> None:
  26. # ERASE THE FOLDER THAT WAS CREATED DURING THIS TEST
  27. if os.path.isdir(os.path.join("checkpoints", cls.folder_name)):
  28. shutil.rmtree(os.path.join("checkpoints", cls.folder_name))
  29. @staticmethod
  30. def get_trainer(name=""):
  31. trainer = Trainer(name)
  32. model = models.get(Models.RESNET18_CIFAR, num_classes=5)
  33. return trainer, model
  34. def test_cosine_lr(self):
  35. trainer, model = self.get_trainer(self.folder_name)
  36. training_params = {**self.training_params, "lr_mode": "CosineLRScheduler", "cosine_final_lr_ratio": 0.01}
  37. trainer.train(
  38. model=model, training_params=training_params, train_loader=classification_test_dataloader(), valid_loader=classification_test_dataloader()
  39. )
  40. def test_step_lr(self):
  41. trainer, model = self.get_trainer(self.folder_name)
  42. training_params = {**self.training_params, "lr_mode": "StepLRScheduler", "lr_decay_factor": 0.1, "lr_updates": [4]}
  43. trainer.train(
  44. model=model, training_params=training_params, train_loader=classification_test_dataloader(), valid_loader=classification_test_dataloader()
  45. )
  46. if __name__ == "__main__":
  47. unittest.main()
Tip!

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

Comments

Loading...