Skip to main content

ML pipelines, model configuration and batch management

Project description

License Python PyTorch codecov PyPI Status

BatchFlow

BatchFlow helps you conveniently work with random or sequential batches of your data and define data processing and machine learning workflows even for datasets that do not fit into memory.

For more details see the documentation and tutorials.

Main features:

  • flexible batch generaton
  • deterministic and stochastic pipelines
  • datasets and pipelines joins and merges
  • data processing actions
  • flexible model configuration
  • within batch parallelism
  • batch prefetching
  • ready to use ML models and proven NN architectures
  • convenient layers and helper functions to build custom models
  • a powerful research engine with parallel model training and extended experiment logging.

Basic usage

my_workflow = my_dataset.pipeline()
              .load('/some/path')
              .do_something()
              .do_something_else()
              .some_additional_action()
              .save('/to/other/path')

The trick here is that all the processing actions are lazy. They are not executed until their results are needed, e.g. when you request a preprocessed batch:

my_workflow.run(BATCH_SIZE, shuffle=True, n_epochs=5)

or

for batch in my_workflow.gen_batch(BATCH_SIZE, shuffle=True, n_epochs=5):
    # only now the actions are fired and data is being changed with the workflow defined earlier
    # actions are executed one by one and here you get a fully processed batch

or

NUM_ITERS = 1000
for i in range(NUM_ITERS):
    processed_batch = my_workflow.next_batch(BATCH_SIZE, shuffle=True, n_epochs=None)
    # only now the actions are fired and data is changed with the workflow defined earlier
    # actions are executed one by one and here you get a fully processed batch

Train a neural network

BatchFlow includes ready-to-use proven architectures like VGG, Inception, ResNet and many others. To apply them to your data just choose a model, specify the inputs (like the number of classes or images shape) and call train_model. Of course, you can also choose a loss function, an optimizer and many other parameters, if you want.

from batchflow.models.torch import ResNet34

my_workflow = my_dataset.pipeline()
              .init_model('model', ResNet34, config={'loss': 'ce', 'classes': 10})
              .load('/some/path')
              .some_transform()
              .another_transform()
              .train_model('ResNet34', inputs=B.images, targets=B.labels)
              .run(BATCH_SIZE, shuffle=True)

For more advanced cases and detailed API see the documentation.

Installation

BatchFlow module is in the beta stage. Your suggestions and improvements are very welcome.

BatchFlow supports python 3.6 or higher.

Stable python package

With poetry

poetry add batchflow

With old-fashioned pip

pip3 install batchflow

Development version

With poetry

poetry add --editable git+https://github.com/analysiscenter/batchflow

With old-fashioned pip

pip install --editable git+https://github.com/analysiscenter/batchflow

Extras

Some batchflow functions and classed require additional dependencies. In order to use that functionality you might need to install batchflow with extras (e.g. batchflow[nn]):

  • image - working with image datasets and plotting
  • nn - for neural networks (includes torch, torchvision, ...)
  • datasets - loading standard datasets (MNIST, CIFAR, ...)
  • profile - performance profiling
  • jupyter - utility functions for notebooks
  • research - multiprocess research
  • telegram - for monitoring pipelines via a telegram bot
  • dev - batchflow development (pylint, pytest, ...)

You can install several extras at once, like batchflow[image,nn,research].

Projects based on BatchFlow

Citing BatchFlow

Please cite BatchFlow in your publications if it helps your research.

DOI

Roman Khudorozhkov et al. BatchFlow library for fast ML workflows. 2017. doi:10.5281/zenodo.1041203
@misc{roman_kh_2017_1041203,
  author       = {Khudorozhkov, Roman and others},
  title        = {BatchFlow library for fast ML workflows},
  year         = 2017,
  doi          = {10.5281/zenodo.1041203},
  url          = {https://doi.org/10.5281/zenodo.1041203}
}

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

batchflow-0.8.10.tar.gz (336.4 kB view details)

Uploaded Source

Built Distribution

batchflow-0.8.10-py3-none-any.whl (395.9 kB view details)

Uploaded Python 3

File details

Details for the file batchflow-0.8.10.tar.gz.

File metadata

  • Download URL: batchflow-0.8.10.tar.gz
  • Upload date:
  • Size: 336.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for batchflow-0.8.10.tar.gz
Algorithm Hash digest
SHA256 e9893f31a561451b4c8b61823ef45b7f1f507bae3f5d441c7904ef9a8f08453e
MD5 86502dd216f1b0ae206fff474dfb86bc
BLAKE2b-256 29a90f8e9210e4301f911607d1071dce9ba75b4155af1c4f6c5c735c5d80688e

See more details on using hashes here.

File details

Details for the file batchflow-0.8.10-py3-none-any.whl.

File metadata

  • Download URL: batchflow-0.8.10-py3-none-any.whl
  • Upload date:
  • Size: 395.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for batchflow-0.8.10-py3-none-any.whl
Algorithm Hash digest
SHA256 736d3f1f9c9ff25c3e14689d5e7c8a645fbcbd8c429581eaf34b154ce443803d
MD5 609777e6e3898c33598ebaedf8b94233
BLAKE2b-256 977e92e77fb3659afc28651c4c9f557f450370a2373e791cff3ee09347a583ed

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