{ "info": { "author": "Jongwook Choi", "author_email": "wookayin@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3" ], "description": "TensorFlow Plot (tfplot)\n========================\n\n[![pypi](https://img.shields.io/pypi/v/tensorflow-plot.svg?maxAge=86400)][pypi_tfplot]\n[![Documentation Status](https://readthedocs.org/projects/tensorflow-plot/badge/?version=latest)][documentation]\n[![Build Status](https://travis-ci.org/wookayin/tensorflow-plot.svg?branch=master)](https://travis-ci.org/wookayin/tensorflow-plot)\n\nA [TensorFlow][tensorflow] utility for providing matplotlib-based **plot** operations\n\u2014 [TensorBoard][tensorboard] \u2764\ufe0f [Matplotlib][matplotlib].\n\n

\n \ud83d\udea7 Under Construction \u2014 API might change!\n

\n\nIt allows us to draw **_any_** [matplotlib][matplotlib] plots or figures into images,\nas a part of TensorFlow computation graph.\nEspecially, we can easily any plot and see the result image\nas an image summary in [TensorBoard][tensorboard].\n\n

\n\n

\n\n\nQuick Overview\n--------------\n\nThere are two main ways of using `tfplot`: (i) Use as TF op, and (ii) Manually add summary protos.\n\n### Usage: Decorator\n\nYou can directly declare a Tensor factory by using [`tfplot.autowrap`][tfplot-autowrap] as a decorator.\nIn the body of the wrapped function you can add any logic for drawing plots. Example:\n\n```python\n@tfplot.autowrap(figsize=(2, 2))\ndef plot_scatter(x: np.ndarray, y: np.ndarray, *, ax, color='red'):\n ax.scatter(x, y, color=color)\n\nx = tf.constant([1, 2, 3], dtype=tf.float32) # tf.Tensor\ny = tf.constant([1, 4, 9], dtype=tf.float32) # tf.Tensor\nplot_op = plot_scatter(x, y) # tf.Tensor shape=(?, ?, 4) dtype=uint8\n```\n\n\n### Usage: Wrap as TF ops\n\nWe can [wrap][tfplot-autowrap] **any** pure python function for plotting as a Tensorflow op, such as:\n\n- (i) A python function that creates and return a matplotlib `Figure` (see below)\n- (ii) A python function that has `fig` or `ax` keyword parameters (will be auto-injected);\n e.g. [`seaborn.heatmap`](http://seaborn.pydata.org/generated/seaborn.heatmap.html)\n- (iii) A method instance of [matplotlib `Axes`](https://matplotlib.org/api/axes_api.html);\n e.g. [`Axes.scatter`](https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.scatter.html#matplotlib.axes.Axes.scatter)\n\nExample of (i): You can define a python function that takes `numpy.ndarray` values as input (as an argument of Tensor input),\nand draw a plot as a return value of `matplotlib.figure.Figure`.\nThe resulting TensorFlow plot op will be a RGBA image tensor of shape `[height, width, 4]` containing the resulting plot.\n\n\n```python\ndef figure_heatmap(heatmap, cmap='jet'):\n # draw a heatmap with a colorbar\n fig, ax = tfplot.subplots(figsize=(4, 3)) # DON'T USE plt.subplots() !!!!\n im = ax.imshow(heatmap, cmap=cmap)\n fig.colorbar(im)\n return fig\n\nheatmap_tensor = ... # tf.Tensor shape=(16, 16) dtype=float32\n\n# (a) wrap function as a Tensor factory\nplot_op = tfplot.autowrap(figure_heatmap)(heatmap_tensor) # tf.Tensor shape=(?, ?, 4) dtype=uint8\n\n# (b) direct invocation similar to tf.py_func\nplot_op = tfplot.plot(figure_heatmap, [heatmap_tensor], cmap='jet')\n\n# (c) or just directly add an image summary with the plot\ntfplot.summary.plot(\"heatmap_summary\", figure_heatmap, [heatmap_tensor])\n```\n\nExample of (ii):\n\n```python tfplot\nimport tfplot\nimport seaborn.apionly as sns\n\ntf_heatmap = tfplot.autowrap(sns.heatmap, figsize=(4, 4), batch=True) # function: Tensor -> Tensor\nplot_op = tf_heatmap(attention_maps) # tf.Tensor shape=(?, 400, 400, 4) dtype=uint8\ntf.summary.image(\"attention_maps\", plot_op)\n```\n\nPlease take a look at the [the showcase][examples-showcase] or [examples directory][examples-dir] for more examples and use cases.\n\n[The full documentation][documentation] including API docs can be found at [readthedocs][documentation].\n\n\n### Usage: Manually add summary protos\n\n```python\nimport tensorboard as tb\nfig, ax = ...\n\n# Get RGB image manually or by executing plot ops.\nembedding_plot = sess.run(plot_op) # ndarray [H, W, 3] uint8\nembedding_plot = tfplot.figure_to_array(fig) # ndarray [H, W, 3] uint8\n\nsummary_pb = tb.summary.image_pb('plot_embedding', [embedding_plot])\nsummary_writer.write_add_summary(summary_pb, global_step=global_step)\n```\n\n\nInstallation\n------------\n\n```\npip install tensorflow-plot\n```\n\nTo grab the latest development version:\n\n```\npip install git+https://github.com/wookayin/tensorflow-plot.git@master\n```\n\nNote\n----\n\n### Some comments on Speed\n\n* Matplotlib operations can be **very** slow as Matplotlib runs in python rather than native code,\nso please watch out for runtime speed.\nThere is still a room for improvement, which will be addressed in the near future.\n\n* Moreover, it might be also a good idea to draw plots from the main code (rather than having a TF op) and add them as image summaries.\nPlease use this library at your best discernment.\n\n### Thread-safety issue\n\nPlease use **object-oriented** matplotlib APIs (e.g. `Figure`, `AxesSubplot`)\ninstead of [pyplot] APIs (i.e. `matplotlib.pyplot` or `plt.XXX()`)\nwhen creating and drawing plots.\nThis is because [pyplot] APIs are not *thread-safe*,\nwhile the TensorFlow plot operations are usually executed in multi-threaded manners.\n\nFor example, avoid any use of `pyplot` (or `plt`):\n\n```python\n# DON'T DO LIKE THIS !!!\ndef figure_heatmap(heatmap):\n fig = plt.figure() # <--- NO!\n plt.imshow(heatmap)\n return fig\n```\n\nand do it like:\n\n```python\ndef figure_heatmap(heatmap):\n fig = matplotlib.figure.Figure() # or just `fig = tfplot.Figure()`\n ax = fig.add_subplot(1, 1, 1) # ax: AxesSubplot\n # or, just `fig, ax = tfplot.subplots()`\n ax.imshow(heatmap)\n return fig # fig: Figure\n```\n\nFor example, `tfplot.subplots()` is a good replacement for `plt.subplots()`\nto use inside plot functions.\nAlternatively, you can just take advantage of automatic injection of `fig` and/or `ax`.\n\n\n[pypi_tfplot]: https://pypi.python.org/pypi/tensorflow-plot\n[matplotlib]: http://matplotlib.org/\n[tensorflow]: https://www.tensorflow.org/\n[tensorboard]: https://www.tensorflow.org/get_started/summaries_and_tensorboard\n[pyplot]: http://matplotlib.org/api/pyplot_api.html\n[examples-dir]: https://github.com/wookayin/tensorflow-plot/blob/master/examples/\n[examples-showcase]: https://github.com/wookayin/tensorflow-plot/blob/master/examples/showcases.ipynb\n[documentation]: http://tensorflow-plot.readthedocs.io/en/latest/\n\n[tfplot-autowrap]: https://tensorflow-plot.readthedocs.io/en/latest/api/tfplot.html#tfplot.autowrap\n\n\n### TensorFlow compatibility\n\nCurrently, `tfplot` is compatible with TensorFlow 1.x series.\nSupport for eager execution and TF 2.0 will be coming soon!\n\n\nLicense\n-------\n\n[MIT License](LICENSE) \u00a9 Jongwook Choi", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/wookayin/tensorflow-plot", "keywords": "tensorflow matplotlib tensorboard plot tfplot", "license": "MIT License", "maintainer": "", "maintainer_email": "", "name": "tensorflow-plot", "package_url": "https://pypi.org/project/tensorflow-plot/", "platform": "", "project_url": "https://pypi.org/project/tensorflow-plot/", "project_urls": { "Homepage": "https://github.com/wookayin/tensorflow-plot" }, "release_url": "https://pypi.org/project/tensorflow-plot/0.3.2/", "requires_dist": null, "requires_python": "", "summary": "TensorFlow Plot", "version": "0.3.2" }, "last_serial": 5575695, "releases": { "0.2.0": [ { "comment_text": "", "digests": { "md5": "152d7e4242169bfbc0e9af0ae84bee5d", "sha256": "709ac25afe70b26a078a19763bce9b3815985e648cb071e03d6c97ce334bda7c" }, "downloads": -1, "filename": "tensorflow-plot-0.2.0.tar.gz", "has_sig": false, "md5_digest": "152d7e4242169bfbc0e9af0ae84bee5d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12845, "upload_time": "2018-10-20T20:00:24", "url": "https://files.pythonhosted.org/packages/41/69/350b59d106813db9ac7591db18b3eedea94894fe732bf897bd9aca74b0b1/tensorflow-plot-0.2.0.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "45f4e3ad8a03a36c6b5cb096b65decff", "sha256": "7749e2eee621712c168bc8e0cfb25f8438bcc88665a20a12b6bd192a88c8036e" }, "downloads": -1, "filename": "tensorflow-plot-0.3.0.tar.gz", "has_sig": false, "md5_digest": "45f4e3ad8a03a36c6b5cb096b65decff", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 22379, "upload_time": "2019-02-23T23:14:41", "url": "https://files.pythonhosted.org/packages/da/d0/95c6e93a4db54b8e6b2c2514b84838aa9f1f0f25d15eccac908fe5266831/tensorflow-plot-0.3.0.tar.gz" } ], "0.3.1": [ { "comment_text": "", "digests": { "md5": "2be7bac7e8df63582e990b7c8f1df98e", "sha256": "420f2e002a1a580c670659d063ac85f2ba3fce36e70ece32afd43da02e15f336" }, "downloads": -1, "filename": "tensorflow-plot-0.3.1.tar.gz", "has_sig": false, "md5_digest": "2be7bac7e8df63582e990b7c8f1df98e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 22873, "upload_time": "2019-05-02T01:51:30", "url": "https://files.pythonhosted.org/packages/f0/bc/a591b7deb756d9ff8525fb79049258e8647b2bbb97628f52510bda7a81f6/tensorflow-plot-0.3.1.tar.gz" } ], "0.3.2": [ { "comment_text": "", "digests": { "md5": "3a110723b7dbda4bdc20a6979706f2e6", "sha256": "3ebfd460324490127aedbb4f2935ba04fe1553b619cd06ef877dbd9bef194a43" }, "downloads": -1, "filename": "tensorflow-plot-0.3.2.tar.gz", "has_sig": false, "md5_digest": "3a110723b7dbda4bdc20a6979706f2e6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 23010, "upload_time": "2019-07-24T04:45:26", "url": "https://files.pythonhosted.org/packages/14/72/df7fa1d0cd68aa6f4ab525cea794713367bf774ce311bdca59e441be91e5/tensorflow-plot-0.3.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "3a110723b7dbda4bdc20a6979706f2e6", "sha256": "3ebfd460324490127aedbb4f2935ba04fe1553b619cd06ef877dbd9bef194a43" }, "downloads": -1, "filename": "tensorflow-plot-0.3.2.tar.gz", "has_sig": false, "md5_digest": "3a110723b7dbda4bdc20a6979706f2e6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 23010, "upload_time": "2019-07-24T04:45:26", "url": "https://files.pythonhosted.org/packages/14/72/df7fa1d0cd68aa6f4ab525cea794713367bf774ce311bdca59e441be91e5/tensorflow-plot-0.3.2.tar.gz" } ] }