Skip to content

yui-mhcp/data_processing

Repository files navigation

πŸ˜‹ Data processing utilities

Check the CHANGELOG file to have a global overview of the latest updates / new features ! πŸ˜‹

Project structure

Check the provided notebooks to have an overview of the available features !

β”œβ”€β”€ example_data        : data used for the demonstrations
β”œβ”€β”€ loggers             : custom utilities for the `logging` module
β”‚   β”œβ”€β”€ __init__.py         : defines useful utilities to control `logging`
β”‚   β”œβ”€β”€ telegram_handler.py : custom logger using the telegram bot api
β”‚   β”œβ”€β”€ time_logging.py     : custom timer features
β”‚   └── tts_handler.py      : custom logger using the Text-To-Speech models
β”œβ”€β”€ tests               : custom unit-testing for the different modules
β”‚   β”œβ”€β”€ data               : test data files
β”‚   β”œβ”€β”€ __reproduction     : expected output files for reproducibility tests
β”‚   β”œβ”€β”€ test_custom_train_objects.py
β”‚   β”œβ”€β”€ test_utils_audio.py
β”‚   β”œβ”€β”€ test_utils_boxes.py
β”‚   β”œβ”€β”€ test_utils_compile.py
β”‚   β”œβ”€β”€ test_utils_distance.py
β”‚   β”œβ”€β”€ test_utils_embeddings.py
β”‚   β”œβ”€β”€ test_utils_files.py
β”‚   β”œβ”€β”€ test_utils_image.py
β”‚   β”œβ”€β”€ test_utils_keras.py
β”‚   β”œβ”€β”€ test_utils_ops.py
β”‚   β”œβ”€β”€ test_utils_sequence.py
β”‚   β”œβ”€β”€ test_utils_stream.py
β”‚   └── test_utils_text.py
β”œβ”€β”€ utils
β”‚   β”œβ”€β”€ audio                   : audio utilities
β”‚   β”‚   β”œβ”€β”€ audio_annotation.py     : annotation features for new TTS/STT dataset creation
β”‚   β”‚   β”œβ”€β”€ audio_io.py             : audio loading / writing
β”‚   β”‚   β”œβ”€β”€ audio_player.py         : audio playback functionality
β”‚   β”‚   β”œβ”€β”€ audio_processing.py     : audio normalization / processing
β”‚   β”‚   β”œβ”€β”€ audio_recorder.py       : audio recording functionality
β”‚   β”‚   β”œβ”€β”€ audio_stream.py         : audio streaming support
β”‚   β”‚   β”œβ”€β”€ mkv_utils.py            : processing for .mkv video format
β”‚   β”‚   β”œβ”€β”€ noisereducev1.py        : maintained version of the old `noisereduce` library
β”‚   β”‚   └── stft.py                 : implementations of various mel-spectrogram methods
β”‚   β”œβ”€β”€ callbacks               : callback management system
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ callback.py             : base callback implementation
β”‚   β”‚   β”œβ”€β”€ displayer.py            : display-related callbacks
β”‚   β”‚   β”œβ”€β”€ file_saver.py           : file saving callbacks
β”‚   β”‚   └── function_callback.py    : function-based callbacks
β”‚   β”œβ”€β”€ datasets                : dataset utilities
β”‚   β”‚   β”œβ”€β”€ audio_datasets          : audio dataset implementations
β”‚   β”‚   β”‚   β”œβ”€β”€ common_voice.py         : Mozilla Common Voice dataset
β”‚   β”‚   β”‚   β”œβ”€β”€ libri_speech.py         : LibriSpeech dataset
β”‚   β”‚   β”‚   β”œβ”€β”€ processing.py           : audio dataset processing
β”‚   β”‚   β”‚   β”œβ”€β”€ siwis.py                : SIWIS dataset
β”‚   β”‚   β”‚   └── voxforge.py             : VoxForge dataset
β”‚   β”‚   β”œβ”€β”€ builder.py               : dataset building utilities
β”‚   β”‚   β”œβ”€β”€ loader.py                : dataset loading utilities
β”‚   β”‚   └── summary.py               : dataset summary tools
β”‚   β”œβ”€β”€ image                   : image features
β”‚   β”‚   β”œβ”€β”€ bounding_box            : features for bounding box manipulation
β”‚   β”‚   β”‚   β”œβ”€β”€ combination.py          : combines group of boxes
β”‚   β”‚   β”‚   β”œβ”€β”€ converter.py            : box format conversion
β”‚   β”‚   β”‚   β”œβ”€β”€ filters.py              : box filtering
β”‚   β”‚   β”‚   β”œβ”€β”€ locality_aware_nms.py   : LA-NMS implementation
β”‚   β”‚   β”‚   β”œβ”€β”€ metrics.py              : box metrics (IoU, etc.)
β”‚   β”‚   β”‚   β”œβ”€β”€ non_max_suppression.py  : NMS implementation
β”‚   β”‚   β”‚   β”œβ”€β”€ processing.py           : box processing
β”‚   β”‚   β”‚   └── visualization.py        : box extraction / drawing
β”‚   β”‚   β”œβ”€β”€ custom_cameras.py       : custom camera implementations
β”‚   β”‚   β”œβ”€β”€ image_io.py             : image loading / writing
β”‚   β”‚   β”œβ”€β”€ image_normalization.py  : normalization schema
β”‚   β”‚   └── image_processing.py     : image processing utilities
β”‚   β”œβ”€β”€ keras                   : keras and hardware acceleration utilities
β”‚   β”‚   β”œβ”€β”€ ops                     : operation interfaces for different backends
β”‚   β”‚   β”‚   β”œβ”€β”€ builder.py              : operation builder
β”‚   β”‚   β”‚   β”œβ”€β”€ core.py                 : core operations
β”‚   β”‚   β”‚   β”œβ”€β”€ execution_contexts.py   : execution context management
β”‚   β”‚   β”‚   β”œβ”€β”€ image.py                : image operations
β”‚   β”‚   β”‚   β”œβ”€β”€ linalg.py               : linear algebra operations
β”‚   β”‚   β”‚   β”œβ”€β”€ math.py                 : mathematical operations
β”‚   β”‚   β”‚   β”œβ”€β”€ nn.py                   : neural network operations
β”‚   β”‚   β”‚   β”œβ”€β”€ numpy.py                : numpy-compatible operations
β”‚   β”‚   β”‚   └── random.py               : random operations
β”‚   β”‚   β”œβ”€β”€ runtimes                : model runtime implementations
β”‚   β”‚   β”‚   β”œβ”€β”€ onnx_runtime.py         : ONNX runtime
β”‚   β”‚   β”‚   β”œβ”€β”€ runtime.py              : base runtime class
β”‚   β”‚   β”‚   β”œβ”€β”€ saved_model_runtime.py  : saved model runtime
β”‚   β”‚   β”‚   β”œβ”€β”€ tensorrt_llm_runtime.py : TensorRT LLM runtime
β”‚   β”‚   β”‚   └── tensorrt_runtime.py     : TensorRT runtime
β”‚   β”‚   β”œβ”€β”€ compile.py              : graph compilation features
β”‚   β”‚   └── gpu.py                  : GPU utilities
β”‚   β”œβ”€β”€ text                    : text-related features
β”‚   β”‚   β”œβ”€β”€ abreviations
β”‚   β”‚   β”œβ”€β”€ parsers                 : document parsers (new implementation)
β”‚   β”‚   β”‚   β”œβ”€β”€ combination.py      : box combination for parsing
β”‚   β”‚   β”‚   β”œβ”€β”€ docx_parser.py      : DOCX document parser
β”‚   β”‚   β”‚   β”œβ”€β”€ java_parser.py      : Java code parser
β”‚   β”‚   β”‚   β”œβ”€β”€ md_parser.py        : Markdown parser
β”‚   β”‚   β”‚   β”œβ”€β”€ parser.py           : base parser implementation
β”‚   β”‚   β”‚   β”œβ”€β”€ pdf_parser.py       : PDF parser
β”‚   β”‚   β”‚   β”œβ”€β”€ py_parser.py        : Python code parser
β”‚   β”‚   β”‚   └── txt_parser.py       : text file parser
β”‚   β”‚   β”œβ”€β”€ cleaners.py             : text cleaning methods
β”‚   β”‚   β”œβ”€β”€ ctc_decoder.py          : CTC-decoding
β”‚   β”‚   β”œβ”€β”€ metrics.py              : text evaluation metrics
β”‚   β”‚   β”œβ”€β”€ numbers.py              : numbers cleaning methods
β”‚   β”‚   β”œβ”€β”€ sentencepiece_tokenizer.py : sentencepiece tokenizer interface
β”‚   β”‚   β”œβ”€β”€ text_processing.py      : text processing functions
β”‚   β”‚   β”œβ”€β”€ tokenizer.py            : tokenizer implementation
β”‚   β”‚   └── tokens_processing.py    : token-level processing
β”‚   β”œβ”€β”€ threading               : threading utilities
β”‚   β”‚   β”œβ”€β”€ async_result.py        : asynchronous result handling
β”‚   β”‚   β”œβ”€β”€ priority_queue.py      : priority queue with order consistency
β”‚   β”‚   β”œβ”€β”€ process.py             : process management
β”‚   β”‚   └── stream.py              : data streaming implementation
β”‚   β”œβ”€β”€ comparison_utils.py     : convenient comparison features for various data types
β”‚   β”œβ”€β”€ distances.py            : distance and similarity metrics
β”‚   β”œβ”€β”€ embeddings.py           : embeddings saving / loading
β”‚   β”œβ”€β”€ file_utils.py           : data saving / loading
β”‚   β”œβ”€β”€ generic_utils.py        : generic features 
β”‚   β”œβ”€β”€ plot_utils.py           : plotting functions
β”‚   β”œβ”€β”€ sequence_utils.py       : sequence manipulation
β”‚   └── wrappers.py             : function wrappers and decorators
β”œβ”€β”€ example_audio.ipynb
β”œβ”€β”€ example_custom_operations.ipynb
β”œβ”€β”€ example_generic.ipynb
β”œβ”€β”€ example_image.ipynb
β”œβ”€β”€ example_text.ipynb
β”œβ”€β”€ LICENSE
β”œβ”€β”€ Makefile
β”œβ”€β”€ README.md
└── requirements.txt

The loggers module is independant from the utils one, making it easily reusable / extractable.

Installation and usage

See the installation guide for a step-by-step installation πŸ˜„

Here is a summary of the installation procedure, if you have a working python environment :

  1. Clone this repository : git clone https://github.com/yui-mhcp/data_processing.git
  2. Go to the root of this repository : cd data_processing
  3. Install requirements : pip install -r requirements.txt
  4. Open an example notebook and follow the instructions !

The utils/{audio / image / text} modules are not loaded by default, meaning that it is not required to install the requirements for a given submodule if you do not want to use it. In this case, you can simply remove the submodule and run the pipreqs command to compute a new requirements.txt file !

Important Note : no backend (i.e., tensorflow, torch, ...) is installed by default, so make sure to properly install them before !

TO-DO list

  • Make example for audio processing
  • Make example for image processing
  • Make example for text processing
  • Make example for plot utils
  • Make example for embeddings manipulation
  • Make example for the producer-consumer utility
  • Make the code keras-3 compatible
    • Update the audio module
    • Update the image module
    • Update the text module
    • Update the utils module
    • Make unit-testing to check correctness for the different keras backends
    • Make unit-testing for the graph_compile and executing_eagerly in all backends
    • Make every function compatible with tf.data, no matter the keras backend (see example_custom_ops.ipynb for more information)
  • Enable any backend to be aware of XLA/eager execution (i.e., executing_eagerly function)
  • Enable graph_compile to support all backends compilation
    • tensorflow backend (tf.function)
    • torch backend (torch.compile)
    • jax backend (jax.jit)
  • Auto-detect static_argnames for the jax.jit compilation
  • Allow tf.function with graph_compile regardless of the keras backend
  • Add GPU features for all backends
    • tensorflow backend
    • torch backend
    • jax backend

Audio

  • Extract audio from videos
  • Enables audio playing without IPython.display autoplay feature
  • Implement specific Mel spectrogram implementations
  • Run the read_audio function in tf.data pipeline
  • Support audio formats :
    • wav
    • mp3
    • Any librosa format
    • Any ffmpeg format (video support)

Image

  • Add image loading / writing support
  • Add video loading / writing support
  • Add support for rotated bounding boxes
  • Implement a keras 3 Non-Maximal Suppression (NMS)
  • Implement the Locality-Aware NMS (LaNMS)

Text

  • Support text encoding in tf.data pipeline
  • Implement text cleaning
    • Abreviation extensions
    • Time / dollar / number extensions
    • unicode convertion
  • Support token-splitting instead of word-splitting in TextEncoder
  • Support transformers tokenizers convertion
  • Support sentencepiece encoders
  • Extract text from documents
    • .txt
    • .md
    • .pdf
    • .docx
    • .html
    • .epub
  • Implement token-based logits masking
  • Implement batch text encoding
  • Add custom tokens to Tokenizer
  • Implement CTC-decoding in keras 3 (Β΅already implemented in keras 3.3*)

Generic utilities

  • Make subplots easier to use via args and kwargs
  • Make custom plot functions usable with plot_multiple
  • Add 3D plot / subplot support
  • Implement custom plotting functions
    • Spectrogram / attention weights
    • Audio waveform
    • Embeddings (d-dimensional vectors projected in 2D space)
    • 3D volumes
    • Classification result
    • Confusion matrix (or any matrix)

Contacts and licence

Contacts :

This project is licensed under the GNU Affero General Public License v3.0 (AGPL-3.0). See the LICENSE file for details.

This license allows you to use, modify, and distribute the code, as long as you include the original copyright and license notice in any copy of the software/source. Additionally, if you modify the code and distribute it, or run it on a server as a service, you must make your modified version available under the same license.

For more information about the AGPL-3.0 license, please visit the official website

Notes and references

  • The text cleaning module (text.cleaners) is inspired from NVIDIA tacotron2 repository. Their implementation of Short-Time Fourrier Transform (STFT) is also available in audio/stft.py, adapted in keras 3.

  • The provided embeddings in example_data/embeddings/embeddings_256_voxforge.csv has been generated based on samples of the VoxForge dataset, and embedded with an AudioSiamese model (audio_siamese_256_mel_lstm).

Tutorials :

  • The Keras 3 API which has been (partially) adapted in the keras_utils/ops module to enable numpy backend, and tf.data compatibility
  • The tf.function guide

Citation

If you find this project useful in your work, please add this citation to give it more visibility ! πŸ˜‹

@misc{yui-mhcp
    author  = {yui},
    title   = {A Deep Learning projects centralization},
    year    = {2021},
    publisher   = {GitHub},
    howpublished    = {\url{https://github.com/yui-mhcp}}
}