# From Foundation Model to Production Model with Roboflow

> Source: <https://roboflow.com/blog/from-foundation-model-to-production-model-with-roboflow>
> Published: 2026-11-25 19:58:39+00:00

**Recommendation:** Test Gemini object detection on a small set including empty and partially occluded images first, then auto-label the full batch with persist_predictions and review before training RF-DETR.
More in the playbook "Fine-tuning and data": <https://wpnews.pro/playbooks/training-data>

A camera and vision AI in a warehouse can help find cardboard boxes on racks and pallets. To build a useful detection model that works even in difficult cases, images with clear labels are needed along with examples of boxes that are partly hidden, close together, or near the edge of the image are also needed.

In this blog, I will show you how to build a warehouse object detection model using Gemini and Roboflow. I'll show you how to test Gemini in a Workflow, generate annotations, and review them in Roboflow. We will then select training images, train an RF-DETR (opens in a new tab) Small model, and deploy the model to the cloud or an edge device. I will also show you how to use Gemini to review difficult images and add new training examples through an active learning loop.

For this example, I used warehouse images from the Warehouse-boxes (opens in a new tab) project by Ashu on Roboflow Universe. The detection class used in this tutorial is cardboard_box. Each visible cardboard box should have a separate bounding box. Pallets and shipping labels are excluded from this class.

Step 1: Prototype with Gemini in a Workflow

The first step is to test whether Gemini can detect the objects needed for the application. Select a few warehouse images with clear boxes, boxes covered in plastic wrap, and boxes that are partly outside the image. Include an image of an empty pallet as well. These examples help check both correct detections and incorrect detections before labeling a larger dataset.

Open Workflows (opens in a new tab)in your Roboflow workspace. Create a Workflow with an image input named image. Add a Google Gemini block and connect it to this input.

In Google Gemini block (opens in a new tab), select a Gemini model that supports Object Detection. Choose this task and enter cardboard_box under Classes. The block returns bounding boxes through its predictions output. Add error_status to the Workflow outputs to check whether the model response was decoded successfully.

Add a Bounding Box Visualization block (opens in a new tab). Connect the original image and the Gemini predictions output to it. Add the annotated image and predictions to the Workflow outputs. Test the selected images and check the bounding boxes. An empty pallet should return no cardboard-box detections.

Above figure shows the full warehouse image. The green bounding boxes mark five individual cartons in the top row of the middle stack. These annotations can be used as a reference when checking Gemini's output. Each carton should have its own bounding box because the model will be trained to detect individual cartons.

Step 2: Auto-label at scale and review in Roboflow

We will continue with the warehouse images and the Gemini Workflow from Step 1. Gemini will generate the initial cardboard_box annotations. Save them to one Roboflow project, review them, and choose the training images before training RF-DETR.

Auto Annotate is another labeling option in Roboflow UI. For this tutorial, we will use Gemini throughout the labeling process so the same Workflow can be extended.

Save the Gemini labels to the warehouse project

Create (opens in a new tab) an Object Detection project for the warehouse dataset. Keep cardboard_box as the detection class.

In the existing Workflow, add Roboflow Dataset Upload (opens in a new tab). Connect the original image to its image input and the complete Gemini predictions output to its predictions input. Select the warehouse project and enable persist_predictions to save the boxes as initial annotations.

Use warehouse-gemini-curation as the labeling batch prefix. Set data_percentage to 100 for the initial labeling batch and set upload quotas to cover the intended batch size. Set fire_and_forget to false while testing, and expose the upload status in the Workflow outputs.

Add the edge-check branch described in Step 3 before running the full batch. It will flag candidate images during labeling. Review and final training selection will follow.

Open Deployments, choose Batch Processing (opens in a new tab), and click New Batch Job. Select this Workflow, upload the warehouse images, choose the hardware, and create the job. Check the job results for Gemini or upload errors and review failed images separately.

Open the uploaded batch in Roboflow Annotate. Check every visible carton. Add missing boxes, remove false detections, and correct boxes that cover more than one carton. Keep images of empty pallets as negative examples after confirming that they contain no cartons.

Above figure illustrates a common correction during review process. One suggested bounding box covers two cartons, so it is replaced with two separate boxes. These are the annotations that will be used for training. After reviewing the images, add them to the dataset and apply the tag reviewed. Also confirm the edge tags as explained below. Our guide shows how to review and add images to the dataset (opens in a new tab) and apply image tags (opens in a new tab).

Step 3: Query annotations to find weak spots, then sample for diversity

Now we will curate the same warehouse dataset. The aim is to find conditions that need more training examples, such as cartons near the camera frame's edges. RF-DETR has not been trained yet. At this stage, a weak spot means a gap in the training data or a labeling problem found during review. We will check the trained detector's performance in Step 4.

The Workflow here, checks the bounding-box positions while Gemini generates labels. During review, we confirm which images really contain edge cartons. We then search those reviewed images and choose a varied training sample. This keeps the complete process in Roboflow, with the Workflow handling inference and filtering, and the dataset interface handling human review and selection.

Add an edge check to the same Workflow

I created Warehouse Gemini Edge Curation in the tim-4ijf0 workspace for this example. It uses gemini-4-carbon in the Google Gemini block and sends labeled images to warehouse-monitoring-lfjp7. The edge check is part of this same Workflow.

For each image, Gemini first returns the proposed cardboard_box bounding boxes. The edge_boxes filter then reads those coordinates. If one or more boxes reach an edge region, the image follows the edge-candidate branch. Otherwise, it follows the routine-candidate branch. Both upload branches receive the full image and all Gemini boxes. The following diagram shows this process.

Use the outer 10% on each side of the original image as the edge region. A box is selected if its left, right, top, or bottom side reaches that region. This is an example selection rule that can be adjusted for the camera as per your need.

In the figure above, the gold bounding box reaches into the outer 10% of the camera frame on the left, so the Workflow counts it as an edge box. The green bounding box stays in the center, so the Workflow counts it as an interior box. The Workflow checks every bounding box returned by Gemini in the same way.

The steps below show how to add the edge check to the same Workflow. We set the four edge limits, find and count the carton bounding boxes that reach any of them, and use that count to tag the image as edge-candidate or routine-candidate. When uploads are enabled, the Workflow saves the original image with all of Gemini’s carton labels for review.

Calculate the four limits: The image_width and image_height Property Definition blocks read the original image dimensions. I added a small Custom Python block named edge_thresholds to calculate the four limits from edge_fraction. It returns left, right, top, and bottom. The default fraction is 0.10. This block only calculates coordinates. Property Definition (opens in a new tab) · Dynamic Python blocks (opens in a new tab).

Filter the boxes: Add Detections Filter after Gemini. Keep class cardboard_box and use an OR group for the four position conditions in the table below. Pass the calculated limits through operations_parameters. Filter bounding-box properties (opens in a new tab).

Count the selected boxes: Use another Property Definition block to extract the number of filtered detections. Name it edge_count. Add this value and the filtered boxes to the Workflow outputs so the edge check can be inspected.

Choose an upload branch: Use two Continue If blocks. The edge branch continues when edge_count > 0. The other branch continues when edge_count = 0. Connect a Dataset Upload block to each branch, both pointing to the same warehouse project. Use edge-candidate as a registration tag on the edge branch. Set branch conditions (opens in a new tab). The routine branch uses the tag routine-candidate. Both gates also require Gemini error_status to be false. A decoding error returns gemini-error and stops both upload branches.

Preserve all carton labels: Both upload blocks must receive the original image and the complete Gemini predictions. The Workflow uses the filtered boxes only to choose the branch. Keep the Step 2 upload settings on both branches and replace the original unconditional upload with these two branches. Each successfully processed image should reach one upload block.

Image edge

Bounding-box condition

Limit calculation

Left

x_min <= left

image width × 0.10

Right

x_max >= right

image width × 0.90

Top

y_min <= top

image height × 0.10

Bottom

y_max >= bottom

image height × 0.90

For a 2,048 by 1,152 pixel image, these limits are 204.8, 1,843.2, 115.2, and 1,036.8 pixels. A carton with x_min = 2 satisfies the left-edge condition. The four limits are calculated for every image, so images with different dimensions use the same percentage rule.

See the complete Workflow

The screenshot below shows the same Workflow used in this example. Gemini generates the bounding boxes. The next blocks check their positions, count the boxes, create the output images, and choose an upload branch.

I'll explain the screenshot in six simple steps.

Generate the annotations:Google Gemini receives the warehouse image and proposes bounding boxes. The cardboard_boxes Detections Filter keeps the cardboard_box class.

Calculate the edge limits: The image_width and image_height blocks read the original image dimensions. Edge Thresholds uses these values and edge_fraction to calculate the left, right, top, and bottom limits.

Separate edge and interior boxes: The edge_boxes filter selects boxes that meet at least one edge condition. The interior_boxes filter selects boxes that remain inside all four limits. These blocks filter the proposed annotations without running another detection model.

Count the boxes and choose a route: The three count blocks return the total, edge, and interior counts. Each First Non Empty Or Default block supplies zero when its count is missing. The has_edge and route Expression blocks use the edge count. The route also checks Gemini's error status, so a decoding error sends the image down the gemini-error route.

Create the output images:all_boxes_cyan draws all carton proposals in cyan. edge_boxes_orange adds orange outlines to the selected edge boxes on that image. edge_only_boxes draws only the edge boxes on the original image. These three visualizations become all_boxes_image, annotated_image, and edge_only_image.

Send the image to the selected upload branch: The two Continue If blocks choose edge_upload or routine_upload. Both branches use the original image and the complete Gemini predictions. They save to the same dataset with different tags when uploads are enabled. Both gates also require Gemini's error status to be false.

The Outputs block returns all 15 configured outputs. The next section shows the three image outputs and explains each value returned by the saved test. I kept disable_upload = true for that test, so it did not add images to the dataset.

Test the Workflow and inspect the results

Open Warehouse Gemini Edge Curation from Workflows in the tim-4ijf0 workspace. Click Run and select the warehouse image. After the run, inspect both the image outputs and the structured results.

Open the saved Workflow and provide a warehouse image. Keep edge_fraction = 0.10 and disable_upload = true for the first test.

Run the Workflow. Open annotated_image to see all proposed boxes. Cyan marks interior boxes and orange marks boxes selected by the edge filter. The output keeps the complete image and its original aspect ratio.

Check total_count, edge_count, interior_count, route, and gemini_error_status. You can also inspect edge_predictions and edge_only_image to see only the selected boxes.

After checking the results and destination project, set disable_upload = false when you want to save new images and labels. Check the upload message. The upload blocks use a 100% sampling rate, but upload quotas still apply. In the saved Workflow, the batch prefix is warehouse-gemini-curation.

I tested the Workflow on the same full rack image used above. The saved run returned 52 proposed carton boxes. The coordinate filter selected 16 edge boxes and left 36 interior boxes. The resulting route was edge-candidate. Gemini's decoding error status was false. Uploads were disabled for this test.

I used three image outputs to explain the result. Each view uses the same input image and the same Gemini predictions from one run. For more details read how to test a Workflow (opens in a new tab).

See all proposed carton boxes

all_boxes_image shows all 52 proposed carton boxes in cyan. Use this view to check whether Gemini missed a carton, marked something else as a carton, or placed one box around several cartons.

See only the boxes selected by the edge check

edge_only_image shows the 16 boxes selected by the coordinate filter in orange. The full photograph is still visible. The other predicted boxes are left out of this view.

Compare edge and interior boxes in one image

annotated_image combines both views. It first draws all carton boxes in cyan, then draws the selected edge boxes in orange. The resulting image has 16 orange edge boxes and 36 cyan interior boxes.

Read the structured Workflow outputs

The following table lists all 15 outputs from this Workflow and the values from the saved rack-image test. The image dimensions are 2,048 × 1,152 pixels.

Output name

Type

Result in this run

What it means

annotated_image

Image

16 orange boxes and 36 cyan boxes

The combined image shows edge boxes in orange and interior boxes in cyan.

all_boxes_image

Image

52 cyan boxes

This image shows every carton bounding box proposed by Gemini.

edge_only_image

Image

16 orange boxes

This image shows only the bounding boxes that meet at least one edge condition.

all_predictions

Object detection result

52 prediction records

Contains the image dimensions and all proposed carton bounding boxes. The selected upload branch receives this complete set of annotations.

edge_predictions

Object detection result

16 prediction records

Contains the bounding boxes selected by the edge filter. Their coordinates refer to the original image.

total_count

Integer

52

Gemini proposed 52 bounding boxes for the cardboard_box class.

edge_count

Integer

16

Sixteen boxes met the edge rule. A box near two edges counts once.

interior_count

Integer

36

Thirty-six boxes stayed inside all four edge limits.

has_edge

Boolean

true

At least one carton bounding box met the edge rule. Read this value together with gemini_error_status.

route

String

edge-candidate

The Workflow selected the edge branch. The other possible values are routine-candidate and gemini-error.

gemini_error_status

Boolean

false

The Google Gemini block decoded the response successfully. The proposed boxes are ready for annotation review.

edge_upload_error_status

Boolean

false

The edge upload block reported no error. Its message below explains why the upload was skipped.

edge_upload_message

String

Sink was disabled by parameter `disable_sink`

Uploads were turned off for this test, so the image was not added to the dataset.

routine_upload_error_status

Boolean or null

null

The routine upload block did not run because the Workflow selected the edge branch.

routine_upload_message

String or null

null

The routine upload block returned no message for this image.

These counts describe this Gemini run. They do not measure detection accuracy, and another run can return different proposals. The edge check tests box positions only. Every image still needs annotation review before it is used for training.

Follow one box through the edge check

Here is one actual prediction from edge_predictions. This excerpt keeps the class, bounding-box coordinates, and confidence field.

JSON

```
{
  "class": "cardboard_box",
  "x": 83,
  "y": 250,
  "width": 166,
  "height": 178,
  "confidence": 1
}
```

In this output, x and y describe the center of the box. Its width is 166 pixels and its height is 178 pixels. The left side is therefore 83 - 166 / 2 = 0. The left edge region ends at 2048 × 0.10 = 204.8 pixels. Because 0 <= 204.8, this box passes the left-edge condition. It remains in all_predictions and also appears in edge_predictions. Its outline becomes orange in annotated_image.

The returned confidence value is shown exactly as received. Even with a confidence of 1, the image still needs review.

Check the route and upload status

The following excerpt contains the count, route, and status outputs from the same run.

JSON

```
{
  "total_count": 52,
  "edge_count": 16,
  "interior_count": 36,
  "has_edge": true,
  "route": "edge-candidate",
  "gemini_error_status": false,
  "edge_upload_error_status": false,
  "edge_upload_message": "Sink was disabled by parameter `disable_sink`",
  "routine_upload_error_status": null,
  "routine_upload_message": null
}
```

route = "edge-candidate" means the Workflow selected the edge upload branch. The message Sink was disabled by parameter `disable_sink` means saving was disabled, so the image was not uploaded. The routine branch returns null because it did not run.

Always check gemini_error_status first. If Gemini reports an error, this Workflow returns gemini-error and prevents both upload branches from running. In that case, the fallback counts can be zero even when the image contains cartons.

When saving is enabled, both branches receive the complete Gemini predictions. The edge filter only sorts images for review, and the uploaded image keeps its interior-carton annotations. After upload, continue with annotation review and diversity selection below.

Query the reviewed images

The edge-candidate tag comes from Gemini's initial boxes. During annotation review, check the full image and apply edge-frame only when a corrected carton box satisfies the edge rule. Add this tag when Gemini missed an edge carton, and remove it if a correction means no carton meets the rule. This makes the final tag describe the reviewed annotations.

Use the following query in the warehouse project's Dataset Search. It selects reviewed images containing the required class and a confirmed edge carton.

```
class:cardboard_box AND tag:reviewed AND tag:edge-frame
```

Inspect these results for labeling problems and missing conditions. For example, there may be many clear edge cartons but very few partly hidden ones. Also inspect images with no annotations, because a completely missed carton cannot be found by its bounding-box coordinates. A reviewer applies and checks these tags by hand, because the Workflow doesn't pick up annotation edits automatically.

We will now select different examples from these results. This is called "sampling for diversity". Choose images showing different camera angles, lighting conditions, carton sizes, and occlusion. When several nearby video frames show almost the same scene, keep a representative frame.

Condition

What to include in the warehouse dataset

Camera angle

Include images taken from the front of a rack and images taken from an angle along the aisle.

Lighting

Include cartons in bright areas, cartons on darker lower racks, and cartons with reflections from plastic wrap.

Occlusion

Include cartons partly hidden behind another carton or a rack support.

Position and size

Select both large and small cartons. Include examples near each of the four image edges and in the center of the frame.

Add edge-diverse to the selected edge images. Keep ordinary cartons away from the edges and reviewed empty-pallet images in the dataset as well. A random upload percentage controls how many images are collected; visual review is still needed to check that the selected set covers different conditions.

Assign the training, validation, and test splits before creating the training version. Keep images from the same video sequence together to avoid nearly identical frames appearing in different splits. Use the selected training images for RF-DETR and keep the validation and test images separate. We are now ready to train on the labels generated and reviewed in this same process.

Step 4: Train RF-DETR and deploy to cloud or edge

The reviewed dataset is now ready for training. RF-DETR Small will learn to predict a class, bounding box, and confidence score for each detected carton. Validation images are used to choose model settings. A separate test set is used to evaluate the final model. RF-DETR object detection models (opens in a new tab).

Add the tag (opens in a new tab)carton-v1 to the selected training images and the validation and test images. Open Versions and select Generate New Version. Check that each image is assigned to the correct split. Under preprocessing, select Filter by Tag (opens in a new tab)and set carton-v1 to Require. Check the image counts in all three splits and generate the dataset version.

Open Train (opens in a new tab) and select Custom Training. Choose the RF-DETR architecture and Small model size. Select the dataset version and a public pretrained checkpoint. Check the training settings and cost estimate, then click Start Training.

After training, test the model on validation images. Compare recall for cartons near and away from the edges. Check for missed cartons, bounding boxes covering several cartons, and false positives on empty pallets. Use these results to select the confidence threshold. Then evaluate the model on the test set using the selected settings. Model Evaluation (opens in a new tab) provides precision, recall, and prediction errors for the test images.

To deploy the model, create a production copy of the warehouse Workflow and add an Object Detection Model (opens in a new tab) block. Remove the initial labeling upload branches from this production copy. Connect the image input and select the trained model version. Add its predictions to the Workflow outputs. Open Deploy (opens in a new tab) to get the code for running the Workflow.

Deployment

How to run the carton detector

Cloud

Use the example code from the Workflow editor to send a warehouse image
to the Serverless Cloud API at https://serverless.roboflow.com.
Check the carton bounding boxes in the returned predictions.
Run a Workflow in the cloud (opens in a new tab).

A cascadeallows RF-DETR to process each image and Gemini to review selected difficult images. In this example, RF-DETR returns detections with a confidence score of at least 0.25. An image is sent to Gemini when any returned detection has a score below 0.60. These are example thresholds and should be adjusted using validation results.

Connect the detector output to Detections Filter (opens in a new tab). Set the filter to keep detections with confidence below 0.60. Connect the filtered predictions to Property Definition (opens in a new tab) and extract the number of detections. Also keep the original RF-DETR predictions as a Workflow output.

Add Continue If (opens in a new tab) and set the condition to a detection count greater than zero. Connect this branch to Google Gemini (opens in a new tab). Provide the original image and use the same cardboard_box detection task. For example, scores of 0.91 and 0.43 would send the image to Gemini because one score is below 0.60. Images with conflicting model results or Gemini decoding errors can be sent for human review.

When RF-DETR runs on an edge device, the Gemini branch still needs a network connection to the hosted service. For the Serverless Cloud API, check that the complete Workflow finishes within the 20-second request limit. A confidence-based rule can select uncertain detections, but a completely missed object has no confidence score. Sampling other images also helps find these missed objects.

Step 5: Build an active learning loop

An active learning loop (opens in a new tab) uses selected images from the deployed system to improve the next model. These images are reviewed and annotated before they are added to the training dataset. For example, an image with a missed carton can be corrected and included in the next training run.

Collect images for review: Add a Roboflow Dataset Upload (opens in a new tab) block to the branch used for uncertain detections. Provide the original image, destination project, and optional RF-DETR predictions. Add a second upload branch for images with an uncertainty count of zero. Set its data_percentage to 1 to collect a random 1% sample. This sample includes images with high-confidence detections and images with no detections. Use separate batch names for the two groups.

Review the annotations: Enable persist_predictions to save the detector's predictions as initial annotations. Review the complete image, add missed cartons, correct boxes covering several cartons, and remove false detections. Select examples from different cameras or recording sessions.

Train and evaluate the updated model: Add the corrected images to the training set and create a new dataset version. Include the previously selected training images and keep the same validation and test splits. Train the updated model and compare it with the deployed model on validation data. Check recall near the edges, recall away from the edges, false positives, and the percentage of images sent to Gemini. Evaluate the selected model on the test set before updating the model version in the production Workflow.

Conclusion

Gemini can give you a first set of labels. Once you’ve checked the bounding boxes and selected images that cover different warehouse conditions, you can use Roboflow to train and deploy RF-DETR. The detector can then handle routine images. When it struggles, send those images to Gemini, check the labels, and add them to the next training run.

To try this with your own data, start with a few images from your warehouse camera. Run them through the Gemini Workflow and review the bounding boxes before labeling the rest.
