Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #8 build #10

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[report]
exclude_lines =
def __repr__
pass
def __str__
if __name__ == .__main__.:
[run]
omit =
*__init__*
*future*
#data_file = /tmp/.coverage
35 changes: 30 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,39 @@
# Python build
*.pyc

# Tensorflow files
*.json

# Pycharm Project
.idea/*
.idea

# Virtualenv
.venv/*
boltzmann_machines/test_rbm_1/*
boltzmann_machines/test_rbm_2/*

models/*
!models/fetch_models.sh
data/*.npy
data/mnist/
data/cifar-10-batches-py/

# Notebooks
notebooks/.ipynb_checkpoints/*
models/*
!models/fetch_models.sh

# TeX files
tex/*.swp
.idea

# python setup.py develop
# python setup_cpu.py develop
boltzmann_machines.egg-info/

# Coverage
.coverage
.coverage*
!.coveragerc
coverage.xml

# Research projects
.tests/
boltzmann_machines/test_rbm_1/*
boltzmann_machines/test_rbm_2/*
2 changes: 1 addition & 1 deletion .noserc
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
all-modules=True
exe=True
with-doctest=True
exclude-dir=examples
exclude-dir=examples
28 changes: 28 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
language: python

python:
- "2.7"
- "3.5"
- "3.6"

sudo: required

#jobs:
# include:
# - stage: doc
# script:
# - make install-docs-requirements
# - make docs

install:
- pip install -U setuptools
- pip list
- pip uninstall --yes pytest numpy
- python setup_cpu.py develop

script:
- make test
- codecov

after_success:
- bash <(curl -s https://codecov.io/bash)
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[![Build Status](https://travis-ci.org/monsta-hd/boltzmann-machines.svg?branch=master)](https://travis-ci.org/monsta-hd/boltzmann-machines)
[![Documentation Status](https://readthedocs.org/projects/srmourasilva-rbm/badge/?version=latest)](http://boltzmann-machine.readthedocs.io/?badge=latest)
[![Code coverage](https://codecov.io/gh/monsta-hd/boltzmann-machines/branch/master/graph/badge.svg)](https://codecov.io/gh/monsta-hd/boltzmann-machine)

<p float="left">
<img src="img/dbm_mnist/rbm1.png" width="140" />
<img src="img/dbm_mnist/samples.png" width="143" />
Expand Down Expand Up @@ -424,12 +428,19 @@ Also, you can download additional data (fine-tuned models' predictions, fine-tun
Check also my supplementary [notes](tex/notes.pdf) (or [dropbox](https://www.dropbox.com/s/7pk4yeixkxogcem/bm_notes.pdf?dl=0)) with some historical outlines, theory, derivations, observations etc.

## How to install
By default, the following commands install (among others) **tensorflow-gpu~=1.3.0**. If you want to install tensorflow without GPU support, replace corresponding line in [requirements.txt](requirements.txt). If you have already tensorflow installed, comment that line.
By default, the following commands install (among others) **tensorflow-gpu~=1.3.0**. If you have already tensorflow installed, comment that line.
```bash
git clone https://github.com/monsta-hd/boltzmann-machines.git
cd boltzmann-machines
pip install -r requirements.txt
```
If you want to install tensorflow without GPU support, use [setup_cpu.py](setup_cpu.py) instead.
```bash
git clone https://github.com/monsta-hd/boltzmann-machines.git
cd boltzmann-machines
python setup_cpu.py develop
```

See [here](docs/virtualenv.md) how to run from a ***virtual environment***.
</br>
See [here](docs/docker.md) how to run from a ***docker container***.
Expand Down
14 changes: 6 additions & 8 deletions boltzmann_machines/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
__author__ = 'Yelysei Bondarenko'
__email__ = '[email protected]'

from .dbm import *
from . import dbm
from . import ebm
from . import layers

from . import base
from . import rbm
from . import utils
from boltzmann_machines.dbm import *
from boltzmann_machines.ebm import *
#from boltzmann_machines.layers import *

#from boltzmann_machines import base
#from boltzmann_machines import rbm
#from boltzmann_machines import utils
1 change: 1 addition & 0 deletions boltzmann_machines/base/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
def is_param_name(name):
return not name.startswith('_') and not name.endswith('_')


def is_attribute_name(name):
return not name.startswith('_') and name.endswith('_')
6 changes: 3 additions & 3 deletions boltzmann_machines/base/base_model.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import numpy as np
from copy import deepcopy
from ..base.base import is_param_name, is_attribute_name
from .mixin import SeedMixin
from ..utils.utils import write_during_training
from boltzmann_machines.base.base import is_param_name, is_attribute_name
from boltzmann_machines.base.mixin import SeedMixin
from boltzmann_machines.utils.utils import write_during_training


class BaseModel(SeedMixin):
Expand Down
2 changes: 1 addition & 1 deletion boltzmann_machines/base/mixin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
import tensorflow as tf

from ..utils import RNG
from boltzmann_machines.utils import RNG


class BaseMixin(object):
Expand Down
2 changes: 0 additions & 2 deletions boltzmann_machines/base/tests/test_tf_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@


class TestWorkingPaths(object):
def __init__(self):
pass

def test_filename_only(self):
tf_model = TFM(model_path='model')
Expand Down
3 changes: 1 addition & 2 deletions boltzmann_machines/base/tf_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import tensorflow as tf
from functools import wraps

from ..base import (BaseModel, DtypeMixin,
is_param_name)
from boltzmann_machines.base import (BaseModel, DtypeMixin, is_param_name)


def run_in_tf_session(check_initialized=True, update_seed=False):
Expand Down
8 changes: 4 additions & 4 deletions boltzmann_machines/dbm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from tensorflow.core.framework import summary_pb2
from tensorflow.contrib.distributions import Bernoulli

from .base import run_in_tf_session
from .ebm import EnergyBasedModel
from .layers import BernoulliLayer
from .utils import (make_list_from, write_during_training,
from boltzmann_machines.base import run_in_tf_session
from boltzmann_machines.ebm import EnergyBasedModel
from boltzmann_machines.layers import BernoulliLayer
from boltzmann_machines.utils import (make_list_from, write_during_training,
batch_iter, epoch_iter,
log_sum_exp, log_diff_exp, log_mean_exp, log_std_exp)

Expand Down
2 changes: 1 addition & 1 deletion boltzmann_machines/ebm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .base import TensorFlowModel
from boltzmann_machines.base import TensorFlowModel


class EnergyBasedModel(TensorFlowModel):
Expand Down
6 changes: 3 additions & 3 deletions boltzmann_machines/rbm/base_rbm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import tensorflow as tf
from tensorflow.core.framework import summary_pb2

from ..ebm import EnergyBasedModel
from ..base import run_in_tf_session, is_attribute_name
from ..utils import (make_list_from, batch_iter, epoch_iter,
from boltzmann_machines.ebm import EnergyBasedModel
from boltzmann_machines.base import run_in_tf_session, is_attribute_name
from boltzmann_machines.utils import (make_list_from, batch_iter, epoch_iter,
write_during_training)
from ..utils.testing import assert_len, assert_shape

Expand Down
10 changes: 5 additions & 5 deletions boltzmann_machines/rbm/rbm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import tensorflow as tf
from tensorflow.contrib.distributions import Multinomial

from .env import *
from .base_rbm import BaseRBM
from layers import BernoulliLayer, MultinomialLayer, GaussianLayer
from boltzmann_machines.rbm.env import *
from boltzmann_machines.rbm.base_rbm import BaseRBM
from boltzmann_machines.layers import BernoulliLayer, MultinomialLayer, GaussianLayer


class BernoulliRBM(BaseRBM):
Expand Down Expand Up @@ -125,6 +125,6 @@ def logit_mean(X):

if __name__ == '__main__':
# run corresponding tests
from utils.testing import run_tests
from tests import test_rbm as t
from boltzmann_machines.utils.testing import run_tests
from boltzmann_machines.rbm.tests import test_rbm as t
run_tests(__file__, t)
9 changes: 5 additions & 4 deletions boltzmann_machines/rbm/tests/test_rbm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
assert_almost_equal,
assert_raises)

from rbm import BernoulliRBM, MultinomialRBM, GaussianRBM
from utils import RNG
from boltzmann_machines.rbm import BernoulliRBM, MultinomialRBM, GaussianRBM
from boltzmann_machines.utils import RNG


class TestRBM(object):
def __init__(self):

def setup_method(self, method):
self.n_visible = 12
self.n_hidden = 8
self.X = RNG(seed=1337).rand(16, self.n_visible)
Expand Down Expand Up @@ -130,5 +131,5 @@ def test_consistency_val(self):
# cleanup
self.cleanup()

def tearDown(self):
def teardown_method(self, method):
self.cleanup()
3 changes: 2 additions & 1 deletion boltzmann_machines/utils/augmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def shift(x, offset=(0, 0)):
y = nd.interpolation.shift(x, shift=offset, mode='nearest')
return y


def horizontal_mirror(x):
y = np.fliplr(x[:,:,...])
y = np.fliplr(x[:, :, ...])
return y
2 changes: 1 addition & 1 deletion boltzmann_machines/utils/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np
import matplotlib.pyplot as plt

from .rng import RNG
from boltzmann_machines.utils.rng import RNG


def load_mnist(mode='train', path='.'):
Expand Down
2 changes: 2 additions & 0 deletions boltzmann_machines/utils/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ def run_tests(script_path, test_module=None):
params.append('--with-doctest')
nose.run(argv=params)


def assert_shape(obj, name, desired_shape):
actual_shape = getattr(obj, name).shape
if actual_shape != desired_shape:
raise ValueError('`{0}` has invalid shape {1} != {2}'.\
format(name, actual_shape, desired_shape))


def assert_len(obj, name, desired_len):
actual_len = len(getattr(obj, name))
if actual_len != desired_len:
Expand Down
Loading