Skip to content

Commit

Permalink
removing new logger and lint error
Browse files Browse the repository at this point in the history
  • Loading branch information
Im-Himanshu committed Jul 5, 2024
1 parent e304a2a commit a2a55bc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
5 changes: 3 additions & 2 deletions yolox/core/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,15 @@ def after_train(self):
if self.args.logger == "wandb":
self.wandb_logger.finish()
elif self.args.logger == "mlflow":
metadata={
metadata = {
"epoch": self.epoch + 1,
"input_size": self.input_size,
'start_ckpt': self.args.ckpt,
'exp_file': self.args.exp_file,
"best_ap": float(self.best_ap)
}
self.mlflow_logger.on_train_end(self.args, file_name=self.file_name, metadata=metadata)
self.mlflow_logger.on_train_end(self.args, file_name=self.file_name,
metadata=metadata)

def before_epoch(self):
logger.info("---> start train epoch{}".format(self.epoch + 1))
Expand Down
4 changes: 0 additions & 4 deletions yolox/utils/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,8 @@ def setup_logger(save_dir, distributed_rank=0, filename="log.txt", mode="a"):

logger.remove()
save_file = os.path.join(save_dir, filename)
crnt_log_save_file = os.path.join(save_dir, 'train_log_crnt.txt')
if mode == "o" and os.path.exists(save_file):
os.remove(save_file)
if os.path.exists(crnt_log_save_file):
os.remove(crnt_log_save_file)
# only keep logger in rank0 process
if distributed_rank == 0:
logger.add(
Expand All @@ -112,7 +109,6 @@ def setup_logger(save_dir, distributed_rank=0, filename="log.txt", mode="a"):
enqueue=True,
)
logger.add(save_file)
logger.add(crnt_log_save_file)

# redirect stdout/stderr to loguru
redirect_sys_output("INFO")
Expand Down
12 changes: 6 additions & 6 deletions yolox/utils/mlflow_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
from loguru import logger
import torch
from yolox.utils import is_main_process


class MlflowLogger:
"""
Main Mlflow logging class to log hyperparameters, metrics, and models to Mlflow.
Expand Down Expand Up @@ -156,10 +158,8 @@ def setup(self, args, exp):
self._mlflow_log_model_per_n_epochs = int(os.getenv(
"YOLOX_MLFLOW_LOG_MODEL_PER_n_EPOCHS", 30))

self._mlflow_log_nth_epoch_models = os.getenv(
"YOLOX_MLFLOW_LOG_Nth_EPOCH_MODELS", "False").upper() in \
self.ENV_VARS_TRUE_VALUES

self._mlflow_log_nth_epoch_models = os.getenv("YOLOX_MLFLOW_LOG_Nth_EPOCH_MODELS",
"False").upper() in self.ENV_VARS_TRUE_VALUES
self.run_name = os.getenv("YOLOX_MLFLOW_RUN_NAME", None)
self.run_name = None if len(self.run_name.strip()) == 0 else self.run_name
self._flatten_params = os.getenv("YOLOX_MLFLOW_FLATTEN_PARAMS",
Expand Down Expand Up @@ -283,7 +283,7 @@ def on_log(self, args, exp, step, logs):
Returns:
None
"""
#step = trainer.progress_in_iter
# step = trainer.progress_in_iter
if not self._initialized:
self.setup(args, exp)
if is_main_process(): # master thread only
Expand Down Expand Up @@ -340,7 +340,7 @@ def save_log_file(self, args, file_name):
Returns:
None
"""
log_file_path = os.path.join(file_name, "train_log_crnt.txt")
log_file_path = os.path.join(file_name, "train_log.txt")
mlflow_out_dir = f"{args.experiment_name}"
logger.info(f"Logging logfile: {log_file_path} in mlflow artifact path: {mlflow_out_dir}.")
self._ml_flow.log_artifact(log_file_path, mlflow_out_dir)
Expand Down

0 comments on commit a2a55bc

Please sign in to comment.