Coder Social home page Coder Social logo

keras-models-factory's Introduction

keras-models-factory

Factory generating keras models, with unit tests proving they work.

The repository includes integration tests showing that the networks perform well on certain datasets.

The tests include caching so that if a test is interrupted and re-launched, it resumes from where it had reached.

The idea is also available in the keras integration tests

LICENSE

Installation

pip3 install pew
pew new TEST_KERAS_MODELS_FACTORY
pip install git+https://github.com/shadiakiki1986/keras-models-factory.git

For GPU instances (e.g. AWS EC2 p2.xlarge): run init-gpu.sh

Usage

To test a keras model (copy one of the integration tests in tests)

To use a model from the factory:

from keras_models_factory import lstm

# stacked lstm
m1 = lstm.model_1(in_neurons=10, lstm_dim=[8,6], look_back=5)
m1.summary()
# ...

# single lstm followed by dense layers
m2 = lstm.model_2(in_neurons=10, lstm_dim=[8,6], look_back=5)
m2.summary()
# _________________________________________________________________
# Layer (type)                 Output Shape              Param #
# =================================================================
# lstm_1 (LSTM)                (None, 8)                 608
# _________________________________________________________________
# dense_1 (Dense)              (None, 6)                 54
# _________________________________________________________________
# dense_2 (Dense)              (None, 1)                 7
# =================================================================
# Total params: 669
# Trainable params: 669
# Non-trainable params: 0
# _________________________________________________________________

Testing

sudo apt-get install python3-tk

pip3 install pew
pew new KERAS_MODELS_FACTORY

# http://stackoverflow.com/questions/28509965/ddg#28842733
pip install -e .[dev]

# for GPU usage, check
# https://gist.github.com/shadiakiki1986/0c9ea999113691fb9a7ae64e3541fe29#file-init-gpu-sh

# run tests
nosetests --logging-level INFO --nocapture

# or run individual tests
# http://pythontesting.net/framework/specify-test-unittest-nosetests-pytest/
# https://nose.readthedocs.io/en/latest/plugins/logcapture.html
nosetests --logging-level INFO --nocapture -v tests/test_lstm_ds1.py:TestLstmDs1.test_fit_model_1
nosetests --logging-level INFO --nocapture -v tests/test_lstm_ds1.py:TestLstmDs1.test_fit_model_2

Note that ATM I moved some LSTM slow tests into

  • tests/data/params_lstm_1_slow.yml
  • and tests/data/params_lstm_2_slow.yml

To run tests in parallel

sudo apt-get install parallel
ls tests/test*py -1|pew in KERAS_MODELS_FACTORY parallel nosetests --logging-level INFO --nocapture -v {}

Note that the nosetests parameter --processes doesnt work and yields a CUDA_ERROR_NOT_INITIALIZED

Dev notes

In order for import keras_models_factor as kmf; help(kmf.datasets) to work, I use the keras_models_factory/__init__.py to have the imports. Ref: https://stackoverflow.com/a/46242108/4126114

keras-models-factory's People

Contributors

shadiakiki1986 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

keras-models-factory's Issues

batch_size = 10e3 => bad MSE ?

  • in params_1.yml (or 2), I tried one of the tests with batch_size = 10e3
  • that yielded a horrible result
  • I would have thought that it wouldn't have any effect on the MSE
  • could investigate if I have some silly problem in my code
    • or if it indeed makes sense?

EDIT: can also try test_lstm_ds3 with batch_size = 100 and see if can achieve same RMSE

add test showing test-ml/t5-lstm/p5c

This sample showed that input + LSTM + Dense + output do not work together

Add test for this

For reference

# https://cmsdk.com/python/lstm--learn-a-simple-lag-in-the-data.html
def build_lstm_vanilla(in_neurons:int, out_neurons:int, lstm_dim:int, enc_dim:int=None):
  model = Sequential()
  model.add(LSTM(lstm_dim,
    return_sequences=False,
    input_shape=(None, in_neurons),
    stateful=False,                                     
    activation='tanh'
    ))
  # can use "dropout" parameter of LSTM(...) constructor instead of the below
  # model.add(Dropout(0.25))                            
                                                        
  # DOESNT WORK as demonstrated in test-ml/t5-lstm/p5c  
  if enc_dim is not None:                               
    model.add(Dense(enc_dim, activation='tanh'))        
  
  model.add(Dense(out_neurons, activation='linear'))    
    
  model.compile(loss="mean_squared_error", optimizer="rmsprop")
  
  model.summary()
  return model

test for over-fitting?

  • perhaps I can add to assert_fit_model a few lines that check that the val_loss isn't much larger than the loss
    • the case of which would signify over-fitting

add `assert_fit_model_to_all_datasets`

  • no need for me to specify the dataset
  • test against all
  • obviously LSTM datasets may be different than AE datasets
    • need to think of how to preprocess the AE dataset to become a LSTM dataset (by striding)
    • maybe move the striding out of the ds1 and into some function for lstm

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.