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

loading model clobbers existing logging configuration #10132

Closed
2 tasks done
rkechols opened this issue Nov 11, 2022 · 5 comments
Closed
2 tasks done

loading model clobbers existing logging configuration #10132

rkechols opened this issue Nov 11, 2022 · 5 comments
Labels
bug Something isn't working

Comments

@rkechols
Copy link
Contributor

Search before asking

  • I have searched the YOLOv5 issues and found no similar bug report.

YOLOv5 Component

PyTorch Hub

Bug

Loading this repository using torch.hub.load results in existing logger configurations being partially clobbered. Specifically, upon loading this repository, the root logger has a new handler added to it which prints the log message to STDERR with no formatting. Additionally, the root logger level is set to either INFO or ERROR (depending on parameters and environment variables).

Environment

  • YOLOv5 🚀 v6.2-237-g55e9516 Python-3.9.11 torch-1.12.1 CPU
  • OS: macOS 13.0 (22A380)

Minimal Reproducible Example

import logging
import logging.config
import torch

logging.config.dictConfig({
    "version": 1,
    "formatters": {
        "formatter_default": {
            "format": "%(asctime)s - %(levelname)8s - %(name)s - %(message)s"
        },
    },
    "handlers": {
        "handler_stdout": {
            "class": "logging.StreamHandler",
            "formatter": "formatter_default",
            "level": "DEBUG",
            "stream": "ext://sys.stdout",
        },
    },
    "loggers": {
        "my.unrelated.logger": {
            "level": "DEBUG"
        },
        "yolov5": {
            "level": "CRITICAL"
        },
    },
    "root": {
        "level": "INFO",
        "handlers": [
            "handler_stdout",
        ],
    },
})
UNRELATED_LOGGER = logging.getLogger("my.unrelated.logger")


def log_test(message: str):
    UNRELATED_LOGGER.debug(message)
    UNRELATED_LOGGER.info(message)
    UNRELATED_LOGGER.warning(message)
    UNRELATED_LOGGER.error(message)
    UNRELATED_LOGGER.critical(message)
    for handler_ref in logging._handlerList:
        handler_ref().flush()


log_test("before torch.hub.load")

model = torch.hub.load(
    "ultralytics/yolov5",  # commit tested: 55e95168465b094733e3ef1ec36e0a18f200cd94
    "yolov5s",
    trust_repo=True,
    pretrained=False,  # just download and load the repo; no specific weights needed
    device="cpu",
    verbose=False,
)

log_test("after torch.hub.load")

Note that above produces the following to STDOUT and STDERR respectively:

STDOUT:

2022-11-11 10:46:00,781 -    DEBUG - my.unrelated.logger - before torch.hub.load
2022-11-11 10:46:00,782 -     INFO - my.unrelated.logger - before torch.hub.load
2022-11-11 10:46:00,782 -  WARNING - my.unrelated.logger - before torch.hub.load
2022-11-11 10:46:00,782 -    ERROR - my.unrelated.logger - before torch.hub.load
2022-11-11 10:46:00,782 - CRITICAL - my.unrelated.logger - before torch.hub.load
2022-11-11 10:46:02,888 -    DEBUG - my.unrelated.logger - after torch.hub.load
2022-11-11 10:46:02,888 -     INFO - my.unrelated.logger - after torch.hub.load
2022-11-11 10:46:02,888 -  WARNING - my.unrelated.logger - after torch.hub.load
2022-11-11 10:46:02,888 -    ERROR - my.unrelated.logger - after torch.hub.load
2022-11-11 10:46:02,888 - CRITICAL - my.unrelated.logger - after torch.hub.load

STDERR:

after torch.hub.load
after torch.hub.load
after torch.hub.load
after torch.hub.load

According to my configuration for my.unrelated.logger, STDERR should not receive any messages from my.unrelated.logger.

Additional

Separate from this actual bug is the fact that the repo is trying to set logging configurations in imported code. Logging configurations should only be set by the python program's direct entrypoint. Setting logging configurations in packages, libraries, imported modules, etc. removes logging control from top-level code.

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!
@rkechols rkechols added the bug Something isn't working label Nov 11, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Nov 11, 2022

👋 Hello @rkechols, thank you for your interest in YOLOv5 🚀! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

If this is a 🐛 Bug Report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available.

For business inquiries or professional support requests please visit https://ultralytics.com or email support@ultralytics.com.

Requirements

Python>=3.7.0 with all requirements.txt installed including PyTorch>=1.7. To get started:

git clone https://github.com/ultralytics/yolov5  # clone
cd yolov5
pip install -r requirements.txt  # install

Environments

YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

YOLOv5 CI

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training, validation, inference, export and benchmarks on MacOS, Windows, and Ubuntu every 24 hours and on every commit.

@glenn-jocher
Copy link
Member

@rkechols got it, thank you! I see your PR, I'll move the convo there.

@rkechols
Copy link
Contributor Author

Related PR fix (#10133) has been merged.

@rkechols
Copy link
Contributor Author

Related PR fix (#10192) has been merged.

@glenn-jocher
Copy link
Member

@rkechols awesome, thanks for letting me know! If you need any further assistance, feel free to reach out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants