Introduce decorator-style API
See original GitHub issueDecorators are pretty?
For example (name is undecided), we can simply define a decorated “op builder” function:
@tfplot.op(batch=True)
def plot_heatmap(heatmap, cmap='jet')
# heatmap: a [16x16] numpy array here
fig, ax = tfplot.subplots(figsize=(4, 3))
im = ax.imshow(heatmap, cmap=cmap)
fig.colorbar(im)
return fig
# heatmap_tensor : a float32 Tensor of shape [4, 16, 16], for example
>>> plot_heatmap(heatmap_tensor)
Tensor("PlotHeatmap:0", shape=(4, ?, ?, 3), dtype=uint8)
Instead of:
# heatmap_tensor : a float32 Tensor of shape [4, 16, 16], for example
>>> PlotOp = tfplot.wrap(figure_heatmap, batch=True, name='PlotHeatmap')
>>> PlotOp(heatmap_tensor)
Tensor("PlotHeatmap:0", shape=(4, ?, ?, 3), dtype=uint8)
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
introduction-decorators-decorator-class-decorator-set-api ...
Instantly share code, notes, and snippets. @omarkdev · omarkdev/introduction-decorators-decorator-class-decorator- ...
Read more >Decorator pattern - Wikipedia
In object-oriented programming, the decorator pattern is a design pattern that allows behavior to be added to an individual object, dynamically, ...
Read more >Documentation - Decorators - TypeScript
Introduction. Further Reading: A Complete Guide to TypeScript Decorators. With the introduction of Classes in TypeScript and ES6, there now exist certain ...
Read more >Quickstart — RESTArt 0.1.3 documentation - Read the Docs
This page gives you a good introduction to RESTArt. ... from restart.api import RESTArt from restart.resource import Resource api = RESTArt() ...
Read more >tff.tf_computation - Federated - TensorFlow
Decorates/wraps Python functions and defuns as TFF TensorFlow computations.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I have been working on this these days, please see #7 (in progress).
tfplot.wrap: The existingtfplot.wrap()can be used as a decorator as well, as suggested by @ferrine.tfplot.autowrap: Similar towrap, but supports automatic injection offig,ax. This will replacewrap_axesplotsoon. Batch supports, etc. will be added soon./cc @ferrine Do you want to take a look or review it?
If you want to kindly give some suggestions, it would be greatly appreciated of course.