I need to import MatPlotLib images into WandB. On the surface, this seems simple, since the documentation clearly shows how to ingest a plt
or fig
object. However, WandB is making a mess of the plots and I don’t want to recode them in plotly.
So I next want to use MatPlotLib to save a PNG and ingest that. Again seems easy, but I would prefer to do it using an in-memory buffer object (this avoids messing with local paths and temp directories on various instances). Apparently I’m not the first one to do this either (link). The instructions are clear and show someone has already done this. But it fails when I try it:
fig, (ax1, ax2) = plt.subplots(2, 1, dpi=300, figsize=(10, 5))
...
buf = io.BytesIO()
plt.savefig(buf, format='png')
buf.seek(0)
wandb.log(({"chart": wandb.Image(file=buf)}))
The error seems to be with wandb.Image()
. It returns:
{TypeError}__init__() got an unexpected keyword argument 'file'
I can remove the file=
parameter so that the command is:
wandb.Image(buf)
And I get: {AttributeError}'_io.BytesIO' object has no attribute 'ndim'
Any recommendations?