Skip to main content

This is a cloned repo to try to support the TensorFlow 2.x version. All the credits go to the original author!

Due to the retracing mechanism introduced in TensorFlow 2.x, the execution behaviour of functions makes some of the assertions in previous test scripts no more valid. Temporarily workaround is adopted, need a clean fixing.

tf-matplotlib - seamless integration of matplotlib figures into TensorFlow summaries

tf-matplotlib renders your everyday matplotlib figures tinside TensorFlow's Tensorboard visualization interface. The library

  • takes care of evaluating input tensors prior to plotting,
  • avoids matplotlib threading issues,
  • support multiple figures and,
  • provides blitting for runtime critical plotting.

The following TensorFlow summary is generated by sgd.py. It plots the progress of gradient descent optimizers on a test surface. To avoid redrawing the test surface, it makes use of blitting. See usage below for a more introductory example.

Installation

pip install tfmpl

Requirements

  • Python 3.5/3.6
  • TensorFlow 1.x
  • matplotlib 2.2.0

Build status

Branch Linux Windows
master
develop

Usage

Below are the relevant snippets to render a simple scatter plot. See scatter.py for the complete self-contained example.

from datetime import datetime
import tensorflow as tf
import numpy as np
import os

import tf_matplotlib as tfmpl

if __name__ == '__main__':
    @tfmpl.figure_tensor
    def draw_scatter(scaled, colors): 
        '''Draw scatter plots. One for each color.'''  
        figs = tfmpl.create_figures(len(colors), figsize=(4,4))
        for idx, f in enumerate(figs):
            ax = f.add_subplot(111)
            ax.axis('off')
            ax.scatter(scaled[:, 0], scaled[:, 1], c=colors[idx])
            f.tight_layout()

        return figs  

    points = tf.random.normal((100, 2), dtype=tf.float32)
    scale = tf.constant(2., dtype=tf.float32)        
    scaled = points*scale
   
    os.makedirs('log', exist_ok=True)
    now = datetime.now()
    logdir = "log/" + now.strftime("%Y%m%d-%H%M%S") + "/"
    writer = tf.summary.create_file_writer(logdir)
    with writer.as_default():
        image_tensor = draw_scatter(scaled, ['r', 'g'])
        image_summary = tf.summary.image('scatter', image_tensor, step=0)
        writer.flush()

Draw utilities

When doing classification, a common task is to generate a confusion matrix. tf-matplotlib provides tfmpl.draw.confusion_matrix to quickly generate such a plot from labels and predictions. The following plot shows classification training progress on the MNIST classification task. Full sample code is provided in mnist.py.

License

MIT License

Copyright (c) 2018 Christoph Heindl

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Release files for tf-matplotlib 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tf-matplotlib 0.1.0
File Size Uploaded
tf_matplotlib-0.1.0.tar.gz 10.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tf-matplotlib 0.1.0
File Interpreter ABI Platform
tf_matplotlib-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 20.5 kB

Release files / tf_matplotlib-0.1.0.tar.gz

Download URL tf_matplotlib-0.1.0.tar.gz
Size 10.9 kB
Tags Source
SHA-256 checksum
How to use checksums
10e12091d34848568d53596169b7acd1c5a65fcc6b926fe846c3fa201bb1630f
BLAKE2b-256 checksum
How to use checksums
e5a463ed8964a74b589e5a5939cc4e81b3ae78f096a17cddf12728e731a63d20
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.7

Release files / tf_matplotlib-0.1.0-py3-none-any.whl

Download URL tf_matplotlib-0.1.0-py3-none-any.whl
Size 9.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4ebea56bf007ae0db1bacc4d402ee01b849dd53ee34b35c2abc2730586e2aa46
BLAKE2b-256 checksum
How to use checksums
29569137dbdf52f423bfa630ae8804975d57e193f538dbf4b7f17315c3997335
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.7

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page