如何使用 wandb.log 在 wandb 中保存绘图?

问题描述 投票:0回答:2

我正在尝试使用 wandb.log 保存绘图。他们的文档说要做:

    wandb.log({"chart": plt})

但这对我来说失败了。

我收到两个错误,第一个错误(当我在尝试执行 wand.log 之前不执行

plt.show()
时):

Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydevd_bundle/pydevd_exec2.py", line 3, in Exec
    exec(exp, global_vars, local_vars)
  File "<input>", line 1, in <module>
  File "/Users/brandomiranda/opt/anaconda3/envs/meta_learning/lib/python3.9/site-packages/wandb/sdk/wandb_run.py", line 256, in wrapper
    return func(self, *args, **kwargs)
  File "/Users/brandomiranda/opt/anaconda3/envs/meta_learning/lib/python3.9/site-packages/wandb/sdk/wandb_run.py", line 222, in wrapper
    return func(self, *args, **kwargs)
  File "/Users/brandomiranda/opt/anaconda3/envs/meta_learning/lib/python3.9/site-packages/wandb/sdk/wandb_run.py", line 1548, in log
    self._log(data=data, step=step, commit=commit)
  File "/Users/brandomiranda/opt/anaconda3/envs/meta_learning/lib/python3.9/site-packages/wandb/sdk/wandb_run.py", line 1339, in _log
    self._partial_history_callback(data, step, commit)
  File "/Users/brandomiranda/opt/anaconda3/envs/meta_learning/lib/python3.9/site-packages/wandb/sdk/wandb_run.py", line 1228, in _partial_history_callback
    self._backend.interface.publish_partial_history(
  File "/Users/brandomiranda/opt/anaconda3/envs/meta_learning/lib/python3.9/site-packages/wandb/sdk/interface/interface.py", line 541, in publish_partial_history
    data = history_dict_to_json(run, data, step=user_step, ignore_copy_err=True)
  File "/Users/brandomiranda/opt/anaconda3/envs/meta_learning/lib/python3.9/site-packages/wandb/sdk/data_types/utils.py", line 54, in history_dict_to_json
    payload[key] = val_to_json(
  File "/Users/brandomiranda/opt/anaconda3/envs/meta_learning/lib/python3.9/site-packages/wandb/sdk/data_types/utils.py", line 82, in val_to_json
    val = Plotly.make_plot_media(val)
  File "/Users/brandomiranda/opt/anaconda3/envs/meta_learning/lib/python3.9/site-packages/wandb/sdk/data_types/plotly.py", line 48, in make_plot_media
    val = util.matplotlib_to_plotly(val)
  File "/Users/brandomiranda/opt/anaconda3/envs/meta_learning/lib/python3.9/site-packages/wandb/util.py", line 560, in matplotlib_to_plotly
    return tools.mpl_to_plotly(obj)
  File "/Users/brandomiranda/opt/anaconda3/envs/meta_learning/lib/python3.9/site-packages/plotly/tools.py", line 112, in mpl_to_plotly
    matplotlylib.Exporter(renderer).run(fig)
  File "/Users/brandomiranda/opt/anaconda3/envs/meta_learning/lib/python3.9/site-packages/plotly/matplotlylib/mplexporter/exporter.py", line 53, in run
    self.crawl_fig(fig)
  File "/Users/brandomiranda/opt/anaconda3/envs/meta_learning/lib/python3.9/site-packages/plotly/matplotlylib/mplexporter/exporter.py", line 124, in crawl_fig
    self.crawl_ax(ax)
  File "/Users/brandomiranda/opt/anaconda3/envs/meta_learning/lib/python3.9/site-packages/plotly/matplotlylib/mplexporter/exporter.py", line 146, in crawl_ax
    self.draw_collection(ax, collection)
  File "/Users/brandomiranda/opt/anaconda3/envs/meta_learning/lib/python3.9/site-packages/plotly/matplotlylib/mplexporter/exporter.py", line 289, in draw_collection
    offset_order = offset_dict[collection.get_offset_position()]
AttributeError: 'LineCollection' object has no attribute 'get_offset_position'

我收到两个错误,第二个错误(当我在尝试执行 wand.log 之前执行

plt.show()
时):

Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydevd_bundle/pydevd_exec2.py", line 3, in Exec
    exec(exp, global_vars, local_vars)
  File "<input>", line 1, in <module>
  File "/Users/brandomiranda/opt/anaconda3/envs/meta_learning/lib/python3.9/site-packages/wandb/sdk/wandb_run.py", line 256, in wrapper
    return func(self, *args, **kwargs)
  File "/Users/brandomiranda/opt/anaconda3/envs/meta_learning/lib/python3.9/site-packages/wandb/sdk/wandb_run.py", line 222, in wrapper
    return func(self, *args, **kwargs)
  File "/Users/brandomiranda/opt/anaconda3/envs/meta_learning/lib/python3.9/site-packages/wandb/sdk/wandb_run.py", line 1548, in log
    self._log(data=data, step=step, commit=commit)
  File "/Users/brandomiranda/opt/anaconda3/envs/meta_learning/lib/python3.9/site-packages/wandb/sdk/wandb_run.py", line 1339, in _log
    self._partial_history_callback(data, step, commit)
  File "/Users/brandomiranda/opt/anaconda3/envs/meta_learning/lib/python3.9/site-packages/wandb/sdk/wandb_run.py", line 1228, in _partial_history_callback
    self._backend.interface.publish_partial_history(
  File "/Users/brandomiranda/opt/anaconda3/envs/meta_learning/lib/python3.9/site-packages/wandb/sdk/interface/interface.py", line 541, in publish_partial_history
    data = history_dict_to_json(run, data, step=user_step, ignore_copy_err=True)
  File "/Users/brandomiranda/opt/anaconda3/envs/meta_learning/lib/python3.9/site-packages/wandb/sdk/data_types/utils.py", line 54, in history_dict_to_json
    payload[key] = val_to_json(
  File "/Users/brandomiranda/opt/anaconda3/envs/meta_learning/lib/python3.9/site-packages/wandb/sdk/data_types/utils.py", line 82, in val_to_json
    val = Plotly.make_plot_media(val)
  File "/Users/brandomiranda/opt/anaconda3/envs/meta_learning/lib/python3.9/site-packages/wandb/sdk/data_types/plotly.py", line 48, in make_plot_media
    val = util.matplotlib_to_plotly(val)
  File "/Users/brandomiranda/opt/anaconda3/envs/meta_learning/lib/python3.9/site-packages/wandb/util.py", line 560, in matplotlib_to_plotly
    return tools.mpl_to_plotly(obj)
  File "/Users/brandomiranda/opt/anaconda3/envs/meta_learning/lib/python3.9/site-packages/plotly/tools.py", line 112, in mpl_to_plotly
    matplotlylib.Exporter(renderer).run(fig)
  File "/Users/brandomiranda/opt/anaconda3/envs/meta_learning/lib/python3.9/site-packages/plotly/matplotlylib/mplexporter/exporter.py", line 53, in run
    self.crawl_fig(fig)
  File "/Users/brandomiranda/opt/anaconda3/envs/meta_learning/lib/python3.9/site-packages/plotly/matplotlylib/mplexporter/exporter.py", line 122, in crawl_fig
    with self.renderer.draw_figure(fig=fig, props=utils.get_figure_properties(fig)):
  File "/Users/brandomiranda/opt/anaconda3/envs/meta_learning/lib/python3.9/contextlib.py", line 119, in __enter__
    return next(self.gen)
  File "/Users/brandomiranda/opt/anaconda3/envs/meta_learning/lib/python3.9/site-packages/plotly/matplotlylib/mplexporter/renderers/base.py", line 45, in draw_figure
    self.open_figure(fig=fig, props=props)
  File "/Users/brandomiranda/opt/anaconda3/envs/meta_learning/lib/python3.9/site-packages/plotly/matplotlylib/renderer.py", line 90, in open_figure
    self.mpl_x_bounds, self.mpl_y_bounds = mpltools.get_axes_bounds(fig)
  File "/Users/brandomiranda/opt/anaconda3/envs/meta_learning/lib/python3.9/site-packages/plotly/matplotlylib/mpltools.py", line 265, in get_axes_bounds
    x_min, y_min, x_max, y_max = min(x_min), min(y_min), max(x_max), max(y_max)
ValueError: min() arg is an empty sequence

请注意,他们的简单示例确实有效:

import matplotlib.pyplot as plt

plt.plot([1, 2, 3, 4])
plt.ylabel("some interesting numbers")
wandb.log({"chart": plt})

对我来说。


交叉发布:https://community.wandb.ai/t/how-does-one-save-a-plot-in-wandb-with-wandb-log/2373

python wandb
2个回答
0
投票

查看本笔记本的

Log Plots
部分:

https://colab.research.google.com/github/wandb/examples/blob/master/colabs/wandb-log/Log_(几乎)_Anything_with_W%26B_Media.ipynb#scrollTo=Log_plots


导入您的

wandb
并登录/验证后,尝试执行
Log Plots
单元格,然后单击指向您的
visualize-predictions
项目的链接。 (当您调用
wandb.init
并使用等于下面粘贴的代码片段第 5 行中的“visualize-predictions”的项目参数时,会自动创建此项目。)

Log_plots
部分的代码粘贴在下面供后代/以便搜索引擎也可以找到它:

import matplotlib.pyplot as plt
%matplotlib inline

# Initialize a new run
wandb.init(project="visualize-predictions", name="plots")

# Make the plot
fibonacci = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
fig, ax = plt.subplots()
ax.plot(fibonacci)
ax.set_ylabel("some interesting numbers")

# Log the plot
wandb.log({"plot": fig})
wandb.finish()
fig

0
投票
wandb.log({"plot": fig}) with wandb.log({"plot": wandb.Image(fig)}) 

– 瑞兰·谢弗

© www.soinside.com 2019 - 2024. All rights reserved.