Skip to content

Commit

Permalink
Polish documents
Browse files Browse the repository at this point in the history
  • Loading branch information
lanpa committed Apr 3, 2021
1 parent 0e4fef3 commit 75ec65f
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 34 deletions.
Binary file added docs/_static/img/tensorboard/add_mesh.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions examples/demo_mesh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import numpy as np
from tensorboardX import SummaryWriter
from numpy.random import randint


def draw_fusilli(turns, radius, omega):
points = []
faces = []
colors = []
for t in range(turns):
for theta in np.linspace(0, 2 * np.pi, 100, endpoint=False):
z = (theta + 2 * np.pi * t) * omega
end_point = radius * np.cos(theta), radius * np.sin(theta), z
center_point = 0, 0, z
points.append(center_point)
points.append(end_point)


# The frontend stays silent even if you assigned
# non-existing points, be careful.
for n in range(0, len(points)-3, 2):
faces.append((n, n+1, n+3))

for _ in range(len(points)):
colors.append((randint(100, 200),
randint(100, 200),
randint(100, 200)))

return np.array([points]), np.array([colors]), np.array([faces])


with SummaryWriter() as w:
points, colors, faces = draw_fusilli(5, 1, 0.1)
w.add_mesh("my_mesh1", points, colors, faces, global_step=0)

for i in range(1, 10):
points, colors, faces = draw_fusilli(randint(4, 7), 1, 0.1*randint(1,3))
points += randint(-5, 5)
w.add_mesh("my_mesh1", points, colors, faces, global_step=i)
3 changes: 1 addition & 2 deletions tensorboardX/torchvis.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ def __init__(self, *args, **init_kwargs):
args (list of strings): The name of the visualization target(s).
Accepted targets are 'tensorboard' and 'visdom'.
init_kwargs: Additional keyword parameters for the visdom writer (For example, server IP).
See https://github.com/facebookresearch/visdom/blob/master/README.md#visdom-arguments-python-only
for more.
See `visdom doc <https://github.com/facebookresearch/visdom/blob/master/README.md#visdom-arguments-python-only>`_ for more.
"""
self.subscribers = {}
self.register(*args, **init_kwargs)
Expand Down
46 changes: 14 additions & 32 deletions tensorboardX/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,9 @@ def add_histogram(
tag: Data identifier
values: Values to build histogram
global_step: Global step value to record
bins: One of {'tensorflow','auto', 'fd', ...}. This determines how the bins are made. You can find
other options in: https://docs.scipy.org/doc/numpy/reference/generated/numpy.histogram.html
bins: One of {'tensorflow','auto', 'fd', ...}. This determines how the
bins are made. You can find other options in the `numpy reference
<https://docs.scipy.org/doc/numpy/reference/generated/numpy.histogram.html>`_.
walltime: Optional override default walltime (time.time()) of event
Examples::
Expand Down Expand Up @@ -832,8 +833,9 @@ def add_audio(
sample_rate: sample rate in Hz
walltime: Optional override default walltime (time.time()) of event
Shape:
snd_tensor: :math:`(L, C)`. The values should lie between [-1, 1]. Where `L`
is the number of audio frames and `C` is the channel. 1 for mono, 2 for stereo.
snd_tensor: :math:`(L, C)`. The values should lie between [-1, 1].
Where `L` is the number of audio frames and `C` is the channel. Set
channel equals to 2 for stereo.
"""
if self._check_caffe2_blob(snd_tensor):
snd_tensor = workspace.FetchBlob(snd_tensor)
Expand Down Expand Up @@ -1108,7 +1110,8 @@ def add_pr_curve_raw(
global_step: Global step value to record
num_thresholds (int): Number of thresholds used to draw the curve.
walltime: Optional override default walltime (time.time()) of event
see: https://github.com/tensorflow/tensorboard/blob/master/tensorboard/plugins/pr_curve/README.md
see: `Tensorboard refenence
<https://github.com/tensorflow/tensorboard/blob/master/tensorboard/plugins/pr_curve/README.md>`_
"""
self._get_file_writer().add_summary(
pr_curve_raw(tag,
Expand Down Expand Up @@ -1196,7 +1199,7 @@ def add_mesh(
so it allows users to interact with the rendered object. Besides the basic definitions
such as vertices, faces, users can further provide camera parameter, lighting condition, etc.
Please check https://threejs.org/docs/index.html#manual/en/introduction/Creating-a-scene for
advanced usage. Note that currently this depends on tb-nightly to show.
advanced usage.
Args:
tag: Data identifier
Expand All @@ -1209,39 +1212,18 @@ def add_mesh(
seconds after epoch of event
Shape:
vertices: :math:`(B, N, 3)`. (batch, number_of_vertices, channels). If you see nothing on
tensorboard, try normalizing the values to [-1, 1].
vertices: :math:`(B, N, 3)`. (batch, number_of_vertices, channels). If
Nothing show on tensorboard, try normalizing the values to [-1, 1].
colors: :math:`(B, N, 3)`. The values should lie in [0, 255].
faces: :math:`(B, N, 3)`. The values should lie in [0, number_of_vertices] for type `uint8`.
Examples::
from tensorboardX import SummaryWriter
vertices_tensor = np.array([[
[1, 1, 1],
[-1, -1, 1],
[1, -1, -1],
[-1, 1, -1],
]], dtype=float)
colors_tensor = np.array([[
[255, 0, 0],
[0, 255, 0],
[0, 0, 255],
[255, 0, 255],
]], dtype=int)
faces_tensor = np.array([[
[0, 2, 3],
[0, 3, 1],
[0, 1, 2],
[1, 3, 2],
]], dtype=int)
Expected result after running ``examples/demo_mesh.py``:
writer = SummaryWriter()
writer.add_mesh('my_mesh', vertices=vertices_tensor, colors=colors_tensor, faces=faces_tensor)
.. image:: _static/img/tensorboard/add_mesh.png
:scale: 30 %
writer.close()
"""
self._get_file_writer().add_summary(mesh(tag, vertices, colors, faces, config_dict), global_step, walltime)

Expand Down

0 comments on commit 75ec65f

Please sign in to comment.