2020-12-22 21:25:37 +00:00
|
|
|
# ClearML - Example of manual graphs and statistics reporting
|
2020-06-15 19:48:51 +00:00
|
|
|
#
|
2020-12-10 07:41:31 +00:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2020-06-15 19:48:51 +00:00
|
|
|
import logging
|
|
|
|
import sys
|
|
|
|
|
2020-11-17 21:07:16 +00:00
|
|
|
import six
|
|
|
|
|
2020-12-22 21:25:37 +00:00
|
|
|
from clearml import Logger, Task
|
2020-06-15 19:48:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
def report_logs(logger):
|
|
|
|
# type: (Logger) -> ()
|
|
|
|
"""
|
|
|
|
reporting text to logs section
|
|
|
|
:param logger: The task.logger to use for sending the text
|
|
|
|
"""
|
|
|
|
# standard python logging
|
|
|
|
logging.info("This is an info message")
|
|
|
|
|
|
|
|
# this is a loguru test example
|
|
|
|
try:
|
2020-11-17 21:07:16 +00:00
|
|
|
from loguru import logger as loguru_logger # noqa
|
2020-06-15 19:48:51 +00:00
|
|
|
|
2020-11-17 21:07:16 +00:00
|
|
|
loguru_logger.info(
|
|
|
|
"That's it, beautiful and simple logging! (using ANSI colors)"
|
|
|
|
)
|
2020-06-15 19:48:51 +00:00
|
|
|
except ImportError:
|
2020-11-17 21:07:16 +00:00
|
|
|
print("loguru not installed, skipping loguru test")
|
2020-06-15 19:48:51 +00:00
|
|
|
|
|
|
|
# report text
|
|
|
|
logger.report_text("hello, this is plain text")
|
|
|
|
|
|
|
|
|
2020-11-17 21:07:16 +00:00
|
|
|
def report_debug_text(logger):
|
|
|
|
# type: (Logger) -> ()
|
|
|
|
"""
|
|
|
|
reporting text to debug sample section
|
|
|
|
:param logger: The task.logger to use for sending the sample
|
|
|
|
"""
|
|
|
|
text_to_send = """
|
|
|
|
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
|
|
|
Suspendisse ac justo ut dolor scelerisque posuere.
|
|
|
|
Donec hendrerit, purus viverra congue maximus, neque orci vehicula elit, pulvinar elementum diam lorem ut arcu.
|
|
|
|
Sed convallis ipsum justo. Duis faucibus consectetur cursus. Morbi eleifend nisl vel maximus dapibus.
|
|
|
|
Vestibulum commodo justo eget tellus interdum dapibus. Curabitur pulvinar nibh vitae orci laoreet, id sodales justo ultrices.
|
|
|
|
Etiam mollis dui et viverra ultrices. Vestibulum vitae molestie libero, quis lobortis risus. Morbi venenatis quis odio nec efficitur.
|
|
|
|
Vestibulum dictum ipsum at viverra ultrices. Aliquam sed ante massa. Quisque convallis libero in orci fermentum tincidunt.
|
|
|
|
"""
|
|
|
|
logger.report_media(
|
|
|
|
title="text title",
|
|
|
|
series="text series",
|
|
|
|
iteration=1,
|
|
|
|
stream=six.StringIO(text_to_send),
|
|
|
|
file_extension=".txt",
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-06-15 19:48:51 +00:00
|
|
|
def main():
|
|
|
|
# Create the experiment Task
|
|
|
|
task = Task.init(project_name="examples", task_name="text reporting")
|
|
|
|
|
2020-11-17 21:07:16 +00:00
|
|
|
print("reporting text logs")
|
2020-06-15 19:48:51 +00:00
|
|
|
|
|
|
|
# report regular console print
|
2020-11-17 21:07:16 +00:00
|
|
|
print("This is standard output test")
|
2020-06-15 19:48:51 +00:00
|
|
|
|
|
|
|
# report stderr
|
2020-11-17 21:07:16 +00:00
|
|
|
print("This is standard error test", file=sys.stderr)
|
2020-06-15 19:48:51 +00:00
|
|
|
|
|
|
|
# Get the task logger,
|
|
|
|
# You can also call Task.current_task().get_logger() from anywhere in your code.
|
|
|
|
logger = task.get_logger()
|
|
|
|
|
|
|
|
# report text based logs
|
|
|
|
report_logs(logger)
|
|
|
|
|
2020-11-17 21:07:16 +00:00
|
|
|
# report text as debug example
|
|
|
|
report_debug_text(logger)
|
|
|
|
|
2020-06-15 19:48:51 +00:00
|
|
|
# force flush reports
|
|
|
|
# If flush is not called, reports are flushed in the background every couple of seconds,
|
|
|
|
# and at the end of the process execution
|
|
|
|
logger.flush()
|
|
|
|
|
2020-11-17 21:07:16 +00:00
|
|
|
print("We are done reporting, have a great day :)")
|
2020-06-15 19:48:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|