# How to draw masks of YoloV8n in iOS App

**URL:** <https://community.ultralytics.com/t/how-to-draw-masks-of-yolov8n-in-ios-app/732>\
**Category:** YOLO\
**Created:** [January 30, 2025, 3:56pm UTC](https://community.ultralytics.com/t/how-to-draw-masks-of-yolov8n-in-ios-app/732 "2025-01-30T15:56:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![domi](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@domi](https://community.ultralytics.com/u/domi)\
**Post date:** [January 30, 2025, 3:56pm UTC](https://community.ultralytics.com/t/how-to-draw-masks-of-yolov8n-in-ios-app/732/1 "2025-01-30T15:56:22Z")

</div>

In our soccer iOS App, we need to draw the segmentation mask of goals onto the screen.

How can we achieve that? This is our code in Swift:

```swift
if let model = try? yolo8n_segment().model,
    let nnmodel = try? VNCoreMLModel(for: model) {
    let url = Bundle.main.url(forResource: "img0", withExtension: "jpg")!
    let data = try? Data(contentsOf: url)
    let request = VNCoreMLRequest(model: nnmodel)
    let handler = VNSequenceRequestHandler()
    try? handler.perform([request], onImageData: data!)
    let results = request.results as? [VNCoreMLFeatureValueObservation]
}

```

Currently we are getting results of type VNCoreMLFeatureValueObservation, but they are “hidden” in a strange way like double nested arrays. What I’m trying to say is - we get the raw output. There are types provided in Apples Vision Framework like VNInstanceMaskObservation. But every instance segmentation packed in a Yolo model don’t let getting us VNInstanceMaskObservation types when requesting.

Is there an easy way to extract the mask of a yolo segmentation model in iOS?

Greetings,  
Dom

---

<div class="post-metadata">

**Author:** ![Toxite](https://sea1.discourse-cdn.com/flex001/user_avatar/community.ultralytics.com/toxite/32/123_2.png) [@Toxite](https://community.ultralytics.com/u/Toxite)\
**Post date:** [January 30, 2025, 5:47pm UTC](https://community.ultralytics.com/t/how-to-draw-masks-of-yolov8n-in-ios-app/732/2 "2025-01-30T17:47:34Z")

</div>

The segmentation model doesn’t directly output masks. Instead each object has 32 values that are called mask coefficients which are multiplied with the second output of the model called protos which is of shape `(32, 160, 160)`.

After the multiplication, you get the mask for each object of shape 160x160.

---

<div class="post-metadata">

**Author:** ![Toxite](https://sea1.discourse-cdn.com/flex001/user_avatar/community.ultralytics.com/toxite/32/123_2.png) [@Toxite](https://community.ultralytics.com/u/Toxite)\
**Post date:** [January 30, 2025, 5:51pm UTC](https://community.ultralytics.com/t/how-to-draw-masks-of-yolov8n-in-ios-app/732/3 "2025-01-30T17:51:26Z")

</div>

You can find a Python example here:

> <https://github.com/ultralytics/ultralytics/blob/main/examples/YOLOv8-Segmentation-ONNXRuntime-Python/main.py>

Or you can check GitHub for iOS examples:

> **[Build software better, together](https://github.com/search?q=yolov8%2Bseg%2Blanguage%3Aswift&type=repositories)**
>
> GitHub is where people build software. More than 150 million people use GitHub to discover, fork, and contribute to over 420 million projects.
