π [Add] logging of optimizre(learning rate)
Browse files- yolo/tools/data_loader.py +0 -1
- yolo/tools/solver.py +2 -1
- yolo/utils/model_utils.py +3 -0
yolo/tools/data_loader.py
CHANGED
@@ -9,7 +9,6 @@ from PIL import Image
|
|
9 |
from rich.progress import track
|
10 |
from torch import Tensor
|
11 |
from torch.utils.data import DataLoader, Dataset
|
12 |
-
from torch.utils.data.distributed import DistributedSampler
|
13 |
|
14 |
from yolo.config.config import DataConfig, DatasetConfig
|
15 |
from yolo.tools.data_augmentation import *
|
|
|
9 |
from rich.progress import track
|
10 |
from torch import Tensor
|
11 |
from torch.utils.data import DataLoader, Dataset
|
|
|
12 |
|
13 |
from yolo.config.config import DataConfig, DatasetConfig
|
14 |
from yolo.tools.data_augmentation import *
|
yolo/tools/solver.py
CHANGED
@@ -83,7 +83,7 @@ class TrainModel(ValidateModel):
|
|
83 |
self.trainer.optimizers[0].next_epoch(len(self.train_loader))
|
84 |
|
85 |
def training_step(self, batch, batch_idx):
|
86 |
-
self.trainer.optimizers[0].next_batch()
|
87 |
batch_size, images, targets, *_ = batch
|
88 |
predicts = self(images)
|
89 |
aux_predicts = self.vec2box(predicts["AUX"])
|
@@ -97,6 +97,7 @@ class TrainModel(ValidateModel):
|
|
97 |
batch_size=batch_size,
|
98 |
rank_zero_only=True,
|
99 |
)
|
|
|
100 |
return loss * batch_size
|
101 |
|
102 |
def configure_optimizers(self):
|
|
|
83 |
self.trainer.optimizers[0].next_epoch(len(self.train_loader))
|
84 |
|
85 |
def training_step(self, batch, batch_idx):
|
86 |
+
lr_dict = self.trainer.optimizers[0].next_batch()
|
87 |
batch_size, images, targets, *_ = batch
|
88 |
predicts = self(images)
|
89 |
aux_predicts = self.vec2box(predicts["AUX"])
|
|
|
97 |
batch_size=batch_size,
|
98 |
rank_zero_only=True,
|
99 |
)
|
100 |
+
self.log_dict(lr_dict, prog_bar=False, logger=True, on_epoch=False, rank_zero_only=True)
|
101 |
return loss * batch_size
|
102 |
|
103 |
def configure_optimizers(self):
|
yolo/utils/model_utils.py
CHANGED
@@ -65,9 +65,12 @@ def create_optimizer(model: YOLO, optim_cfg: OptimizerConfig) -> Optimizer:
|
|
65 |
|
66 |
def next_batch(self):
|
67 |
self.batch_idx += 1
|
|
|
68 |
for lr_idx, param_group in enumerate(self.param_groups):
|
69 |
min_lr, max_lr = self.min_lr[lr_idx], self.max_lr[lr_idx]
|
70 |
param_group["lr"] = min_lr + (self.batch_idx) * (max_lr - min_lr) / self.batch_num
|
|
|
|
|
71 |
|
72 |
optimizer_class.next_batch = next_batch
|
73 |
optimizer_class.next_epoch = next_epoch
|
|
|
65 |
|
66 |
def next_batch(self):
|
67 |
self.batch_idx += 1
|
68 |
+
lr_dict = dict()
|
69 |
for lr_idx, param_group in enumerate(self.param_groups):
|
70 |
min_lr, max_lr = self.min_lr[lr_idx], self.max_lr[lr_idx]
|
71 |
param_group["lr"] = min_lr + (self.batch_idx) * (max_lr - min_lr) / self.batch_num
|
72 |
+
lr_dict[f"LR/{lr_idx}"] = param_group["lr"]
|
73 |
+
return lr_dict
|
74 |
|
75 |
optimizer_class.next_batch = next_batch
|
76 |
optimizer_class.next_epoch = next_epoch
|