Skip to content

Commit

Permalink
Merge pull request #7 from oujago/develop
Browse files Browse the repository at this point in the history
integrate auto test development tools
  • Loading branch information
oujago authored Apr 12, 2017
2 parents 5bb4741 + eede1b4 commit 74189a3
Show file tree
Hide file tree
Showing 29 changed files with 322 additions and 649 deletions.
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[run]
omit = test/*
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ __pycache__/
*.py[cod]
*$py.class


.pypirc
.idea
docs/_build/*

Expand Down
22 changes: 22 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
language: python
sudo: false
python:
- "3.3"
- "3.4"
- "3.5"
- "3.6"
- "pypy3"
addons:
apt:
packages:
- libblas-dev
- liblapack-dev
before_install:
- pip install -U pip
install:
- travis_wait travis_retry pip install -r requirements.txt
- travis_retry pip install python-coveralls
- travis_retry python setup.py install
script: py.test --runslow --cov-config=.coveragerc
after_success:
- coveralls
7 changes: 7 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Changelog
---------

0.1 (2017-04-11)
~~~~~~~~~~~~~~~~

First release.
4 changes: 4 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# misc
include LICENSE
include requirements.txt
include CHANGES.rst
10 changes: 9 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
:target: https://github.com/oujago/NumpyDL/blob/master/LICENSE


.. image:: https://travis-ci.org/Lasagne/Lasagne.svg
:target: https://travis-ci.org/oujago/NumpyDL

.. image:: https://img.shields.io/coveralls/Lasagne/Lasagne.svg
:target: https://coveralls.io/r/oujago/NumpyDL

.. image:: https://zenodo.org/badge/16974/Lasagne/Lasagne.svg
:target: https://zenodo.org/badge/latestdoi/16974/oujago/NumpyDL



Expand Down Expand Up @@ -91,7 +99,7 @@ Install NumpyDL using pip:

.. code-block:: bash
$> pip install numpydl
$> pip install npdl
Install from source code:

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def find_source():
if domain != 'py' or not info['module']:
return None
try:
filename = 'numpydl/%s#L%d-L%d' % find_source()
filename = 'npdl/%s#L%d-L%d' % find_source()
except Exception:
filename = info['module'].replace('.', '/') + '.py'
tag = 'master' if 'dev' in release else ('v' + release)
Expand Down
Empty file added docs/examples/mlp.rst
Empty file.
18 changes: 15 additions & 3 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ developer.
:maxdepth: 2
:caption: Contents:

user/installation
user_guide/installation


API Reference
Expand All @@ -36,8 +36,20 @@ method, this part of the documentation is for you.
:maxdepth: 2
:caption: Contents:

modules/activation.rst
modules/initialization.rst
api_reference/activation
api_reference/initialization


Examples
--------

This part provides examples for building deep neural networks.

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




Indices and tables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ on PyPI. To install a version that is known to work, run the following command:
.. code-block:: bash
pip install numpydl
pip install npdl
If you do not use ``virtualenv``, add ``--user`` to both commands to install
into your home directory instead. To upgrade from an earlier installation, add
Expand Down
35 changes: 35 additions & 0 deletions examples/01-mlp-digits.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-

import numpy as np
from sklearn.datasets import load_digits

import npdl


def main(max_iter):
# prepare
npdl.utils.random.set_seed(1234)

# data
digits = load_digits()

X_train = digits.data
X_train /= np.max(X_train)

Y_train = digits.target
n_classes = np.unique(Y_train).size

# model
model = npdl.model.Model()
model.add(npdl.layers.Dense(n_out=500, n_in=64, activation=npdl.activation.ReLU()))
model.add(npdl.layers.Dense(n_out=n_classes, activation=npdl.activation.Softmax()))
model.compile(loss=npdl.objectives.SCCE(), optimizer=npdl.optimizers.SGD(lr=0.005))

# train
model.fit(X_train, npdl.utils.data.one_hot(Y_train), max_iter=max_iter, validation_split=0.1)


if __name__ == '__main__':
main(150)


31 changes: 31 additions & 0 deletions examples/01-mlp-mnist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-

import os
import numpy as np
from sklearn.datasets import fetch_mldata

import npdl


def main(max_iter):
# data
print("loading data ...")
mnist = fetch_mldata('MNIST original', data_home=os.path.join(os.path.dirname(__file__), './data'))
X_train = mnist.data / 255.0
y_train = mnist.target
n_classes = np.unique(y_train).size

# model
print("building model ...")
model = npdl.Model()
model.add(npdl.layers.Dense(n_out=500, n_in=784, activation=npdl.activation.ReLU()))
model.add(npdl.layers.Dense(n_out=n_classes, activation=npdl.activation.Softmax()))
model.compile(loss=npdl.objectives.SCCE(), optimizer=npdl.optimizers.SGD(lr=0.001))

# train
print("train model ... ")
model.fit(X_train, npdl.utils.data.one_hot(y_train), max_iter=max_iter, validation_split=0.1)


if __name__ == '__main__':
main(150)
57 changes: 0 additions & 57 deletions examples/01-mlp.py

This file was deleted.

10 changes: 5 additions & 5 deletions examples/02-rnn.py → examples/02-rnn-character-lm.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-


import os
import csv
import itertools

Expand All @@ -10,7 +10,7 @@
import npdl


def load_data(corpus_path='data/lm/reddit-comments-2015-08.csv',
def load_data(corpus_path=os.path.join(os.path.dirname(__file__), 'data/lm/reddit-comments-2015-08.csv'),
vocabulary_size=8000):
sentence_start_token = "SENTENCE_START"
sentence_end_token = "SENTENCE_END"
Expand Down Expand Up @@ -50,7 +50,7 @@ def load_data(corpus_path='data/lm/reddit-comments-2015-08.csv',
return index_to_word, word_to_index, train_x, train_y


def character_lm(corpus_path='data/lm/tiny_shakespeare.txt'):
def main(max_iter, corpus_path=os.path.join(os.path.dirname(__file__), 'data/lm/tiny_shakespeare.txt')):
raw_text = open(corpus_path, 'r').read()
chars = list(set(raw_text))
data_size, vocab_size = len(raw_text), len(chars)
Expand All @@ -77,8 +77,8 @@ def character_lm(corpus_path='data/lm/tiny_shakespeare.txt'):
net.compile(loss=npdl.objectives.SCCE(), optimizer=npdl.optimizers.SGD(lr=0.00001, clip=5))

print("Train model ...")
net.fit(batch_in, batch_out, max_iter=100, batch_size=batch_size)
net.fit(batch_in, batch_out, max_iter=max_iter, batch_size=batch_size)


if __name__ == '__main__':
character_lm()
main(100)
38 changes: 38 additions & 0 deletions examples/03-cnn-minist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-


import os
import numpy as np
from sklearn.datasets import fetch_mldata

import npdl


def main(max_iter):
seed = 100
nb_data = 1000

print("loading data ...")
mnist = fetch_mldata('MNIST original', data_home=os.path.join(os.path.dirname(__file__), './data'))
X_train = mnist.data.reshape((-1, 1, 28, 28)) / 255.0
np.random.seed(seed)
X_train = np.random.permutation(X_train)[:nb_data]
y_train = mnist.target
np.random.seed(seed)
y_train = np.random.permutation(y_train)[:nb_data]
n_classes = np.unique(y_train).size

print("building model ...")
net = npdl.Model()
net.add(npdl.layers.Convolution(1, (3, 3), input_shape=(None, 1, 28, 28)))
net.add(npdl.layers.MeanPooling((2, 2)))
net.add(npdl.layers.Flatten())
net.add(npdl.layers.Softmax(n_out=n_classes))
net.compile()

print("train model ... ")
net.fit(X_train, npdl.utils.data.one_hot(y_train), max_iter=max_iter, validation_split=0.1)


if __name__ == '__main__':
main(10)
26 changes: 0 additions & 26 deletions examples/03-cnn.py

This file was deleted.

3 changes: 1 addition & 2 deletions npdl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@
from .model import Model



__version__ = '0.1.0'
__version__ = "0.1.0"

Loading

0 comments on commit 74189a3

Please sign in to comment.