mirror of
https://github.com/clearml/clearml
synced 2025-05-04 13:02:13 +00:00
Add support for reporting tables
This commit is contained in:
parent
1043c22d0a
commit
98c9a95338
@ -14,7 +14,7 @@ from ..setupuploadmixin import SetupUploadMixin
|
|||||||
from ...utilities.async_manager import AsyncManagerMixin
|
from ...utilities.async_manager import AsyncManagerMixin
|
||||||
from ...utilities.plotly_reporter import create_2d_histogram_plot, create_value_matrix, create_3d_surface, \
|
from ...utilities.plotly_reporter import create_2d_histogram_plot, create_value_matrix, create_3d_surface, \
|
||||||
create_2d_scatter_series, create_3d_scatter_series, create_line_plot, plotly_scatter3d_layout_dict, \
|
create_2d_scatter_series, create_3d_scatter_series, create_line_plot, plotly_scatter3d_layout_dict, \
|
||||||
create_image_plot
|
create_image_plot, create_plotly_table
|
||||||
from ...utilities.py3_interop import AbstractContextManager
|
from ...utilities.py3_interop import AbstractContextManager
|
||||||
from .events import ScalarEvent, VectorEvent, ImageEvent, PlotEvent, ImageEventNoUpload, UploadEvent
|
from .events import ScalarEvent, VectorEvent, ImageEvent, PlotEvent, ImageEventNoUpload, UploadEvent
|
||||||
|
|
||||||
@ -272,6 +272,27 @@ class Reporter(InterfaceBase, AbstractContextManager, SetupUploadMixin, AsyncMan
|
|||||||
iter=iter,
|
iter=iter,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def report_table(self, title, series, table, iteration):
|
||||||
|
"""
|
||||||
|
Report a table plot.
|
||||||
|
|
||||||
|
:param title: Title (AKA metric)
|
||||||
|
:type title: str
|
||||||
|
:param series: Series (AKA variant)
|
||||||
|
:type series: str
|
||||||
|
:param table: The table data
|
||||||
|
:type table: pandas.DataFrame
|
||||||
|
:param iteration: Iteration number
|
||||||
|
:type iteration: int
|
||||||
|
"""
|
||||||
|
table_output = create_plotly_table(table, title, series)
|
||||||
|
return self.report_plot(
|
||||||
|
title=self._normalize_name(title),
|
||||||
|
series=self._normalize_name(series),
|
||||||
|
plot=table_output,
|
||||||
|
iter=iteration,
|
||||||
|
)
|
||||||
|
|
||||||
def report_line_plot(self, title, series, iter, xtitle, ytitle, mode='lines', reverse_xaxis=False, comment=None):
|
def report_line_plot(self, title, series, iter, xtitle, ytitle, mode='lines', reverse_xaxis=False, comment=None):
|
||||||
"""
|
"""
|
||||||
Report a (possibly multiple) line plot.
|
Report a (possibly multiple) line plot.
|
||||||
|
@ -2,6 +2,12 @@ import logging
|
|||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import six
|
||||||
|
|
||||||
|
try:
|
||||||
|
import pandas as pd
|
||||||
|
except ImportError:
|
||||||
|
pd = None
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from pathlib2 import Path
|
from pathlib2 import Path
|
||||||
|
|
||||||
@ -140,6 +146,49 @@ class Logger(object):
|
|||||||
ytitle=yaxis,
|
ytitle=yaxis,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def report_table(self, title, series, iteration, table_plot=None, csv=None, url=None):
|
||||||
|
"""
|
||||||
|
Report a table plot.
|
||||||
|
|
||||||
|
:param title: Title (AKA metric)
|
||||||
|
:type title: str
|
||||||
|
:param series: Series (AKA variant)
|
||||||
|
:type series: str
|
||||||
|
:param iteration: Iteration number
|
||||||
|
:type iteration: int
|
||||||
|
:param table_plot: The output table plot object
|
||||||
|
:type table_plot: pandas.DataFrame
|
||||||
|
:param csv: path to local csv file
|
||||||
|
:type csv: str
|
||||||
|
:param url: A URL to the location of csv file.
|
||||||
|
:type url: str
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
:paramref:`~.Logger.report_table.table_plot`, :paramref:`~.Logger.report_table.csv`
|
||||||
|
and :paramref:`~.Logger.report_table.url' are mutually exclusive, and at least one must be provided.
|
||||||
|
"""
|
||||||
|
mutually_exclusive(
|
||||||
|
UsageError, _check_none=True,
|
||||||
|
table_plot=table_plot, csv=csv, url=url
|
||||||
|
)
|
||||||
|
table = table_plot
|
||||||
|
if url or csv:
|
||||||
|
if not pd:
|
||||||
|
raise UsageError(
|
||||||
|
"pandas is required in order to support reporting tables using CSV or a URL, please install the pandas python package"
|
||||||
|
)
|
||||||
|
if url:
|
||||||
|
table = pd.read_csv(url)
|
||||||
|
elif csv:
|
||||||
|
table = pd.read_csv(csv)
|
||||||
|
|
||||||
|
return self._task.reporter.report_table(
|
||||||
|
title=title,
|
||||||
|
series=series,
|
||||||
|
table=table,
|
||||||
|
iteration=iteration
|
||||||
|
)
|
||||||
|
|
||||||
def report_line_plot(self, title, series, iteration, xaxis, yaxis, mode='lines',
|
def report_line_plot(self, title, series, iteration, xaxis, yaxis, mode='lines',
|
||||||
reverse_xaxis=False, comment=None):
|
reverse_xaxis=False, comment=None):
|
||||||
"""
|
"""
|
||||||
|
@ -1,4 +1,11 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
|
from ..errors import UsageError
|
||||||
|
|
||||||
|
try:
|
||||||
|
import pandas as pd
|
||||||
|
except ImportError:
|
||||||
|
pd = None
|
||||||
from attr import attrs, attrib
|
from attr import attrs, attrib
|
||||||
|
|
||||||
|
|
||||||
@ -412,3 +419,51 @@ def plotly_scatter3d_layout_dict(title="Scatter", xaxis_title="X", yaxis_title="
|
|||||||
"name": series,
|
"name": series,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def create_plotly_table(table_plot, title, series):
|
||||||
|
"""
|
||||||
|
Create a basic Plotly table json style to be sent
|
||||||
|
|
||||||
|
:param table_plot: the output table in pandas.DataFrame structure
|
||||||
|
:return: dict with plotly data
|
||||||
|
:param title: Title (AKA metric)
|
||||||
|
:type title: str
|
||||||
|
:param series: Series (AKA variant)
|
||||||
|
:type series: str
|
||||||
|
"""
|
||||||
|
if not pd:
|
||||||
|
raise UsageError(
|
||||||
|
"pandas is required in order to support reporting tables using CSV or a URL, please install the pandas python package"
|
||||||
|
)
|
||||||
|
index_added = not isinstance(table_plot.index, pd.RangeIndex)
|
||||||
|
headers_values = list([col] for col in table_plot.columns)
|
||||||
|
cells_values = table_plot.T.values.tolist()
|
||||||
|
if index_added:
|
||||||
|
headers_values.insert(0, "")
|
||||||
|
cells_values.insert(0, table_plot.index.values.tolist())
|
||||||
|
|
||||||
|
ret = {
|
||||||
|
"data": [{
|
||||||
|
'type': 'table',
|
||||||
|
'header': {
|
||||||
|
'values': headers_values,
|
||||||
|
'align': "left",
|
||||||
|
'line': {'width': 0.5, 'color': '#d4d6e0'},
|
||||||
|
'fill': {'color': "#fff"},
|
||||||
|
'font': {'family': "Heebo, verdana, arial, sans-serif", 'size': 12, 'color': "#333"}
|
||||||
|
},
|
||||||
|
'cells': {
|
||||||
|
'height': 30,
|
||||||
|
'values': cells_values,
|
||||||
|
'align': "left",
|
||||||
|
'line': {'color': "white", 'width': 1},
|
||||||
|
'font': {'family': "Heebo, verdana, arial, sans-serif", 'size': 14, 'color': "#384161"},
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
"layout": {
|
||||||
|
"title": title,
|
||||||
|
"name": series,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
Loading…
Reference in New Issue
Block a user