The python package for training ML models base on loss, metrics and timeout.
Project description
Infinite Training
The python package for training ML models base on loss, metrics and timeout. We can create target for training or using Ctrl + C to interrupt the training session. This package can store the last weight and optimize weight for us to continue training after interrupting.
Using as example:
uv pip install infinite-training
"""
Apply in example from https://www.tensorflow.org/datasets/keras_example
"""
import tensorflow_datasets as tfds
import tensorflow as tf
from infinite_training import InfinityTraining, Target
(ds_train, ds_test), ds_info = tfds.load(
'mnist',
split=['train', 'test'],
shuffle_files=True,
as_supervised=True,
with_info=True,
)
def normalize_img(image, label):
"""Normalizes images: `uint8` -> `float32`."""
return tf.cast(image, tf.float32) / 255., label
ds_train = ds_train.map(
normalize_img, num_parallel_calls=tf.data.AUTOTUNE)
ds_train = ds_train.cache()
ds_train = ds_train.shuffle(ds_info.splits['train'].num_examples)
ds_train = ds_train.batch(128)
ds_train = ds_train.prefetch(tf.data.AUTOTUNE)
ds_test = ds_test.map(
normalize_img, num_parallel_calls=tf.data.AUTOTUNE)
ds_test = ds_test.batch(128)
ds_test = ds_test.cache()
ds_test = ds_test.prefetch(tf.data.AUTOTUNE)
model = tf.keras.models.Sequential([
tf.keras.layers.Flatten(input_shape=(28, 28)),
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.Dense(10)
])
it = InfinityTraining(model=model, target=Target(
name="val_sparse_categorical_accuracy", smaller_is_better=False, target_value=0.98), timeout=100)
it.compile(optimizer=tf.keras.optimizers.Adam(0.001),
loss=tf.keras.losses.SparseCategoricalCrossentropy(
from_logits=True),
metrics=[tf.keras.metrics.SparseCategoricalAccuracy()],)
it.train(ds_train, validation_data=ds_test)
it.show_result(ds_train)
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file infinite_training-2.0.0.tar.gz.
File metadata
- Download URL: infinite_training-2.0.0.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
05ba8464182b6859488cb34de0cd7bbf927a86c9c92015f0a1b6c9c9af0c73cd
|
|
| MD5 |
92acfa932f7efa74a2ea1908f106d9fe
|
|
| BLAKE2b-256 |
427bd1d820f6367f3d8d2513080864861c7d00a71463175f013032fff6d14887
|
File details
Details for the file infinite_training-2.0.0-py3-none-any.whl.
File metadata
- Download URL: infinite_training-2.0.0-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
76c6a95af3b7d19d71ba61b3440cc089d5319d61996e3c74c6ed488957de256d
|
|
| MD5 |
2ef73de3eea8e7b64e898971e4b8ea7e
|
|
| BLAKE2b-256 |
6a0571a388eff3636d0d4e333a05084844dc7a63246db5675293f38d3ebe38b1
|