Flow gym: A framework for the development, benchmarking, training, and deployment of flow-field quantification methods

Francesco Banelli, Antonio Terpin, Alan Bonomi, Raffaello D'Andrea

TL;DR

Flow Gym is an open-source, JAX-based framework designed to standardize the development, benchmarking, and deployment of fluid flow-field quantification methods like Particle Image Velocimetry (PIV). By introducing a unified, hardware-accelerated interface, it bridges the gap between classical and deep learning approaches, allowing researchers to seamlessly transition from offline training to real-time experimental deployment.

What Problem Does This Paper Address?

Quantifying fluid motion using Particle Image Velocimetry (PIV) and optical-flow methods is foundational to experimental fluid mechanics. However, the software ecosystem is highly fragmented. Classical algorithms and modern deep learning models are often trapped in isolated libraries (e.g., OpenCV, PyTorch, OpenPIV) with incompatible interfaces, varying pre- and post-processing steps, and inconsistent evaluation protocols.

This fragmentation makes fair benchmarking nearly impossible and severely hinders reproducibility. Furthermore, transitioning an algorithm from a synthetic research environment to a real-time physical experiment with hardware-in-the-loop typically requires rewriting massive amounts of boilerplate code.

Methods

The core innovation of Flow Gym is its standardized, stateless, and functional Estimator interface, built to align with JAX's programming model.

Overview of the Flow Gym pipeline centered on the Estimator abstraction.

Key components of the framework include:

  • Unified API: Every algorithm follows the functional signature: new_state, metrics = estimator(image, state, trainable_state). For classical methods without learnable weights, Flow Gym simply propagates an empty container, allowing classical and learning-based methods to share the exact same pipeline.
  • JAX-Native Implementations & Wrappers: The authors re-implemented several baseline methods natively in JAX (such as DIS, OpenPIV, and RAFT32-PIV) to leverage hardware acceleration (jit, vmap). For non-JAX methods, they provide interoperable wrappers around external PyTorch and OpenCV libraries.
  • Modular Pipelines: Standardized hooks for image pre-processing (histogram equalization, high-pass filtering, intensity capping) and post-processing (data validation, tile-based averaging interpolation, and smoothing filters).

Datasets

Flow Gym is designed to be data-provenance agnostic, operating on a standardized batch interface:

  • SynthPix: Integrated directly with SynthPix, a lightspeed PIV image generator, to synthesize image pairs from prescribed flow fields or load existing datasets.
  • External Databases: Compatible with offline simulation outputs and public datasets like The Well collection and the Johns Hopkins Turbulence Database.
  • Experimental Data: Capable of processing real-world experimental image pairs and live video streams from physical setups like water channels.

Key Insights and Ideas

  • The "Empty Container" Trick: By passing an empty trainable_state to classical cross-correlation algorithms, Flow Gym unifies classical and deep learning methods under a single abstraction. This enables direct, head-to-head benchmarking under identical conditions.
  • Stateless Temporal Tracking: The framework handles both "one-shot" estimators (independent image pairs) and "recurrent" estimators (temporal streams) simply by carrying forward or resetting the state variable, making it highly versatile for sequential fluid tracking.
  • Code Continuity: The exact same estimator code used for offline benchmarking on synthetic data can be deployed directly into real-time physical fluid-control loops without modification.

Key Results

  • Broad Algorithm Support: Flow Gym successfully integrates a wide variety of standard methods, including DIS, Farneback, DeepFlow, Horn-Schunck, OpenPIV, RAFT32-PIV, and PIV-ADMM.
  • Sub-Millisecond Validation: By utilizing comparator networks implemented in JAX, the framework achieves sub-millisecond performance for universal outlier detection on megapixel images.
  • Real-World Proven Impact: The framework has already been successfully deployed in active, real-time physical fluid-control loops and used to validate hard-constrained neural networks in experimental settings.

Limitations and Future Work

  • Dimension Constraints: Flow Gym currently only supports two-dimensional (2D) flow-field quantification. The authors note that extending the framework to volumetric (3D) setups using multi-camera grouped batches is a critical next step.
  • Native JAX Library Expansion: While wrappers exist for external libraries, maximizing GPU/TPU acceleration requires more algorithms to be natively rewritten in JAX.
  • Remote Physical Integration: The authors plan to connect Flow Gym directly to physical water channels via internet-accessible interfaces, allowing global researchers to evaluate their algorithms under real-world operating conditions remotely.

Summary updated

BibTeX
@article{banelli2026flow,
  author = {Francesco Banelli and Antonio Terpin and Alan Bonomi and Raffaello D'Andrea},
  title = {{Flow gym: A framework for the development, benchmarking, training, and deployment of flow-field quantification methods}},
  journal = {SoftwareX},
  year = {2026},
  doi = {10.1016/j.softx.2026.102641},
}
Figure