mobilesam v1.2
Browse files
app.py
CHANGED
|
@@ -30,7 +30,7 @@ def greet_json():
|
|
| 30 |
@app.post("/predict_full")
|
| 31 |
async def predict_full(
|
| 32 |
file: UploadFile = File(...),
|
| 33 |
-
point_x: int = Query(..., description="X-координата точки на фрукте
|
| 34 |
point_y: int = Query(..., description="Y-координата точки на фрукте"),
|
| 35 |
return_cropped: bool = Query(default=True, description="Вернуть обрезанное изображение в base64?"),
|
| 36 |
cropped_size: int = Query(224, description="Размер обрезанного изображения (100 или 224)")
|
|
@@ -43,7 +43,8 @@ async def predict_full(
|
|
| 43 |
input_point = np.array([[point_x, point_y]])
|
| 44 |
input_label = np.array([1]) # 1 = foreground
|
| 45 |
|
| 46 |
-
|
|
|
|
| 47 |
image=orig_np,
|
| 48 |
point_coords=input_point,
|
| 49 |
point_labels=input_label,
|
|
@@ -103,7 +104,7 @@ async def predict_full(
|
|
| 103 |
result["freshness"] = fresh_name
|
| 104 |
result["freshness_confidence"] = round(fresh_conf, 4)
|
| 105 |
|
| 106 |
-
# Возвращаем обрезанное изображение
|
| 107 |
if return_cropped:
|
| 108 |
cropped_final = crop_fruit_with_white_bg(orig_np, mask, out_size=cropped_size)
|
| 109 |
pil_img = Image.fromarray(cropped_final)
|
|
|
|
| 30 |
@app.post("/predict_full")
|
| 31 |
async def predict_full(
|
| 32 |
file: UploadFile = File(...),
|
| 33 |
+
point_x: int = Query(..., description="X-координата точки на фрукте"),
|
| 34 |
point_y: int = Query(..., description="Y-координата точки на фрукте"),
|
| 35 |
return_cropped: bool = Query(default=True, description="Вернуть обрезанное изображение в base64?"),
|
| 36 |
cropped_size: int = Query(224, description="Размер обрезанного изображения (100 или 224)")
|
|
|
|
| 43 |
input_point = np.array([[point_x, point_y]])
|
| 44 |
input_label = np.array([1]) # 1 = foreground
|
| 45 |
|
| 46 |
+
# Правильный вызов MobileSAM (без set_image!)
|
| 47 |
+
masks, scores, logits = sam_model(
|
| 48 |
image=orig_np,
|
| 49 |
point_coords=input_point,
|
| 50 |
point_labels=input_label,
|
|
|
|
| 104 |
result["freshness"] = fresh_name
|
| 105 |
result["freshness_confidence"] = round(fresh_conf, 4)
|
| 106 |
|
| 107 |
+
# Возвращаем обрезанное изображение
|
| 108 |
if return_cropped:
|
| 109 |
cropped_final = crop_fruit_with_white_bg(orig_np, mask, out_size=cropped_size)
|
| 110 |
pil_img = Image.fromarray(cropped_final)
|
utils.py
CHANGED
|
@@ -17,7 +17,7 @@ def preprocess_for_classifier(img: np.ndarray) -> torch.Tensor:
|
|
| 17 |
])
|
| 18 |
return transform(img)
|
| 19 |
|
| 20 |
-
# Letterbox без искажения
|
| 21 |
def letterbox_any_size(
|
| 22 |
img: np.ndarray,
|
| 23 |
target_size: int = 224,
|
|
|
|
| 17 |
])
|
| 18 |
return transform(img)
|
| 19 |
|
| 20 |
+
# Letterbox без искажения
|
| 21 |
def letterbox_any_size(
|
| 22 |
img: np.ndarray,
|
| 23 |
target_size: int = 224,
|