Spaces:
Runtime error
Runtime error
Fix preprocessing bug
Browse files
app.py
CHANGED
|
@@ -14,7 +14,6 @@ from segment_anything import SamAutomaticMaskGenerator, sam_model_registry
|
|
| 14 |
CHECKPOINT_PATH = "sam_vit_h_4b8939.pth"
|
| 15 |
MODEL_TYPE = "default"
|
| 16 |
MAX_WIDTH = MAX_HEIGHT = 800
|
| 17 |
-
CLIP_WIDTH = CLIP_HEIGHT = 300
|
| 18 |
THRESHOLD = 0.05
|
| 19 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 20 |
|
|
@@ -85,8 +84,7 @@ def filter_masks(
|
|
| 85 |
masked = image * np.expand_dims(mask["segmentation"], -1)
|
| 86 |
crop = masked[y: y + h, x: x + w]
|
| 87 |
crop = cv2.cvtColor(crop, cv2.COLOR_BGR2RGB)
|
| 88 |
-
crop = PIL.Image.fromarray(crop
|
| 89 |
-
crop.resize((CLIP_WIDTH, CLIP_HEIGHT))
|
| 90 |
cropped_masks.append(crop)
|
| 91 |
|
| 92 |
if query and filtered_masks:
|
|
@@ -162,7 +160,7 @@ demo = gr.Interface(
|
|
| 162 |
[
|
| 163 |
0.9,
|
| 164 |
0.8,
|
| 165 |
-
0.
|
| 166 |
os.path.join(os.path.dirname(__file__), "examples/dog.jpg"),
|
| 167 |
"A dog",
|
| 168 |
],
|
|
@@ -171,7 +169,7 @@ demo = gr.Interface(
|
|
| 171 |
0.8,
|
| 172 |
0.05,
|
| 173 |
os.path.join(os.path.dirname(__file__), "examples/city.jpg"),
|
| 174 |
-
"
|
| 175 |
],
|
| 176 |
[
|
| 177 |
0.9,
|
|
|
|
| 14 |
CHECKPOINT_PATH = "sam_vit_h_4b8939.pth"
|
| 15 |
MODEL_TYPE = "default"
|
| 16 |
MAX_WIDTH = MAX_HEIGHT = 800
|
|
|
|
| 17 |
THRESHOLD = 0.05
|
| 18 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 19 |
|
|
|
|
| 84 |
masked = image * np.expand_dims(mask["segmentation"], -1)
|
| 85 |
crop = masked[y: y + h, x: x + w]
|
| 86 |
crop = cv2.cvtColor(crop, cv2.COLOR_BGR2RGB)
|
| 87 |
+
crop = PIL.Image.fromarray(crop)
|
|
|
|
| 88 |
cropped_masks.append(crop)
|
| 89 |
|
| 90 |
if query and filtered_masks:
|
|
|
|
| 160 |
[
|
| 161 |
0.9,
|
| 162 |
0.8,
|
| 163 |
+
0.15,
|
| 164 |
os.path.join(os.path.dirname(__file__), "examples/dog.jpg"),
|
| 165 |
"A dog",
|
| 166 |
],
|
|
|
|
| 169 |
0.8,
|
| 170 |
0.05,
|
| 171 |
os.path.join(os.path.dirname(__file__), "examples/city.jpg"),
|
| 172 |
+
"water",
|
| 173 |
],
|
| 174 |
[
|
| 175 |
0.9,
|