Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.


# ModelZoo

A Scaffold to help you build Deep-learning Model much more easily, implemented with TensorFlow Eager Execution and Keras.

## Installation

You can install this package easily with pip:

```
pip3 install model-zoo
```

## Usage

Let's implement a linear-regression model quickly.

Here we use boston_housing dataset as example.

Define a linear model like this, named `model.py`:

```python
from model_zoo.model import BaseModel
import tensorflow as tf

class BostonHousingModel(BaseModel):
def __init__(self, config):
super(BostonHousingModel, self).__init__(config)
self.dense = tf.keras.layers.Dense(1)

def call(self, inputs, training=None, mask=None):
o = self.dense(inputs)
return o

```

Then define a trainer like this, named `train.py`:

```python
import tensorflow as tf
from model_zoo.trainer import BaseTrainer
from model_zoo.preprocess import standardize

tf.flags.DEFINE_integer('epochs', 20, 'Max epochs')
tf.flags.DEFINE_string('model_class', 'BostonHousingModel', 'Model class name')

class Trainer(BaseTrainer):

def prepare_data(self):
from tensorflow.python.keras.datasets import boston_housing
(x_train, y_train), (x_eval, y_eval) = boston_housing.load_data()
x_train, x_eval = standardize(x_train, x_eval)
train_data, eval_data = (x_train, y_train), (x_eval, y_eval)
return train_data, eval_data

if __name__ == '__main__':
Trainer().run()
```

Now, we've finished this model!

Next we can run this model using this cmd:

```
python3 train.py
```

Outputs like this:

```
Epoch 1/100
1/13 [=>............................] - ETA: 0s - loss: 816.1798
13/13 [==============================] - 0s 4ms/step - loss: 457.9925 - val_loss: 343.2489

Epoch 2/100
1/13 [=>............................] - ETA: 0s - loss: 361.5632
13/13 [==============================] - 0s 3ms/step - loss: 274.7090 - val_loss: 206.7015
Epoch 00002: saving model to checkpoints/model.ckpt

Epoch 3/100
1/13 [=>............................] - ETA: 0s - loss: 163.5308
13/13 [==============================] - 0s 3ms/step - loss: 172.4033 - val_loss: 128.0830

Epoch 4/100
1/13 [=>............................] - ETA: 0s - loss: 115.4743
13/13 [==============================] - 0s 3ms/step - loss: 112.6434 - val_loss: 85.0848
Epoch 00004: saving model to checkpoints/model.ckpt

Epoch 5/100
1/13 [=>............................] - ETA: 0s - loss: 149.8252
13/13 [==============================] - 0s 3ms/step - loss: 77.0281 - val_loss: 57.9716
....

Epoch 42/100
7/13 [===============>..............] - ETA: 0s - loss: 20.5911
13/13 [==============================] - 0s 8ms/step - loss: 22.4666 - val_loss: 23.7161
Epoch 00042: saving model to checkpoints/model.ckpt
```

It runs only 42 epochs and stopped early, because the framework auto enabled early stop mechanism and there are no more good evaluation results for 20 epochs.

When finished, we can find two folders generated named `checkpoints` and `events`.

Go to `events` and run TensorBoard:

```
cd events
tensorboard --logdir=.
```

TensorBoard like this:

![](https://ws4.sinaimg.cn/large/006tNbRwgy1fvxrcajse2j31kw0hkgnf.jpg)

There are training batch loss, epoch loss, eval loss.

And also we can find checkpoints in `checkpoints` dir.

It saved the best model named `model.ckpt` according to eval score, and it also saved checkpoints every 2 epochs.

Next we can predict using existing checkpoints, define `infer.py` like this:

```python
from model_zoo.inferer import BaseInferer
from model_zoo.preprocess import standardize
import tensorflow as tf

tf.flags.DEFINE_string('checkpoint_name', 'model.ckpt-20', help='Model name')

class Inferer(BaseInferer):

def prepare_data(self):
from tensorflow.python.keras.datasets import boston_housing
(x_train, y_train), (x_test, y_test) = boston_housing.load_data()
_, x_test = standardize(x_train, x_test)
return x_test

if __name__ == '__main__':
result = Inferer().run()
print(result)
```

Now we've restored the specified model `model.ckpt-38` and prepared test data, outputs like this:

```python
[[ 9.637125 ]
[21.368305 ]
[20.898445 ]
[33.832504 ]
[25.756516 ]
[21.264557 ]
[29.069794 ]
[24.968184 ]
...
[36.027283 ]
[39.06852 ]
[25.728745 ]
[41.62165 ]
[34.340042 ]
[24.821484 ]]
```

OK, we've finished restoring and predicting. Just so quickly.

## Implemented Models

Just see [models](./models), welcome to contribute your model to us.

## License

MIT



Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

model-zoo-0.2.2rc1.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

model_zoo-0.2.2rc1-py2.py3-none-any.whl (15.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file model-zoo-0.2.2rc1.tar.gz.

File metadata

  • Download URL: model-zoo-0.2.2rc1.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.17.1 CPython/3.6.1

File hashes

Hashes for model-zoo-0.2.2rc1.tar.gz
Algorithm Hash digest
SHA256 c1cc7556a7e39afa4a13178ae82cb792a864a3e9e16946feffe55a2a555e7588
MD5 c2c9d602b2e739a6af05a93a3bbd0cd4
BLAKE2b-256 e9436ccf8a8e032d350c1462bbe8f5d2c5aef0f8b2e4578e24cdd1d617f7cd29

See more details on using hashes here.

File details

Details for the file model_zoo-0.2.2rc1-py2.py3-none-any.whl.

File metadata

  • Download URL: model_zoo-0.2.2rc1-py2.py3-none-any.whl
  • Upload date:
  • Size: 15.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.17.1 CPython/3.6.1

File hashes

Hashes for model_zoo-0.2.2rc1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e82078480a30e36cc1f6516931bc4da4980f3118b85741140c746935861372b2
MD5 a0b6bc480780c2c79a0afc760c9ae6b1
BLAKE2b-256 b0c123ed8f58b98757803de0dbc662cbbc03ea5a841e4b56e9de26cc2d1d2ef8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page