Short description
show_examples leads to an error: "AttributeError: module 'matplotlib' has no attribute 'pyplot'"
Environment information
tensorflow-datasets version: 2.0.0Reproduction instructions
import tensorflow_datasets as tfds
datasets, info = tfds.load(name='stanford_dogs',
with_info=True, split='train')
tfds.show_examples(
info, datasets, rows=3, cols=3, plot_scale=3.0, image_key=None
)
Additional context
https://github.com/tensorflow/datasets/blob/dcaa4c76905bb9eb14b4e0947d1fce15c48aea0f/tensorflow_datasets/core/visualization.py#L66 is not enough, you need to explicitly import matplotlib.pyplot, see https://stackoverflow.com/questions/14812342/matplotlib-has-no-attribute-pyplot
@Flamefire, I also encountered this error when running locally but its work fine on colab.
There is a workaround: import matplotlib.pyplot anywhere before this. Maybe colab does this by default?
Yes you are right it works, but we use lazy imports for importing modules so that we dont need to import them externally.
Yes, and that needs fixing, hence this bug report. I just wanted to show a workaround and an idea why colab works.
A solution could be similar to https://github.com/tensorflow/datasets/blob/dcaa4c76905bb9eb14b4e0947d1fce15c48aea0f/tensorflow_datasets/core/lazy_imports_lib.py#L101-L105 or https://github.com/tensorflow/datasets/blob/dcaa4c76905bb9eb14b4e0947d1fce15c48aea0f/tensorflow_datasets/core/lazy_imports_lib.py#L119-L122
Yes it works fine
def matplotlib(cls):
_try_import("matplotlib.pyplot")
return _try_import("matplotlib")
Please check if it works?
It does work :+1:
okay thanks for this bug I will send PR for fixing it
@Flamefire why it is working on colab ?
I can't say as I don't know what colab does. For an idea see https://github.com/tensorflow/datasets/issues/1696#issuecomment-602602989