-
-
Notifications
You must be signed in to change notification settings - Fork 16.6k
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
Is there a way to hide/suppress any console output when loading and inferencing via PyTorch Hub? #2862
Comments
👋 Hello @haimat, 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://www.ultralytics.com or email Glenn Jocher at glenn.jocher@ultralytics.com. RequirementsPython 3.8 or later with all requirements.txt dependencies installed, including $ pip install -r requirements.txt EnvironmentsYOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):
StatusIf this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training (train.py), testing (test.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu every 24 hours and on every commit. |
@haimat yes we probably want to group these outputs into a verbose=True setting. If you'd like to update the PyTorch Hub model code for this and submit a PR that would be awesome! If not we can add this to our TODO queue, which is very long at the moment. |
@haimat see https://github.com/ultralytics/yolov5/blob/master/hubconf.py for the right place to start. Lines 1 to 7 in 1df8c6c
|
@glenn-jocher Well, for now I always worked with TF and Keras, so this is my first project with PyTorch and its hub. This YOLOv5 project is pretty cool though and I am always willing to learn something new, so why not, I can give this change a try. But could you please be so kind and give me just a few hints where to start and how you would like to have this change? I am totally fine with Python in general and these things, I would just like to know what you would have in mind, so that my change can reflect that. Thanks in advance! |
@haimat well, there's two ways of managing the output, either with The first is pretty simple, but will require a lot of code changes, plus passing the verbose value through several functions to all of the places that currently print/log output, which would be a hassle. The main place where the model architecture is printed as it's built is here: Lines 201 to 202 in 1df8c6c
|
@glenn-jocher Ok thanks, I will have a look at thia. One more thing though: When I update the logging logic e.g. for the |
@haimat ah well yes once we merge a PR, new operations with the same Hub cache would be unaffected unless the Hub cache is updated with But also detect.py is mostly a separate inference channel from pytorch hub. |
Hi, speaking of the first method that Glenn mentioned, maybe we can rework the logging logic a bit? It was left untouched for a while. Lines 33 to 36 in 1df8c6c
Maybe we can a def set_logging(rank=-1, verbose=True):
logging.basicConfig(
format="%(message)s",
level=logging.INFO if (verbose and rank in [-1, 0]) else logging.WARN) Lines 28 to 29 in 1df8c6c
The only thing to note is that if |
@NanoCode012 yeah I think this is a great idea. I wonder if there's a way to pair this with a global verbose variable or an environment variable somehow so any function could set verbose=False and the other functions/files would be faithful to the change. |
I was thinking of utilizing Python's logging functionalities. How about passing the log level (like "error", "warning", "info") to the script, and based on that more or less logging will be printed. And all that comes for free if we replace all |
@haimat @NanoCode012 yes these are both good ideas. I've added a TODO label here to remind ourselves to get to this eventually, but I don't have much availability for this and the priority is not high, so it may take a while. If either of you want to take a stab at it feel free to submit a PR, thank you! |
@haimat good news 😃! Your original issue may now been fixed ✅ in PR #2926 by @NanoCode012. To receive this update you can:
Thank you for spotting this issue and informing us of the problem. Please let us know if this update resolves the issue for you, and feel free to inform us of any other issues you discover or feature requests that come to mind. Happy trainings with YOLOv5 🚀! |
Removing TODO as this is partly resolved now by avoiding model construction during most PyTorch Hub model loads. |
👋 Hello, this issue has been automatically marked as stale because it has not had recent activity. Please note it will be closed if no further activity occurs. Access additional YOLOv5 🚀 resources:
Access additional Ultralytics ⚡ resources:
Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed! Thank you for your contributions to YOLOv5 🚀 and Vision AI ⭐! |
Hi, I have switched to the |
Hi, for those who want no logs at all, you can use this piece of code:
This is probably not the most intuitive logger name though. |
@JonathanSamelson thanks for the tip! Where would this code be placed? Before or after importing LOGGER from utils.general? @kalenmike example of eliminating all YOLOv5 logs in #2862 (comment) This might be useful for creating a global verbose mode. |
I simply use it at the very beginning of my code. Since I wanted to infer the results without anything printed in the console. For instance:
Usually it works with other loggers, but they have a more explicit name:
However I saw that this is setup with |
@JonathanSamelson ah ok got it. Is there anyway to rename the logger? i.e. to something like this? logging.getLogger("yolov5").setLevel(logging.WARNING) BTW we just did a PR #6353 that sets export VERBOSE=False
python detect.py |
@glenn-jocher Yes, there is. Instead of :
I'd simply use:
And I think that's it because internally you probably import LOGGER everytime you use it. Externally you would change the log level exactly has you mentionned:
I don't mind opening/amending a PR but as I'm very new to this project I don't know if there is any other impacts or what has been done exactly with the VERBOSE environment variable. |
@JonathanSamelson oh perfect! That seems like an easy change. Can you check that this doesn't alter the current logging output and then please submit a PR with this fix? |
Here we go @glenn-jocher : #6421 |
@JonathanSamelson thank you, PR is merged! |
❔Question
I would like to use YOLOv5 in a custom project, so I need to be in control of what will be printed to the console. Currently I am loading the model and using it like described in your wiki:
However, these line result in some console output (like network layout, autoShape info, etc.)
Is there any way to hide all these standad console output?
The text was updated successfully, but these errors were encountered: