tfplot.contrib
: Some pre-defined plot ops¶
The tfplot.contrib
package contains some off-the-shelf functions for defining plotting operations. This package provides some off-the-shelf functions that could be useful widely across many typical use cases.
Unfortunately, it may not provide super flexible and fine-grained customization points beyond the current parameters. If it does not fit what you want to get, then consider designing your own plotting functions using tfplot.autowrap
.
[6]:
import tfplot.contrib
for fn in sorted(tfplot.contrib.__all__):
print("%-20s" % fn, tfplot.contrib.__dict__[fn].__doc__.split('\n')[1].strip())
batch Make an autowrapped plot function (... -> RGBA tf.Tensor) work in a batch
probmap Display a heatmap in color. The resulting op will be a RGBA image Tensor.
probmap_simple Display a heatmap in color, but only displays the image content.
probmap¶
For example, probmap
and probmap_simple
create an image Tensor that visualizes a probability map:
[7]:
attention_op = tf.constant(attention_map, name="attention_op")
print(attention_op)
op = tfplot.contrib.probmap(attention_map, figsize=(4, 3))
execute_op_as_image(op)
Tensor("attention_op:0", shape=(16, 16), dtype=float32)
Executing: Tensor("probmap:0", shape=(?, ?, 4), dtype=uint8)
[7]:
[8]:
op = tfplot.contrib.probmap_simple(attention_map, figsize=(3, 3),
vmin=0, vmax=1)
execute_op_as_image(op)
Executing: Tensor("probmap_1:0", shape=(?, ?, 4), dtype=uint8)
[8]:
Auto-batch mode (tfplot.contrib.batch
)¶
In many cases, we may want to make plotting operations behave in a batch manner. You can use tfplot.contrib.batch
to make those functions work in a batch mode:
[9]:
# batch version
N = 5
p = np.zeros([N, N, N])
for i in range(N):
p[i, i, i] = 1.0
p = tf.constant(p, name="batch_tensor"); print(p) # (batch_size, 5, 5)
op = tfplot.contrib.batch(tfplot.contrib.probmap)(p, figsize=(3, 2)) # (batch_size, H, W, 4)
results = execute_op_as_image(op) # list of N images
Image.fromarray(np.hstack([np.asarray(im) for im in results]))
Tensor("batch_tensor:0", shape=(5, 5, 5), dtype=float64)
Executing: Tensor("probmap_2/PlotImages:0", shape=(5, ?, ?, 4), dtype=uint8)
[9]: