clearml/examples/manual_reporting.py

66 lines
2.5 KiB
Python
Raw Normal View History

2019-06-10 17:00:28 +00:00
# TRAINS - Example of manual graphs and statistics reporting
#
import os
2019-10-10 17:33:58 +00:00
from PIL import Image
2019-06-10 17:00:28 +00:00
import numpy as np
import logging
from trains import Task
task = Task.init(project_name="examples", task_name="Manual reporting")
2019-06-10 17:00:28 +00:00
2019-08-06 21:05:24 +00:00
# standard python logging
logging.info("This is an info message")
2019-06-10 17:00:28 +00:00
# this is loguru test example
try:
from loguru import logger
2019-08-19 18:26:29 +00:00
logger.info("That's it, beautiful and simple logging! (using ANSI colors)")
except ImportError:
pass
2019-06-10 17:00:28 +00:00
# get TRAINS logger object for any metrics / reports
2019-08-06 21:05:24 +00:00
logger = Task.current_task().get_logger()
2019-06-10 17:00:28 +00:00
# log text
logger.report_text("hello")
2019-06-10 17:00:28 +00:00
# report scalar values
logger.report_scalar("example_scalar", "series A", iteration=0, value=100)
logger.report_scalar("example_scalar", "series A", iteration=1, value=200)
# report histogram
histogram = np.random.randint(10, size=10)
logger.report_histogram("example_histogram", "random histogram", iteration=1, values=histogram,
xaxis="title x", yaxis="title y")
2019-06-10 17:00:28 +00:00
# report confusion matrix
confusion = np.random.randint(10, size=(10, 10))
logger.report_matrix("example_confusion", "ignored", iteration=1, matrix=confusion, xaxis="title X", yaxis="title Y")
2019-06-10 17:00:28 +00:00
2019-08-19 18:26:29 +00:00
# report 3d surface
logger.report_surface("example_surface", "series1", iteration=1, matrix=confusion,
xaxis="title X", yaxis="title Y", zaxis="title Z")
2019-08-19 18:26:29 +00:00
2019-06-10 17:00:28 +00:00
# report 2d scatter plot
scatter2d = np.hstack((np.atleast_2d(np.arange(0, 10)).T, np.random.randint(10, size=(10, 1))))
logger.report_scatter2d("example_scatter", "series_xy", iteration=1, scatter=scatter2d,
xaxis="title x", yaxis="title y")
2019-06-10 17:00:28 +00:00
# report 3d scatter plot
scatter3d = np.random.randint(10, size=(10, 3))
logger.report_scatter3d("example_scatter_3d", "series_xyz", iteration=1, scatter=scatter3d,
xaxis="title x", yaxis="title y", zaxis="title z")
2019-06-10 17:00:28 +00:00
2019-08-19 18:26:29 +00:00
# reporting images
2019-06-10 17:00:28 +00:00
m = np.eye(256, 256, dtype=np.float)
2019-10-10 17:33:58 +00:00
logger.report_image("test case", "image float", iteration=1, image=m)
m = np.eye(256, 256, dtype=np.uint8)*255
2019-10-10 17:33:58 +00:00
logger.report_image("test case", "image uint8", iteration=1, image=m)
m = np.concatenate((np.atleast_3d(m), np.zeros((256, 256, 2), dtype=np.uint8)), axis=2)
2019-10-10 17:33:58 +00:00
logger.report_image("test case", "image color red", iteration=1, image=m)
image_open = Image.open(os.path.join("samples", "picasso.jpg"))
2019-10-10 17:33:58 +00:00
logger.report_image("test case", "image PIL", iteration=1, image=image_open)
2019-06-10 17:00:28 +00:00
# flush reports (otherwise it will be flushed in the background, every couple of seconds)
logger.flush()