Spaces:
Sleeping
Sleeping
jhj0517
commited on
Commit
•
b0345e8
1
Parent(s):
6df697d
Add error message
Browse files- modules/sam_inference.py +9 -4
modules/sam_inference.py
CHANGED
@@ -7,6 +7,7 @@ import torch
|
|
7 |
import os
|
8 |
from datetime import datetime
|
9 |
import numpy as np
|
|
|
10 |
|
11 |
from modules.model_downloader import (
|
12 |
AVAILABLE_MODELS, DEFAULT_MODEL_TYPE, OUTPUT_DIR,
|
@@ -63,7 +64,7 @@ class SamInference:
|
|
63 |
if not is_sam_exist(model_type):
|
64 |
logger.info(f"No SAM2 model found, downloading {model_type} model...")
|
65 |
download_sam_model_url(model_type)
|
66 |
-
logger.info(f"Applying configs to model..")
|
67 |
|
68 |
if load_video_predictor:
|
69 |
try:
|
@@ -182,6 +183,13 @@ class SamInference:
|
|
182 |
pixel_size: Optional[int] = None,
|
183 |
color_hex: Optional[str] = None,
|
184 |
):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
185 |
if self.video_predictor is None or self.video_inference_state is None:
|
186 |
logger.exception("Error while adding filter to preview, load video predictor first")
|
187 |
raise f"Error while adding filter to preview"
|
@@ -213,12 +221,9 @@ class SamInference:
|
|
213 |
labels=point_labels,
|
214 |
box=box
|
215 |
)
|
216 |
-
print("before", logits)
|
217 |
masks = (logits[0] > 0.0).cpu().numpy()
|
218 |
generated_masks = self.format_to_auto_result(masks)
|
219 |
-
print("after", generated_masks)
|
220 |
image = create_mask_pixelized_image(image, generated_masks, pixel_size)
|
221 |
-
#
|
222 |
return image
|
223 |
|
224 |
def divide_layer(self,
|
|
|
7 |
import os
|
8 |
from datetime import datetime
|
9 |
import numpy as np
|
10 |
+
import gradio as gr
|
11 |
|
12 |
from modules.model_downloader import (
|
13 |
AVAILABLE_MODELS, DEFAULT_MODEL_TYPE, OUTPUT_DIR,
|
|
|
64 |
if not is_sam_exist(model_type):
|
65 |
logger.info(f"No SAM2 model found, downloading {model_type} model...")
|
66 |
download_sam_model_url(model_type)
|
67 |
+
logger.info(f"Applying configs to {model_type} model..")
|
68 |
|
69 |
if load_video_predictor:
|
70 |
try:
|
|
|
183 |
pixel_size: Optional[int] = None,
|
184 |
color_hex: Optional[str] = None,
|
185 |
):
|
186 |
+
if not image_prompt_input_data["points"]:
|
187 |
+
error_message = ("Prompt data is empty! Please provide at least one point or box on the image. <br>"
|
188 |
+
"If you've already added prompts, please press the eraser button "
|
189 |
+
"and add your prompts again.")
|
190 |
+
logger.error(error_message)
|
191 |
+
raise gr.Error(error_message, duration=20)
|
192 |
+
|
193 |
if self.video_predictor is None or self.video_inference_state is None:
|
194 |
logger.exception("Error while adding filter to preview, load video predictor first")
|
195 |
raise f"Error while adding filter to preview"
|
|
|
221 |
labels=point_labels,
|
222 |
box=box
|
223 |
)
|
|
|
224 |
masks = (logits[0] > 0.0).cpu().numpy()
|
225 |
generated_masks = self.format_to_auto_result(masks)
|
|
|
226 |
image = create_mask_pixelized_image(image, generated_masks, pixel_size)
|
|
|
227 |
return image
|
228 |
|
229 |
def divide_layer(self,
|