Skip to main content

Wrapper for machine learning experiments

Project description

MLWrapper v0.1

MLwrapper is a context manager that helps you store experiment results.

Context manager __enter__ creates mlflow run and store logged values inside. It allows logging following stuff:

  • script arguments
  • images
  • scalars
  • metrics

Quick start

        # data to log
        kwargs = {
            "experiment parameter": 42,
        }
        test_image_1 = np.ones(shape=(3, 40, 40, 1))
        test_image_1[0,:20,:,:] = 0.
        test_image_1[1,:,:,:] = 0.
        test_image_1[2,20:,:,:] = 0.

        test_image_2 = np.ones(shape=(3, 1, 40, 40))
        test_image_2[0,:, 20:,:] = 0.
        test_image_2[1,:,:,:] = 0.
        test_image_2[2,:, :20,:] = 0.

        def test(logger):
            logger.log_args(**{"run param": "value"})
            for step in range(0, 50):
                logger.log_scalar("test_loss", value=100 - step * 1.5, step=step)
                logger.log_scalar("test_acc", value=0.00 + step * 0.01, step=step)
            logger.log_images("test_image", test_image_1, 1)
            logger.log_images("test_image", test_image_2, 2, channel_first=True)
            logger.log_metric("result", result)

        # approach 1
        Experiment = MLWrapper(mlflow_dir="/tmp/mlruns/", **kwargs)
        with Experiment as logger:
            test(logger)

        # approach 2
        with MLWrapper(mlflow_dir="/tmp/mlruns/", **kwargs) as logger:
            test(logger)

        # approach 3
        Experiment = MLWrapper(mlflow_dir="/tmp/mlruns/", **kwargs)
        wrapped_test = Experiment(test) # func needs to accept "logger" or "**kwarg"
        wrapped_test()

Testing

Testing will create files under /tmp directory. Those files are not deleted automatically.

python3 -m unittest discover .

References

mlflow

tensorboard

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

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

Source Distribution

mlwrapper-0.1.tar.gz (4.8 kB view details)

Uploaded Source

File details

Details for the file mlwrapper-0.1.tar.gz.

File metadata

  • Download URL: mlwrapper-0.1.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.1 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.6.9

File hashes

Hashes for mlwrapper-0.1.tar.gz
Algorithm Hash digest
SHA256 4d64b9366e356d0c8f112de5f22dbbb885625b1c6b5b6e062bf4b412c1ea8b15
MD5 2bb5bb3ea427aec993ac1d75e550a960
BLAKE2b-256 3d9ec6097daf7b5f11782d1261fff3bdc606abb404d9d74fa3006d198b16db61

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