Spaces:
Running
Running
Commit
·
d367c2f
1
Parent(s):
183692d
adding app with CLIP image segmentation
Browse files
app.py
CHANGED
@@ -37,7 +37,7 @@ def detect_using_clip(image,prompts=[],threshould=0.4):
|
|
37 |
|
38 |
return predicted_masks
|
39 |
|
40 |
-
def visualize_images(image,predicted_images,brightness=15):
|
41 |
alpha = 0.7
|
42 |
image_resize = cv2.resize(image,(352,352))
|
43 |
resize_image_copy = image_resize.copy()
|
@@ -45,9 +45,9 @@ def visualize_images(image,predicted_images,brightness=15):
|
|
45 |
for mask_image in predicted_images:
|
46 |
resize_image_copy = cv2.addWeighted(resize_image_copy,alpha,mask_image,1-alpha,10)
|
47 |
|
48 |
-
return cv2.convertScaleAbs(resize_image_copy, alpha=
|
49 |
|
50 |
-
def shot(brightness,image,
|
51 |
if "," in labels_text:
|
52 |
prompts = labels_text.split(',')
|
53 |
else:
|
@@ -55,20 +55,23 @@ def shot(brightness,image, labels_text):
|
|
55 |
prompts = list(map(lambda x: x.strip(),prompts))
|
56 |
predicted_images = detect_using_clip(image,prompts=prompts)
|
57 |
|
58 |
-
category_image = visualize_images(image=image,predicted_images=predicted_images,brightness=brightness)
|
59 |
return category_image
|
60 |
|
61 |
iface = gr.Interface(fn=shot,
|
62 |
-
inputs = [
|
|
|
|
|
|
|
|
|
|
|
63 |
outputs = "image",
|
64 |
description ="Add an Image and lists of category to be detected separated by commas(atleast 2 )",
|
65 |
title = "Zero-shot Image Segmentation with Prompt ",
|
66 |
examples=[
|
67 |
-
[15,"images/room.jpg","bed, table, plant, light, window,light"],
|
68 |
-
[10,"images/image2.png","banner, building,door, sign,"],
|
69 |
[19,"images/seats.jpg","door,table,chairs"],
|
70 |
-
[20,"images/vegetables.jpg","carrot,radish,
|
71 |
-
[17,"images/room2.jpg","door,
|
72 |
],
|
73 |
# allow_flagging=False,
|
74 |
# analytics_enabled=False,
|
|
|
37 |
|
38 |
return predicted_masks
|
39 |
|
40 |
+
def visualize_images(image,predicted_images,brightness=15,contrast=1.8):
|
41 |
alpha = 0.7
|
42 |
image_resize = cv2.resize(image,(352,352))
|
43 |
resize_image_copy = image_resize.copy()
|
|
|
45 |
for mask_image in predicted_images:
|
46 |
resize_image_copy = cv2.addWeighted(resize_image_copy,alpha,mask_image,1-alpha,10)
|
47 |
|
48 |
+
return cv2.convertScaleAbs(resize_image_copy, alpha=contrast, beta=brightness)
|
49 |
|
50 |
+
def shot(brightness,contrast,image,labels_text):
|
51 |
if "," in labels_text:
|
52 |
prompts = labels_text.split(',')
|
53 |
else:
|
|
|
55 |
prompts = list(map(lambda x: x.strip(),prompts))
|
56 |
predicted_images = detect_using_clip(image,prompts=prompts)
|
57 |
|
58 |
+
category_image = visualize_images(image=image,predicted_images=predicted_images,brightness=brightness,contrast=contrast)
|
59 |
return category_image
|
60 |
|
61 |
iface = gr.Interface(fn=shot,
|
62 |
+
inputs = [
|
63 |
+
gr.Slider(5, 50, value=15, label="Brightness", info="Choose between 5 and 50"),
|
64 |
+
gr.Slider(1, 5, value=1.5, label="Contrast", info="Choose between 1 and 5"),
|
65 |
+
"image",
|
66 |
+
"text"
|
67 |
+
],
|
68 |
outputs = "image",
|
69 |
description ="Add an Image and lists of category to be detected separated by commas(atleast 2 )",
|
70 |
title = "Zero-shot Image Segmentation with Prompt ",
|
71 |
examples=[
|
|
|
|
|
72 |
[19,"images/seats.jpg","door,table,chairs"],
|
73 |
+
[20,"images/vegetables.jpg","carrot,white radish,brinjal,basket,potato"],
|
74 |
+
[17,"images/room2.jpg","door, plants, dog, coffe table, table lamp, carpet, door"]
|
75 |
],
|
76 |
# allow_flagging=False,
|
77 |
# analytics_enabled=False,
|