Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🩹Minor fixes #1788

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/anomalib/callbacks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,4 @@ def get_callbacks(config: DictConfig | ListConfig | Namespace) -> list[Callback]
),
)

# Add callback to log graph to loggers
# TODO(ashwinvaidya17): Find location for log_graph key
# CVS-122658
# if config.logging.log_graph not in (None, False):

return callbacks
2 changes: 0 additions & 2 deletions src/anomalib/callbacks/thresholding.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,6 @@ def _reset(self, pl_module: AnomalyModule) -> None:
pl_module.pixel_threshold.reset()

def _outputs_to_cpu(self, output: STEP_OUTPUT) -> STEP_OUTPUT | dict[str, Any]:
# TODO(ashwinvaidya17): This is duplicated in multiple trainer callbacks.
# CVS-122664
if isinstance(output, dict):
for key, value in output.items():
output[key] = self._outputs_to_cpu(value)
Expand Down
2 changes: 0 additions & 2 deletions src/anomalib/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,6 @@ def add_arguments_to_parser(self, parser: ArgumentParser) -> None:
)
parser.add_argument("--results_dir.unique", type=bool, help="Whether to create a unique folder.", default=False)
parser.link_arguments("results_dir.path", "trainer.default_root_dir")
# TODO(ashwinvaidya17): Tiling should also be a category of its own
# CVS-122659

def add_trainer_arguments(self, parser: ArgumentParser, subcommand: str) -> None:
"""Add train arguments to the parser."""
Expand Down
104 changes: 3 additions & 101 deletions src/anomalib/loggers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@


import logging
from pathlib import Path

from omegaconf.dictconfig import DictConfig
from omegaconf.listconfig import ListConfig
from rich.logging import RichHandler

__all__ = [
Expand All @@ -17,11 +14,9 @@
]

try:
from lightning.pytorch.loggers import CSVLogger, Logger

from .comet import AnomalibCometLogger
from .tensorboard import AnomalibTensorBoardLogger
from .wandb import AnomalibWandbLogger
from .comet import AnomalibCometLogger # noqa: F401
from .tensorboard import AnomalibTensorBoardLogger # noqa: F401
from .wandb import AnomalibWandbLogger # noqa: F401

__all__.extend(
[
Expand All @@ -34,16 +29,6 @@
print("To use any logger install it using `anomalib install -v`")


AVAILABLE_LOGGERS = ["tensorboard", "wandb", "csv", "comet"]


logger = logging.getLogger(__name__)


class UnknownLoggerError(Exception):
"""Raised when the logger option in `config.yaml` file is set incorrectly."""


def configure_logger(level: int | str = logging.INFO) -> None:
"""Get console logger by name.

Expand All @@ -65,86 +50,3 @@ def configure_logger(level: int | str = logging.INFO) -> None:
handler.setFormatter(logging.Formatter(format_string))
handler.setLevel(level)
logging.getLogger("lightning.pytorch").addHandler(RichHandler(rich_tracebacks=True))


def get_experiment_logger(
config: DictConfig | ListConfig,
) -> list | bool:
"""Return a logger based on the choice of logger in the config file.

Args:
config (DictConfig): config.yaml file for the corresponding anomalib model.

Raises:
ValueError: for any logger types apart from false and tensorboard

Returns:
list[Logger] | bool: Logger
"""
logger.info("Loading the experiment logger(s)")

if "logger" not in config.trainer or config.trainer.logger in (None, False):
return False

logger_list: list[Logger] = []
if isinstance(config.trainer.logger, str):
config.trainer.logger = [config.trainer.logger]

for experiment_logger in config.trainer.logger:
if experiment_logger == "tensorboard":
logger_list.append(
AnomalibTensorBoardLogger(
name="Tensorboard Logs",
save_dir=str(Path(config.project.path) / "logs"),
# TODO(ashwinvaidya17): Find location for log_graph key
# CVS-122658
log_graph=False,
),
)
elif experiment_logger == "wandb":
wandb_logdir = str(Path(config.project.path) / "logs")
Path(wandb_logdir).mkdir(parents=True, exist_ok=True)
name = (
config.model.class_path.split(".")[-1]
if "category" not in config.data.init_args
else f"{config.data.init_args.category} {config.model.class_path.split('.')[-1]}"
)
logger_list.append(
AnomalibWandbLogger(
project=config.data.class_path.split(".")[-1],
name=name,
save_dir=wandb_logdir,
),
)
elif experiment_logger == "comet":
comet_logdir = str(Path(config.project.path) / "logs")
Path(comet_logdir).mkdir(parents=True, exist_ok=True)
run_name = (
config.model.name
if "category" not in config.data.init_args
else f"{config.data.init_args.category} {config.model.class_path.split('.')[-1]}"
)
logger_list.append(
AnomalibCometLogger(
project_name=config.data.class_path.split(".")[-1],
experiment_name=run_name,
save_dir=comet_logdir,
),
)
elif experiment_logger == "csv":
logger_list.append(CSVLogger(save_dir=Path(config.project.path) / "logs"))
else:
msg = (
f"Unknown logger type: {config.trainer.logger}. Available loggers are: {AVAILABLE_LOGGERS}.\n"
"To enable the logger, set `project.logger` to `true` or use one of available loggers in "
"config.yaml\nTo disable the logger, set `project.logger` to `false`."
)
raise UnknownLoggerError(
msg,
)

# TODO(ashwinvaidya17): Remove this method and set these values in ``update_config``
# CVS-122657
del config.trainer.logger

return logger_list
3 changes: 0 additions & 3 deletions src/anomalib/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
# Copyright (C) 2022-2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

# TODO(ashwinvaidya17): This would require a new design.
# https://jira.devtools.intel.com/browse/IAAALD-149


import inspect
import logging
Expand Down
4 changes: 0 additions & 4 deletions tests/unit/loggers/__init__.py

This file was deleted.

102 changes: 0 additions & 102 deletions tests/unit/loggers/test_get_logger.py

This file was deleted.

Loading