models
models copied to clipboard
Matplotlib pyplot not working on a python 3.10 conda environment (Fixed, but unsure how fix works)
Prerequisites
Please answer the following questions for yourself before submitting an issue.
- [ X ] I am using the latest TensorFlow Model Garden release and TensorFlow 2.
- [ X ] I am reporting the issue to the correct repository. (Model Garden official or research directory)
- [ X ] I checked to make sure that this issue has not been filed already.
0. The fix
(Also, one can read through 1-5 first.)
Quoting some of my text / images in this report's part 5,
"
Changing to the backend before importing tensorflow_models, though, does work:
And after the rest works nicely. "
1. The entire URL of the file you are using
Not a file, but this notebook.
2. Describe the bug
matplotlib's pyplot does not seem to be working after importing tensorflow_models. On the other hand, it seems to be working before importing.
3. Steps to reproduce
- Download VSCode.
- Create a new conda environment with python 3.10 (3.10.13?); download tensorflow with this link
- Install TF Model Garden using pip; also use pip3 install tf-models-nightly.
- On this link, click the "Download notebook" icon that appears next to the "Run in Google Colab" and "View on Github" icons.
- Add some extra lines of code, each of which have "plt" as the first letters:
- Run the two lines in the screenshot.
4. Expected behavior
Both cells should show the plot, but only the first one does:
5. Additional context
These extra lines of code show below the plot, which doesn't show if the lines of code creating the plot aren't added.
Checking the matplotlib backend after importing tensorflow_models shown below it seems to be agg, so it does not plot as it is a non-interactive backend.
But before importing tensorflow_models, the backend is different:
Changing to TkAgg, an interactive backend, after importing tensorflow_models, doesn't work:
Changing to the backend before importing tensorflow_models, though, does work:
And after the rest works nicely.
6. System information
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): 2.13.0
- Mobile device name if the issue happens on a mobile device:
- TensorFlow installed from (source or binary): this link
- TensorFlow version (use command below): 2.13.10
- Python version: 3.10.13 (3.10?)
- Bazel version (if compiling from source): ?
- GCC/Compiler version (if compiling from source): ?
- CUDA/cuDNN version: From this link, cuDNN version should be 8.6.0.163 (CUDA 12.0?)
- GPU model and memory: NVIDIA GeForce RTX 3090, 24576 MiB (?)
Assign me this issue I would love to contribute
Not a complete fix but a workaround: Run matplotlib inline immediately after tensorflow_models imported:
import tensorflow_models as tfm
%matplotlib inline
Then every time you use plt to plot, make sure to add plt.show() at the end like:
plt.plot([1,2,3])
plt.show()
plt.show() is necessary to let the plot show up.