Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,32 @@
|
|
1 |
import streamlit as st
|
2 |
from PIL import Image
|
3 |
from transformers import pipeline
|
|
|
|
|
|
|
4 |
|
5 |
semantic_segmentation = pipeline("image-segmentation", "nvidia/segformer-b1-finetuned-cityscapes-1024-1024")
|
6 |
|
7 |
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
if uploaded_file is not None:
|
9 |
image = Image.open(uploaded_file)
|
10 |
st.image(image, caption='Uploaded Image.', use_column_width=True)
|
|
|
1 |
import streamlit as st
|
2 |
from PIL import Image
|
3 |
from transformers import pipeline
|
4 |
+
import numpy as np
|
5 |
+
import cv2
|
6 |
+
import matplotlib.cm as cm
|
7 |
|
8 |
semantic_segmentation = pipeline("image-segmentation", "nvidia/segformer-b1-finetuned-cityscapes-1024-1024")
|
9 |
|
10 |
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png"])
|
11 |
+
|
12 |
+
def draw_masks_fromDict(image, results):
|
13 |
+
masked_image = image.copy()
|
14 |
+
|
15 |
+
colormap = cm.get_cmap('nipy_spectral')
|
16 |
+
|
17 |
+
for i, result in enumerate(results):
|
18 |
+
mask = np.array(result['mask'])
|
19 |
+
mask = np.repeat(mask[:, :, np.newaxis], 3, axis=2)
|
20 |
+
|
21 |
+
color = colormap(i / len(results))[:3]
|
22 |
+
color = tuple(int(c * 255) for c in color)
|
23 |
+
|
24 |
+
masked_image = np.where(mask, color, masked_image)
|
25 |
+
|
26 |
+
masked_image = masked_image.astype(np.uint8)
|
27 |
+
return cv2.addWeighted(image, 0.3, masked_image, 0.7, 0)
|
28 |
+
|
29 |
+
|
30 |
if uploaded_file is not None:
|
31 |
image = Image.open(uploaded_file)
|
32 |
st.image(image, caption='Uploaded Image.', use_column_width=True)
|