diff --git a/.gitignore b/.gitignore index fee6477..45b037c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ __pycache__/ *.py[cod] *$py.class YellowFIN.py -test* +#test* .idea/ diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..298ea9e --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,19 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +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) \ No newline at end of file diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000..7393ae3 --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,229 @@ +# -*- coding: utf-8 -*- +# +# Configuration file for the Sphinx documentation builder. +# +# This file does only contain a selection of the most common options. For a +# full list see the documentation: +# http://www.sphinx-doc.org/en/master/config + +# -- Path setup -------------------------------------------------------------- + +# 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('../')) + + +# -- Project information ----------------------------------------------------- + +project = 'TensorMonk' +copyright = '2019, Vikas Gottemukkula' +author = 'Vikas Gottemukkula' + +# The short X.Y version +version = '' +# The full version, including alpha/beta/rc tags +release = '0.1' + +import pytorch_sphinx_theme + +# -- 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.doctest', + 'sphinx.ext.intersphinx', + 'sphinx.ext.todo', + 'sphinx.ext.coverage', + 'sphinx.ext.mathjax', + 'sphinx.ext.ifconfig', + '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' + +# 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 pattern also affects 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 = None + + +# -- Options for HTML output ------------------------------------------------- + +import guzzle_sphinx_theme + +html_theme_path = guzzle_sphinx_theme.html_theme_path() +html_theme = 'guzzle_sphinx_theme' + +# Register the theme as an extension to generate a sitemap.xml +extensions.append("guzzle_sphinx_theme") + +# Guzzle theme options (see theme.conf for more information) +html_theme_options = { + # Set the name of the project to appear in the sidebar + "project_nav_name": "Tensor Monk", +} + +''' +html_theme = 'pytorch_sphinx_theme' +html_theme_path = [pytorch_sphinx_theme.get_html_theme_path()] + +# 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 = { + 'pytorch_project': 'docs', + 'canonical_url': 'https://tensormonk.org', + 'collapse_navigation': False, + 'display_version': False, + 'logo_only': False, +} +''' + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +#####html_theme = 'alabaster' + +# 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'] + +# Custom sidebar templates, must be a dictionary that maps document names +# to template names. +# +# The default sidebars (for documents that don't match any pattern) are +# defined by theme itself. Builtin themes are using these templates by +# default: ``['localtoc.html', 'relations.html', 'sourcelink.html', +# 'searchbox.html']``. +# +# html_sidebars = {} + + +# -- Options for HTMLHelp output --------------------------------------------- + +# Output file base name for HTML help builder. +htmlhelp_basename = 'TensorMonkdoc' + + +# -- 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, 'TensorMonk.tex', 'TensorMonk Documentation', + 'Vikas Gottemukkula', '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, 'tensormonk', 'TensorMonk 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, 'TensorMonk', 'TensorMonk Documentation', + author, 'TensorMonk', 'One line description of project.', + 'Miscellaneous'), +] + + +# -- Options for Epub output ------------------------------------------------- + +# Bibliographic Dublin Core info. +epub_title = project + +# The unique identifier of the text. This can be a ISBN number +# or the project homepage. +# +# epub_identifier = '' + +# A unique identification for the text. +# +# epub_uid = '' + +# A list of files that should not be packed into the epub file. +epub_exclude_files = ['search.html'] + + +# -- Extension configuration ------------------------------------------------- + +# -- Options for intersphinx extension --------------------------------------- + +# Example configuration for intersphinx: refer to the Python standard library. +intersphinx_mapping = {'https://docs.python.org/': None} + +# -- Options for todo extension ---------------------------------------------- + +# If true, `todo` and `todoList` produce output, else they produce nothing. +todo_include_todos = True diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 0000000..ce02ccd --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,20 @@ +.. TensorMonk documentation master file, created by + sphinx-quickstart on Sat Jan 12 01:54:14 2019. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Welcome to TensorMonk's documentation! +====================================== + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 0000000..27f573b --- /dev/null +++ b/docs/make.bat @@ -0,0 +1,35 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=. +set BUILDDIR=_build + +if "%1" == "" goto help + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.http://sphinx-doc.org/ + exit /b 1 +) + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% + +:end +popd diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..a464184 --- /dev/null +++ b/setup.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python +import os +import io +import re +import sys +from setuptools import setup, find_packages + + +with open('README.md', 'r') as fh: + long_description = fh.read() + +requirements = [ + 'pytorch>= 0.4.1', + 'torchvision', + 'visdom', +] + +setup( + # Metadata + name='tensormon', + version='0.1', + author='Vikas Gottemukkula', + author_email='tensor46@gmail.com', + url='https://github.com/Tensor46/TensorMONK', + description='TenorMonk is a collection of deep learning architectures', + long_description=long_description, + license='BSD', + + # Package info + packages=find_packages(exclude=('test',)), + + zip_safe=True, + install_requires=requirements, + extras_require={}, +) \ No newline at end of file diff --git a/tensormonk/__init__.py b/tensormonk/__init__.py index f82da51..983595c 100644 --- a/tensormonk/__init__.py +++ b/tensormonk/__init__.py @@ -4,6 +4,6 @@ "normalizations", "regularizations", "essentials", "data", "plots", "utils", "thirdparty"] -from . import activations, architectures, layers, loss -from . import normalizations, regularizations, essentials -from . import data, plots, utils, thirdparty +from tensormonk import activations, architectures, layers, loss +from tensormonk import normalizations, regularizations, essentials +from tensormonk import data, plots, utils, thirdparty diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 0000000..3f6c898 --- /dev/null +++ b/test/__init__.py @@ -0,0 +1 @@ +from test import test_activations \ No newline at end of file diff --git a/test/perf/benchmark_folderittr.py b/test/perf/benchmark_folderittr.py new file mode 100644 index 0000000..30da312 --- /dev/null +++ b/test/perf/benchmark_folderittr.py @@ -0,0 +1,57 @@ +import argparse +import os +from timeit import default_timer as timer +from tqdm import tqdm +import torch +import torch.utils.data +import torchvision +import torchvision.transforms as transforms +import torchvision.datasets as datasets + + +parser = argparse.ArgumentParser(description='PyTorch ImageNet Training') +parser.add_argument('--data', metavar='PATH', required=True, + help='path to dataset') +parser.add_argument('--nThreads', '-j', default=2, type=int, metavar='N', + help='number of data loading threads (default: 2)') +parser.add_argument('--batchSize', '-b', default=256, type=int, metavar='N', + help='mini-batch size (1 = pure stochastic) Default: 256') +parser.add_argument('--accimage', action='store_true', + help='use accimage') + + +if __name__ == "__main__": + args = parser.parse_args() + + if args.accimage: + torchvision.set_image_backend('accimage') + print('Using {}'.format(torchvision.get_image_backend())) + + # Data loading code + transform = transforms.Compose([ + transforms.RandomSizedCrop(224), + transforms.RandomHorizontalFlip(), + transforms.ToTensor(), + transforms.Normalize(mean=[0.485, 0.456, 0.406], + std=[0.229, 0.224, 0.225]), + ]) + + traindir = os.path.join(args.data, 'train') + valdir = os.path.join(args.data, 'val') + train = datasets.ImageFolder(traindir, transform) + val = datasets.ImageFolder(valdir, transform) + train_loader = torch.utils.data.DataLoader( + train, batch_size=args.batchSize, shuffle=True, num_workers=args.nThreads) + train_iter = iter(train_loader) + + start_time = timer() + batch_count = 20 * args.nThreads + for _ in tqdm(range(batch_count)): + batch = next(train_iter) + end_time = timer() + print("Performance: {dataset:.0f} minutes/dataset, {batch:.1f} ms/batch," + " {image:.2f} ms/image {rate:.0f} images/sec" + .format(dataset=(end_time - start_time) * (float(len(train_loader)) / batch_count / 60.0), + batch=(end_time - start_time) / float(batch_count) * 1.0e+3, + image=(end_time - start_time) / (batch_count * args.batchSize) * 1.0e+3, + rate=(batch_count * args.batchSize) / (end_time - start_time))) \ No newline at end of file diff --git a/test/test_activations.py b/test/test_activations.py new file mode 100644 index 0000000..67edcf8 --- /dev/null +++ b/test/test_activations.py @@ -0,0 +1,28 @@ +import unittest +import tensormonk +import torch + +class Tester(unittest.TestCase): + """ + Test for Tensormonk activation functions + """ + + def test_squash(self): + print('validating squash function') + pass + + def test_relu(self): + activation = tensormonk.activations.Activations(activation='relu') + input = torch.Tensor([-1.0, 0.1, 100.00]) + expected_output = torch.Tensor([0.0, 0.1, 100.00]) + actual_output = activation(input) + error = expected_output - actual_output + + self.assertEqual(True, error.sum().item() < 1e6) + + +if __name__ == '__main__': + ''' + >> nosetests + ''' + unittest.main() \ No newline at end of file