Unanswered
Hello :slightly_smiling_face:
I am having issues persisting output images to a self-hosted clearml server. When I use the matplotlib automagical hooks (with `plt.show()` ) I get empty images. I get the same empty images if I try to disable the hooks and u
Hello 🙂
I am having issues persisting output images to a self-hosted clearml server. When I use the matplotlib automagical hooks (with plt.show()
) I get empty images. I get the same empty images if I try to disable the hooks and use the manual logger.report_matplotlib_figure
methods. I can persist other plot types though; logger.report_confusion_matrix
saves with no issues.
Here is a script that reproduces my issue:
import logging
import joblib
import pandas as pd
import matplotlib.pyplot as plt
from clearml import Task, TaskTypes
from sklearn import tree
from sklearn import datasets
from sklearn.metrics import ConfusionMatrixDisplay, confusion_matrix
from sklearn.model_selection import train_test_split
def preprocess(df: pd.DataFrame) -> tuple[any]:
X = df.loc[
:,
[
"sepal length (cm)",
"sepal width (cm)",
"petal length (cm)",
"petal width (cm)",
],
].to_numpy()
y = df.target
return (X, y)
def main():
task = Task.init(
project_name="Demo-Data",
task_name="iris_training",
task_type=TaskTypes.training,
tags=["demo", "iris"],
reuse_last_task_id=False,
output_uri=True,
auto_connect_frameworks={"matplotlib": False},
)
logger = task.get_logger()
iris_set = datasets.load_iris()
iris_df = pd.DataFrame(data=iris_set.data, columns=iris_set.feature_names).assign(
target=iris_set.target
)
train, test = train_test_split(iris_df, test_size=0.2)
model = tree.DecisionTreeClassifier().fit(*preprocess(train))
joblib.dump(model, "model.pkl") # persist model artifact using hooks
test_features, test_labels = preprocess(test)
predicted_labels = model.predict(test_features)
####persisting outputs####
fig, ax = plt.subplots()
cm = confusion_matrix(test_labels, predicted_labels)
ConfusionMatrixDisplay(cm).plot(ax=ax)
logger.report_text(
"trying to save an image", level=logging.DEBUG, print_console=False
)
logger.report_matplotlib_figure(
title="confusion_matrix",
series="mpl",
iteration=0,
figure=fig,
report_interactive=False,
)
logger.report_text(
"trying to save a confusion matrix", level=logging.DEBUG, print_console=False
)
logger.report_confusion_matrix(
title="confusion_matrix", series="direct_logging", iteration=0, matrix=cm
)
if __name__ == "__main__":
main()
120 Views
0
Answers
one month ago
one month ago
Tags