An adapter callback for Keras ModelCheckpoint that allows checkpointing an alternate model (often submodel of a multi-GPU model).
Project description
alt-model-checkpoint
An adapter callback for Keras ModelCheckpoint that allows checkpointing an alternate model (often submodel of a multi-GPU model).
Installation
pip install alt-model-checkpoint
Usage
You must provide your own Keras or Tensorflow installation. See Pipfile
for preferred versions.
If using the Keras bundled in Tensorflow:
from alt_model_checkpoint.tensorflow import AltModelCheckpoint
If using Keras standalone:
from alt_model_checkpoint.keras import AltModelCheckpoint
Common usage involving multi-GPU models built with Keras multi_gpu_model()
:
from alt_model_checkpoint.keras import AltModelCheckpoint
from keras.models import Model
from keras.utils import multi_gpu_model
def compile_model(m):
"""Implement with your model compile logic; both base and GPU models should be compiled identically"""
m.compile(...)
base_model = Model(...)
gpu_model = multi_gpu_model(base_model)
compile_model(base_model)
compile_model(gpu_model)
gpu_model.fit(..., callbacks=[
AltModelCheckpoint('save/path/for/model.hdf5', base_model)
])
Constructor args
filepath
Model save file path; see underlying ModelCheckpoint docs for details.
alternate_model
Keras model to save instead of the default. This is used especially when training multi-gpu models built with Keras multi_gpu_model(). In that case, you would pass the original "template model" to be saved each checkpoint.
inherit_optimizer
If TRUE (default), saves the optimizer of the base model (e.g. a multi-gpu model) with the alternate model. This is necessary if you want to be able to resume training on a saved alternate model. If FALSE, the alternate model's optimizer will be saved as-is.
*args, **kwargs
These are passed as-is to the underlying ModelCheckpoint constructor.
Dev environment setup
- Install pipenv.
- Run
make test
(runsmake test-build
automatically to ensure deps)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file alt-model-checkpoint-2.0.3.tar.gz
.
File metadata
- Download URL: alt-model-checkpoint-2.0.3.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6001eae3329d2d90da02413eca04725deab54a834f2539288ee3f10832ea10a7 |
|
MD5 | fa3917ceb2967cd47596f733b298eb89 |
|
BLAKE2b-256 | 0f14f956f4f4e3bc750bc0615570e341a884c34bafcd260273d69b3d2b140396 |
File details
Details for the file alt_model_checkpoint-2.0.3-py3-none-any.whl
.
File metadata
- Download URL: alt_model_checkpoint-2.0.3-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e71d8395de254f3a02fdff5a1ec2ad5bc2cfcbc7fcffd17e36e23740cbb92e98 |
|
MD5 | 53594440834291ba078ef0c971616840 |
|
BLAKE2b-256 | 0a00c0091a1b99d97374ada680d741f96ec23ba8d49310f3f7d21a379182afe2 |