Skip to content

Commit

Permalink
create sphinx docs
Browse files Browse the repository at this point in the history
  • Loading branch information
lanpa committed Aug 8, 2017
1 parent 3d5dc78 commit 6499c36
Show file tree
Hide file tree
Showing 7 changed files with 294 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
proto_src/
__pycache__
__pycache__
docs/_*
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SPHINXPROJ = tensorboard-pytorch
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
170 changes: 170 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# tensorboard-pytorch documentation build configuration file, created by
# sphinx-quickstart on Wed Aug 9 01:38:01 2017.
#
# This file is execfile()d with the current directory set to its
# containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
# sys.path.insert(0, os.path.abspath('.'))
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
import tensorboard
# -- General configuration ------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
#
# needs_sphinx = '1.0'

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.autodoc',
'sphinx.ext.mathjax',
'sphinx.ext.intersphinx',
'sphinx.ext.napoleon',
'sphinx.ext.viewcode',
'sphinx.ext.githubpages']

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'

# The master toctree document.
master_doc = 'index'

# General information about the project.
project = 'tensorboard-pytorch'
copyright = '2017, tensorboard-pytorch Contributors'
author = 'tensorboard-pytorch Contributors'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = ''
# The full version, including alpha/beta/rc tags.
release = ''

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False


# -- Options for HTML output ----------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#
# html_theme_options = {}

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']


# -- Options for HTMLHelp output ------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'tensorboard-pytorchdoc'


# -- Options for LaTeX output ---------------------------------------------

latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'tensorboard-pytorch.tex', 'tensorboard-pytorch Documentation',
'tensorboard-pytorch Contributors', 'manual'),
]


# -- Options for manual page output ---------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'tensorboard-pytorch', 'tensorboard-pytorch Documentation',
[author], 1)
]


# -- Options for Texinfo output -------------------------------------------

# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'tensorboard-pytorch', 'tensorboard-pytorch Documentation',
author, 'tensorboard-pytorch', 'One line description of project.',
'Miscellaneous'),
]




# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {
'python':('https://docs.python.org/3', None),
'numpy': ('http://docs.scipy.org/doc/numpy/', None),
'torch': ('http://pytorch.org/docs/master', None),

}
21 changes: 21 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.. tensorboard-pytorch documentation master file, created by
sphinx-quickstart on Wed Aug 9 01:38:01 2017.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to tensorboard-pytorch's documentation!
===============================================

.. toctree::
:maxdepth: 2
:caption: Contents:

tensorboard


Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
7 changes: 7 additions & 0 deletions docs/tensorboard.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
tensorboard-pytorch
===================================
.. automodule:: tensorboard

.. autoclass:: SummaryWriter
:members:
.. autofunction:: tensorboard.embedding.add_embedding
20 changes: 20 additions & 0 deletions tensorboard/embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,26 @@ def make_pbtxt(save_path, metadata, label_img):
'''

def add_embedding(mat, save_path, metadata=None, label_img=None):
"""add embedding
Args:
mat (torch.Tensor): Data identifier
save_path (string): Save location
metadata (list): A list of label
label_img (torch.Tensor): Images correspond to each point
Shape:
mat
.. note::
needs tensorflow
Examples::
>>> # With square kernels and equal stride
>>> m = nn.Conv2d(16, 33, 3, stride=2)
"""
try:
os.makedirs(save_path)
except OSError:
Expand Down
54 changes: 54 additions & 0 deletions tensorboard/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ class SummaryWriter(object):
training.
"""
def __init__(self, log_dir):
"""
Args:
log_dir (string): save location
"""
self.file_writer = FileWriter(logdir=log_dir)
v = 1E-12
buckets = []
Expand All @@ -229,18 +235,60 @@ def __init__(self, log_dir):
self.default_bins = neg_buckets[::-1] + [0] + buckets
self.text_tags = []
def add_scalar(self, name, scalar_value, global_step=None):
"""Add scalar data to summary.
Args:
tag (string): Data identifier
scalar_value (float): value to save
global_step (int): global step value to record
"""
self.file_writer.add_summary(scalar(name, scalar_value), global_step)

def add_histogram(self, name, values, global_step=None, bins='tensorflow'):
"""Add histogram to summary.
Args:
tag (string): Data identifier
values (numpy.array):
global_step (int): global step value to record
"""
if bins=='tensorflow':
bins = self.default_bins
self.file_writer.add_summary(histogram(name, values, bins), global_step)

def add_image(self, tag, img_tensor, global_step=None):
"""Add image data to summary.
Args:
tag (string): Data identifier
img_tensor (torch.Tensor):
global_step (int): global step value to record
Shape:
img_tensor: :math:`(C, H, W)`
"""
self.file_writer.add_summary(image(tag, img_tensor), global_step)
def add_audio(self, tag, snd_tensor, global_step=None):
"""Add audio data to summary.
Args:
tag (string): Data identifier
snd_tensor (torch.Tensor):
global_step (int): global step value to record
- snd_tensor: :math:`(1, L)`
"""
self.file_writer.add_summary(audio(tag, snd_tensor), global_step)
def add_text(self, tag, text_string, global_step=None):
"""Add text data to summary.
Args:
tag (string): Data identifier
text_string (string):
global_step (int): global step value to record
"""
self.file_writer.add_summary(text(tag, text_string), global_step)
if tag not in self.text_tags:
self.text_tags.append(tag)
Expand All @@ -252,6 +300,12 @@ def add_text(self, tag, text_string, global_step=None):
def add_graph(self, model, lastVar):
# prohibit second call?
# no, let tensorboard handles it and show its warning message.
"""Add graph data to summary.
Args:
model (torch.nn.Module): model to draw.
lastVar (torch.autograd.Variable): the root node start from.
"""
import torch
if not hasattr(torch.autograd.Variable, 'grad_fn'):
print('pytorch version is too old, how about build by yourself?')
Expand Down

0 comments on commit 6499c36

Please sign in to comment.