---
updatedAt: 2025-06-17T21:25:43.000Z
agentTools:
  projectIndex: https://documentation.picsellia.com/llms.txt
---

# 4. Segmentation - Monitor Model Predictions

If you have created a `Deployment` on Picsellia platform, and that `Deployment` is configured to be plugged to our *monitoring service*, you can monitor `Predictions` by requesting our *monitoring service*.

You can use the Python SDK to do this, or you can directly send a request on the *monitoring service*.

## 1. Monitor *Segmentation* `Prediction` with [Python SDK](https://documentation.picsellia.com/reference/deployment#monitor)

### A. Simple Example

This snippet will add a `Prediction` to your Picsellia `Deployment` : this prediction took 0.257 second to be computed, was done on image in given path at "/path/to/image.png" of size (w600\*h800) and is made of 1 polygon with 5 points in \[x, y]

format, being an object of class 1 with a score of 0.9.

```python Python
from picsellia import Client
from picsellia.types.schemas_prediction import SegmentationPredictionFormat

api_token = "<YOUR_API_TOKEN>"
organization_name = "<ORGANIZATION_NAME>"
deployment_name = "<DEPLOYMENT_NAME>"

# You can also use your organization_id, please be sure it's an UUID if you're in a version < 6.6
client = Client(api_token=api_token, organization_name=organization_name)

deployment = client.get_deployment(deployment_name)

# This has only one shape with 5 points : (200, 200), (225, 200), (250, 250), (250, 225), (220, 220)
prediction = SegmentationPredictionFormat(
 	  detection_classes=[1],
    detection_scores=[0.8],
    detection_masks=[[[200, 200], [225, 200], [250, 250], [250, 225], [220, 220]]],
    detection_boxes=[[200, 200, 250, 250]]
)


# Height and width are needed because monitoring service will not open the image 
# Latency is a float representing seconds
data = deployment.monitor(
    image_path="/path/to/image.png",
  	latency=0.257,
    height=800,
    width=600,
    prediction=prediction
)

print(data)
```

> 📘 `Prediction` are always stored as `Data` in the `Datalake`
>
> Please note that once the `Prediction` logged in a `Deployment`, it will be stored as a `Data`in your `Datalake` and be linked to the related `Prediction`.
>
> You can retrieve them easily by filtering on the *source* among your `Datalake`. Indeed by default, `Data`in the `Datalake`coming from a `Deployment` has the source set as *serving*, unless you defined another customized *source* using the `monitor()` function.

> ❗️ SegmentationPredictionFormat
>
> SegmentationPredictionFormat has been fixed in version 6.7.0, our monitoring serving allow detection\_masks as a list of polygon made by a list of points (so list of list of list of integers). If you need to stay in an unfixed version with this format, try monitoring without SDK : documentation can be found [here](https://documentation.picsellia.com/docs/predicting-and-monitoring-without-python-sdk).

> 🚧 Detection boxes needs to be provided too
>
> Based on the detection masks, you can easily compute the associated boxes that needs to be provided as well to instanciate a SegmentationPredictionFormat. It can for instance be done using the following loop:
>
> ```python
> detection_masks=[[[200, 200], [225, 200], [250, 250], [250, 225], [220, 220]]]
> detection_boxes = []
>
> for coords in detection_masks:
>   x_coords = [c[0] for c in coords]
>   y_coords = [c[1] for c in coords]
>   xmin, xmax = min(x_coords), max(x_coords)
>   ymin, ymax = min(y_coords), max(y_coords)
>   box = [int(xmin), int(ymin),int(xmax), int(ymax)]
>   detection_boxes.append(box)
> ```

### B. In-Depth Example: Shadow predictions

If you want to give a shadow prediction at the same time of prediction, you can give parameters *shadow\_latency* and *shadow\_raw\_predictions* .

As parameters *latency* and *prediction* those parameters are of type *float* and *PredictionFormat*.

### C. Optional parameters

Below is the signature of the `monitor()` function, we already saw mandatory parameters *image\_path*, *latency*, *height*, *width*, *prediction*. Let's dig into the optional ones.

```python
class Deployment:
  ...
    def monitor(
        self,
        image_path: Union[str, Path],
        latency: float,
        height: int,
        width: int,
        prediction: PredictionFormat,
        source: Optional[str] = None,
        tags: Optional[List[str]] = None,
        timestamp: Optional[float] = None,
        model_version: Optional[ModelVersion] = None,
        shadow_model_version: Optional[ModelVersion] = None,
        shadow_latency: Optional[float] = None,
        shadow_raw_predictions: Optional[PredictionFormat] = None,
    ) -> dict:
			pass
```

* *source*: value of the source *Metadata* of the `Data`created in the `Datalake`and related to the `Prediction`.
* *tags*: the `DataTag` that will be attached to the `Data`created in the `Datalake`and related to the `Prediction`.
* *timestamp*: a float giving the timestamp of this prediction, if not given our monitoring service will set one at server time (UTC+0).
* *model\_version*: **deprecated in 6.7.0** was used because we could send the *model\_id* to *monitoring service*, now each `Prediction` use the `ModelVersion` set in the `Deployment`. If you want to speed up your workflow and you are in a version prior to 6.7.0, consider giving *model\_version* as it will be retrieved anyway.
* *shadow\_model\_version* : **deprecated in 6.7.0** same as *model\_version*.