# IV Bag Fill-Level and Leak Detection

> Source: <https://blog.roboflow.com/iv-bag-fill-level-and-leak-detection/>
> Published: 2026-06-16 19:13:04+00:00

*You can automate IV bag monitoring with Roboflow. Train an RF-DETR Small model to detect each bag and classify its fill level, then pass the annotated image to Gemini 2.5 Pro to inspect for visible leaks and write a short summary.*

IV bags deliver fluids, medications, and nutrients to patients in hospitals, clinics, and home [healthcare](https://roboflow.com/industries/healthcare-and-medicine?ref=blog.roboflow.com) settings. An empty IV bag or an undetected leak can interrupt treatment and increase workload for clinical staff. As IV therapy usage grows, automated monitoring becomes increasingly valuable.

The global IV fluid bags market is [estimated](https://www.healthcareforesights.com/reports/intravenous-iv-fluid-bags-market?ref=blog.roboflow.com) to reach USD 3.01 billion in 2026 and is projected to grow at a CAGR of 6.8% through 2035, reaching approximately USD 5.46 billion. This growth is driven by the rising prevalence of chronic diseases, increasing surgical procedures, expanding home healthcare services, and a growing elderly population requiring long-term medical care. As the number of IV infusions increases, automated monitoring solutions become increasingly valuable.

In this tutorial, we will build an automated IV bag monitoring system using Roboflow. We will train an [RF-DETR](https://rfdetr.roboflow.com/latest/?ref=blog.roboflow.com) model to classify IV bag fill levels, deploy the model in [Roboflow Workflows](https://roboflow.com/workflows/build?ref=blog.roboflow.com), and use [Gemini 2.5 Pro](https://playground.roboflow.com/models/google/gemini-2-5-pro?ref=blog.roboflow.com) to inspect images for visible signs of leakage and generate inspection observations.

## IV Bag Fill-Level and Leak Detection with Vision AI

The final output is an annotated image containing fill-level detections alongside AI-generated inspection observations. [Here's the workflow we'll build.](https://app.roboflow.com/workflows/embed/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ3b3JrZmxvd0lkIjoic1ZxMzFvQkVkSzJ1dFgzQVNaQ0wiLCJ3b3Jrc3BhY2VJZCI6Im5JRk5DOGRjbU5OOXZ4d29ybWpoWTdCNjdQZTIiLCJ1c2VySWQiOiJuSUZOQzhkY21OTjl2eHdvcm1qaFk3QjY3UGUyIiwiaWF0IjoxNzgxNjExNTU4fQ.zTP-M2-W_7Qnitfu3nV1vrwKac_nYppuvsl5kf7Y0Rc?ref=blog.roboflow.com)

### Step 1: Prepare the Dataset

For this tutorial, we use an IV bag fill-level [ dataset](https://universe.roboflow.com/jayesh-xzwmh/iv-p9nvz?ref=blog.roboflow.com) to train an RF-DETR model that detects IV bags and classifies their visible fill levels. The predictions are later combined with Gemini 2.5 Pro for leakage assessment.

The dataset contains IV bag images annotated with fill-level categories corresponding to the visible amount of liquid inside the bag. The dataset includes the following classes:

- liquid-0%
- liquid-50%
- liquid-80%
- liquid-100%
- null

The liquid classes represent different fill levels observed in the IV bag, while the null class is used for images that do not clearly belong to one of the defined fill-level categories. This labeling structure allows the model to both locate an IV bag and classify its approximate fill level.

The dataset contains IV bags captured under different lighting conditions, viewing angles, and orientations.

To begin, fork the dataset into your Roboflow workspace. Then navigate to the Train tab and select Custom Training. From the available architectures, choose RF-DETR and set the model size to Small.

Once the model architecture is selected, generate a new dataset version before starting training. Configure a 70/15/15 split for training, validation, and testing.

Enable the following preprocessing steps:

- Auto-orientation
- Resize (512×512)

Since the dataset contains only 69 original training images, we enabled data augmentation and generated a 3× augmented dataset, increasing the dataset size to 207 total images. This helps expose the model to a wider range of visual variations during training while reducing the risk of overfitting to the limited number of original examples.

We enabled the following augmentations:

- Horizontal Flip
- Shear (±10° horizontal and vertical)
- Brightness Adjustment (±15%)
- Exposure Adjustment (±10%)

These preprocessing and augmentation steps help normalize images captured under different conditions while improving the model's ability to generalize to unseen IV bag images. The resulting dataset provides a consistent input size for RF-DETR training while introducing additional variation in orientation, lighting, and perspective.

### Step 2: Train the RF-DETR Model

Once training begins, RF-DETR learns to localize IV bags and classify their visible fill levels directly from the annotated examples in the dataset. Unlike a traditional image classification model that predicts a single label for an entire image, RF-DETR identifies the location of the IV bag and associates it with the corresponding fill-level category using bounding boxes.

This localization capability is valuable because it provides visual confirmation of which IV bag is being analyzed and what fill level has been detected. Instead of returning a single prediction, the model produces an annotated output showing both the detected bag and its predicted fill-level class.

After training completes, Roboflow provides evaluation metrics that help measure how accurately the model detects and classifies IV bags across the different fill-level categories. These results help determine whether the model is ready for deployment in a workflow where Gemini 2.5 Pro can perform a secondary inspection for visible signs of leakage.

### Step 3: Evaluate Metrics

Once training completes, review the model's performance on the test set. Our RF-DETR Small model achieved strong results on the IV bag fill-level detection task:

The model achieved 100% mAP@50, 100% precision, 93.8% recall, and a 96.4% F1 score. These results indicate that the model was able to accurately detect IV bags and classify their fill levels across the test dataset.

Because the dataset contains fewer than 100 original images, these metrics should be interpreted alongside visual inspection of predictions on unseen images. Small test sets can produce optimistic results, so additional testing on a larger and more diverse dataset would be needed before deployment in a production environment.

These metrics evaluate only the RF-DETR fill-level detection model. Visible leak assessment and inspection observations will be handled later in the workflow using Gemini 2.5 Pro.

### Step 4: Deploy to Workflows

After validating the RF-DETR model, deploy it in Roboflow Workflows to create a complete IV bag inspection pipeline. The workflow combines fill-level detection, visual annotation, Gemini-based leakage assessment, response formatting, and image overlay into a single output.

The workflow begins with an input image that is processed by the detect_fill_level RF-DETR model to identify the IV bag's fill level. A Bounding Box Visualization block draws the detection, while a Label Visualization block adds the predicted fill-level class to the image.

The annotated image is then sent to Gemini 2.5 Pro, which inspects it for visible signs of leakage such as fluid droplets, wet surfaces, or pooling liquid. Finally, a formatting block processes Gemini's response, and a Text Display block overlays the inspection summary onto the image.

The workflow returns a single annotated image containing the fill-level prediction and Gemini-generated leakage assessment.

**Workflow architecture:**

To create the workflow, click Try Workflows from your model deployment page and select the Detect and Visualize template as the starting point.

### Step 5: Configure the Gemini 2.5 Pro VLM Block

Fill-level classification is a structured object detection task. Leak detection is less predictable because leakage can appear in several forms. Creating a dedicated leak detector would require a large, consistently annotated leakage dataset. Instead, Gemini analyzes the annotated image and looks for visible evidence of leakage.

Add a Google Gemini block after the label visualization block and configure it with the following settings:

- Image: draw_fill_level_labels.image
- Model: Gemini 2.5 Pro
- Task Type: Open Prompt
- Temperature: 0

**Use this prompt:**

```
Analyze this annotated IV bag image.
The bounding boxes come from an RF-DETR model trained to classify visible IV bag fill levels. The possible fill-level classes are liquid-0%, liquid-50%, liquid-80%, liquid-100%, and null.

Assess the image using the visual evidence and annotations. Determine the predicted fill level from the RF-DETR label. Then inspect the IV bag for visible signs of leakage, including droplets, wet surfaces, pooling liquid, or fluid running down the outside of the bag.

Do not claim that leakage is present unless visible evidence can be observed in the image. Do not infer medical conditions, flow rate, treatment status, or patient information. Do not invent defects that are not visible.

Return only a concise inspection summary in 2–4 sentences. Do not use bullet points, headings, numbering, or structured lists.
```

Gemini receives the image produced by the RF-DETR detection and visualization blocks. The model does not perform fill-level classification. Instead, it interprets the annotated image, evaluates visible leakage indicators, and produces a short inspection summary.

### Step 6: Format and Overlay the Inspection Summary

Next, add a custom Python block after the Gemini block. This block formats Gemini’s response so it can be displayed cleanly on the final image.

**Use this code:**

``` python
def run(self, gemini_response):
    import textwrap

    text = str(gemini_response or '').strip()
    if not text:
        text = 'Inspection summary unavailable.'

    text = ' '.join(text.replace('\n', ' ').split())
    wrapped = textwrap.fill(text, width=58)

    return {'formatted_summary': wrapped}
```

The block converts Gemini's output into plain text, removes extra whitespace, and wraps long lines so the summary fits inside the image overlay.

After the formatting block, add a Text Display block named overlay_inspection_summary.

Configure it as follows:

The final output is a single annotated image showing the RF-DETR fill-level prediction and Gemini-generated leakage assessment.

### Step 7: Test the Workflow

Click Run in the top-right corner of Workflows and upload the IV bag image to validate the pipeline.

The final output should contain:

- RF-DETR fill-level detection
- Fill-level class label
- Gemini-generated leakage assessment
- A formatted inspection summary displayed in the bottom-left corner

Because the workflow relies on visual inspection from a single image, results should be treated as image-based assessments rather than definitive clinical determinations. Images with clear views of the IV bag, tubing connections, and ports generally produce the most reliable leakage evaluations.

## Production Considerations for IV Bag Manufacturing

While this tutorial uses a small IV bag fill-level dataset as a proof of concept, a production system would be trained on images collected directly from manufacturing lines. These datasets would include different bag sizes, fill levels, packaging variations, labels, and examples of real production defects.

In a [manufacturing](https://roboflow.com/industries/manufacturing?ref=blog.roboflow.com) environment, the workflow could be integrated into the production line using industrial cameras placed after filling and sealing stations. RF-DETR could detect underfilled or overfilled bags, damaged containers, missing labels, and other quality issues specific to the product.

Gemini could act as a secondary inspection layer by reviewing detected IV bags for visible signs of leakage, such as fluid droplets, wet surfaces, or leakage around ports and tubing connections. Inspection results could then be compared against production records and quality-control requirements.

Inspection data could also be stored in manufacturing quality systems to support traceability, batch reporting, audits, and review of flagged products.

## Build It Faster with the Roboflow Agent

If you'd rather not add each block by hand, use [Roboflow Agent](https://app.roboflow.com/solutions/chat/new?ref=blog.roboflow.com). Instead of configuring blocks one at a time, you describe the pipeline you want in plain text and the Agent builds it for you. Here's an example:

## IV Bag Fill-Level and Leak Detection** **Conclusion

We trained an RF-DETR model to classify IV bag fill levels, deployed it in Roboflow Workflows, and connected it to Gemini 2.5 Pro for leakage assessment.

The resulting workflow can identify IV bag fill levels, inspect images for visible signs of leakage, and generate a concise inspection summary directly on the output image. This proof of concept shows how computer vision and VLMs can support automated IV bag inspection.

Further reading:

**Cite this Post**

Use the following entry to cite this post in your research:

[Mostafa Ibrahim](/author/mostafa/). (Jun 16, 2026).
IV Bag Fill-Level and Leak Detection. Roboflow Blog: https://blog.roboflow.com/iv-bag-fill-level-and-leak-detection/
