Repository: voxel51/fiftyone

Issue:
[BUG] Setting "mask_targets" for Segmentation Dataset does not show labels in App
### System information

-   **OS Platform and Distribution (e.g., Linux Ubuntu 16.04)**: Windows 10
-   **FiftyOne installed from (pip or source)**: pip
-   **FiftyOne version (run `fiftyone --version`)**: v0.16.5
-   **Python version**: 3.9.1

### Describe the problem

The [docs](https://voxel51.com/docs/fiftyone/user_guide/using_datasets.html#storing-mask-targets) say:
When you load datasets with [Segmentation](https://voxel51.com/docs/fiftyone/api/fiftyone.core.labels.html#fiftyone.core.labels.Segmentation) fields in the App that have corresponding mask targets, the label strings will appear in the App’s tooltip when you hover over pixels.

But the mask_targets are not used as can be seen here:
![grafik](https://user-images.githubusercontent.com/39338429/179057642-cfded6e6-e41a-4d0b-b46e-efa52aa9917e.png)

### Code to reproduce issue

```python
import fiftyone as fo
import numpy as np
import cv2

dataset = fo.Dataset()

# Set default mask targets
dataset.default_mask_targets = {1: "cat", 2: "dog"}
dataset.mask_targets = {
    "segmentation": {1: "cat", 2: "dog"},
}
dataset.save()  # must save after edits

data = np.random.randint(255, size=(2000, 2000))
cv2.imwrite("data.png", data)


mask = np.random.randint(3, size=(2000, 2000))

sample = fo.Sample(filepath="data.png")

sample["segmentation"] = fo.Segmentation(mask=mask)
dataset.add_sample(sample)

if __name__ == "__main__":
    session = fo.launch_app(dataset)
    session.wait()

```

### What areas of FiftyOne does this bug affect?

-   [x] `App`: FiftyOne application issue
-   [x] `Core`: Core `fiftyone` Python library issue
-   [ ] `Server`: Fiftyone server issue

### Willingness to contribute

The FiftyOne Community encourages bug fix contributions. Would you or another
member of your organization be willing to contribute a fix for this bug to the
FiftyOne codebase?

-   [ ] Yes. I can contribute a fix for this bug independently.
-   [x] Yes. I would be willing to contribute a fix for this bug with guidance
        from the FiftyOne community.
-   [ ] No. I cannot contribute a bug fix at this time.



Discussion:
I was able to reproduce this.

@benjaminpkane would this be easy for @Sa-Schmi to fix? Thanks for volunteering btw 🤗 

Resolving patch:
diff --git a/fiftyone/server/query.py b/fiftyone/server/query.py
--- a/fiftyone/server/query.py
+++ b/fiftyone/server/query.py
@@ -149,10 +149,14 @@ def get_collection_name() -> str:
 
     @staticmethod
     def modifier(doc: dict) -> dict:
-
         doc["id"] = doc.pop("_id")
-        doc["mask_targets"] = []
-        doc["default_mask_targets"] = []
+        doc["default_mask_targets"] = _convert_targets(
+            doc.get("default_mask_targets", [])
+        )
+        doc["mask_targets"] = [
+            NamedTargets(name, _convert_targets(targets))
+            for name, targets in doc.get("mask_targets", []).items()
+        ]
         doc["sample_fields"] = _flatten_fields([], doc["sample_fields"])
         doc["frame_fields"] = _flatten_fields([], doc["frame_fields"])
         doc["brain_methods"] = list(doc.get("brain_methods", {}).values())
@@ -326,3 +330,7 @@ def _flatten_fields(
             result = result + _flatten_fields(field_path, fields)
 
     return result
+
+
+def _convert_targets(targets: t.Dict[str, str]) -> Target:
+    return [Target(value=v, target=int(k)) for k, v in targets.items()]


Test patch: