Update pipeline.py
Browse files- pipeline.py +11 -3
pipeline.py
CHANGED
|
@@ -4,8 +4,8 @@ from typing import Any, Dict, List
|
|
| 4 |
import tensorflow as tf
|
| 5 |
from tensorflow import keras
|
| 6 |
from huggingface_hub import from_pretrained_keras, hf_hub_download
|
| 7 |
-
from PIL import Image
|
| 8 |
import base64
|
|
|
|
| 9 |
import numpy as np
|
| 10 |
from PIL import Image
|
| 11 |
|
|
@@ -45,8 +45,16 @@ class PreTrainedPipeline():
|
|
| 45 |
else:
|
| 46 |
binary_masks[f"mask_{cls}"][row][col] = 0
|
| 47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
-
mask_codes[f"mask_{cls}"] =
|
| 50 |
|
| 51 |
|
| 52 |
for i in range(pred_mask.shape[-1]): #for every class
|
|
@@ -56,4 +64,4 @@ class PreTrainedPipeline():
|
|
| 56 |
"mask": mask_codes[f"mask_{i}"],
|
| 57 |
"score": 1.0,
|
| 58 |
})
|
| 59 |
-
|
|
|
|
| 4 |
import tensorflow as tf
|
| 5 |
from tensorflow import keras
|
| 6 |
from huggingface_hub import from_pretrained_keras, hf_hub_download
|
|
|
|
| 7 |
import base64
|
| 8 |
+
import io
|
| 9 |
import numpy as np
|
| 10 |
from PIL import Image
|
| 11 |
|
|
|
|
| 45 |
else:
|
| 46 |
binary_masks[f"mask_{cls}"][row][col] = 0
|
| 47 |
|
| 48 |
+
mask = binary_masks[f"mask_{cls}"]
|
| 49 |
+
mask *= 255
|
| 50 |
+
img = Image.fromarray(mask.astype(np.int8), mode="L")
|
| 51 |
+
|
| 52 |
+
with io.BytesIO() as out:
|
| 53 |
+
img.save(out, format="PNG")
|
| 54 |
+
png_string = out.getvalue()
|
| 55 |
+
mask = base64.b64encode(png_string).decode("utf-8")
|
| 56 |
|
| 57 |
+
mask_codes[f"mask_{cls}"] = mask
|
| 58 |
|
| 59 |
|
| 60 |
for i in range(pred_mask.shape[-1]): #for every class
|
|
|
|
| 64 |
"mask": mask_codes[f"mask_{i}"],
|
| 65 |
"score": 1.0,
|
| 66 |
})
|
| 67 |
+
return labels
|