Skip to main content

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:

"""
    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


Download files

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

Source Distribution

infinite_training-1.0.0.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

infinite_training-1.0.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file infinite_training-1.0.0.tar.gz.

File metadata

  • Download URL: infinite_training-1.0.0.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.15

File hashes

Hashes for infinite_training-1.0.0.tar.gz
Algorithm Hash digest
SHA256 2888cb2871bd826846b03693db6dbbdd643ba7cd7174a2bcf017f21bd5de2d2e
MD5 5e9ea479017fdbd05e0aae932186feff
BLAKE2b-256 a45eb7c868a42c0d6669314b1c0d2dc1df6d40020a764ae07d61f4f4b8cc6902

See more details on using hashes here.

File details

Details for the file infinite_training-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for infinite_training-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6b8d71e2d3f51cd4204564aca519cfd73919ccccdf4c63c8bf34efe21b931f06
MD5 8a44a10eef5a1767b1a6c3bdf2234e03
BLAKE2b-256 44c5dde306ab21c5e2469e4a841664c413392a7fb34000d2cfdabb8e53ee4d84

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page