Spaces:
Sleeping
Sleeping
ניסיון תיקון
Browse files- __pycache__/backend.cpython-310.pyc +0 -0
- __pycache__/webui.cpython-310.pyc +0 -0
- backend.py +19 -39
- checkpoints/sam2.1_hiera_tiny.pt +3 -0
- instruct.txt +28 -0
- requirements.txt +2 -3
__pycache__/backend.cpython-310.pyc
DELETED
Binary file (8.14 kB)
|
|
__pycache__/webui.cpython-310.pyc
DELETED
Binary file (2.09 kB)
|
|
backend.py
CHANGED
@@ -7,8 +7,6 @@ import numpy as np
|
|
7 |
import cv2
|
8 |
from PIL import Image, ImageFilter
|
9 |
from scipy.ndimage import binary_dilation
|
10 |
-
import hydra
|
11 |
-
from hydra import initialize_config_dir, compose
|
12 |
from omegaconf import OmegaConf
|
13 |
|
14 |
# -----------------------------
|
@@ -158,23 +156,28 @@ CONF_THRESHOLD = 0.2
|
|
158 |
# -----------------------------
|
159 |
# 4) הכנה ל-SAM2
|
160 |
# -----------------------------
|
161 |
-
|
162 |
-
|
163 |
-
from sam2.sam2_image_predictor import SAM2ImagePredictor
|
164 |
|
165 |
-
|
166 |
-
|
|
|
167 |
|
168 |
-
|
169 |
-
|
170 |
|
171 |
-
|
172 |
-
|
173 |
-
sam2_predictor
|
|
|
174 |
|
175 |
except Exception as e:
|
176 |
-
print("[SAM2]
|
177 |
-
|
|
|
|
|
|
|
|
|
178 |
sam2_predictor = None
|
179 |
|
180 |
# -----------------------------
|
@@ -231,13 +234,7 @@ def process_image(
|
|
231 |
if not gemini_api_key:
|
232 |
raise ValueError("מפתח API של Gemini אינו מוזן.")
|
233 |
"""
|
234 |
-
פונקציה המקבלת תמונת PIL, מפתח API של Gemini, ומחזירה את התמונה לאחר טשטוש
|
235 |
-
תוך שלבי התקדמות מוגדרים:
|
236 |
-
- זיהוי אנשים ב-YOLO
|
237 |
-
- זיהוי אם אישה בעזרת Gemini
|
238 |
-
- פילוח באמצעות SAM2
|
239 |
-
- טשטוש
|
240 |
-
פרמטר progress_callback: פונקציה לקבלת (fraction, description)
|
241 |
"""
|
242 |
|
243 |
if progress_callback is None:
|
@@ -287,24 +284,7 @@ def process_image(
|
|
287 |
women_boxes.append(bbox)
|
288 |
|
289 |
# 3) שלב SAM2 (עבור בוקסים של נשים)
|
290 |
-
#
|
291 |
-
global sam2_predictor
|
292 |
-
if sam2_predictor is None:
|
293 |
-
try:
|
294 |
-
config_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), SAM2_CONFIG_PATH))
|
295 |
-
with initialize_config_dir(version_base=None, config_dir=config_dir):
|
296 |
-
cfg = compose(config_name="config") # "config" is the name of the config file, replace if necessary
|
297 |
-
sam2_predictor = SAM2ImagePredictor.from_pretrained(SAM2_MODEL_NAME, config=cfg)
|
298 |
-
sam2_predictor.model.to(device)
|
299 |
-
except Exception as e:
|
300 |
-
print(f"[SAM2] שגיאה בטעינת SAM2: {e}")
|
301 |
-
print(f" - סוג השגיאה: {type(e).__name__}")
|
302 |
-
print(f" - הודעת השגיאה: {e}")
|
303 |
-
import traceback
|
304 |
-
print(f" - Traceback:")
|
305 |
-
traceback.print_exc()
|
306 |
-
sam2_predictor = None
|
307 |
-
|
308 |
if sam2_predictor is None:
|
309 |
print("[process_image] SAM2 לא זמין/נטען. מחזירים תמונה ללא טשטוש.")
|
310 |
raise ValueError("SAM2 model is not loaded.")
|
|
|
7 |
import cv2
|
8 |
from PIL import Image, ImageFilter
|
9 |
from scipy.ndimage import binary_dilation
|
|
|
|
|
10 |
from omegaconf import OmegaConf
|
11 |
|
12 |
# -----------------------------
|
|
|
156 |
# -----------------------------
|
157 |
# 4) הכנה ל-SAM2
|
158 |
# -----------------------------
|
159 |
+
from sam2.build_sam import build_sam2
|
160 |
+
from sam2.sam2_image_predictor import SAM2ImagePredictor
|
|
|
161 |
|
162 |
+
# נתיבים יחסיים ל-Space של Hugging Face
|
163 |
+
SAM2_CHECKPOINT = "checkpoints/sam2.1_hiera_tiny.pt" # עדכן את הנתיב בהתאם
|
164 |
+
MODEL_CFG = "configs/sam2.1_hiera_t.yaml"
|
165 |
|
166 |
+
sam2_predictor = None
|
167 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
168 |
|
169 |
+
try:
|
170 |
+
sam2_model = build_sam2(MODEL_CFG, SAM2_CHECKPOINT, device=device)
|
171 |
+
sam2_predictor = SAM2ImagePredictor(sam2_model)
|
172 |
+
print("[SAM2] מודל SAM2 נטען בהצלחה.")
|
173 |
|
174 |
except Exception as e:
|
175 |
+
print(f"[SAM2] שגיאה בטעינת SAM2: {e}")
|
176 |
+
print(f" - סוג השגיאה: {type(e).__name__}")
|
177 |
+
print(f" - הודעת השגיאה: {e}")
|
178 |
+
import traceback
|
179 |
+
print(f" - Traceback:")
|
180 |
+
traceback.print_exc()
|
181 |
sam2_predictor = None
|
182 |
|
183 |
# -----------------------------
|
|
|
234 |
if not gemini_api_key:
|
235 |
raise ValueError("מפתח API של Gemini אינו מוזן.")
|
236 |
"""
|
237 |
+
פונקציה המקבלת תמונת PIL, מפתח API של Gemini, ומחזירה את התמונה לאחר טשטוש נשים.
|
|
|
|
|
|
|
|
|
|
|
|
|
238 |
"""
|
239 |
|
240 |
if progress_callback is None:
|
|
|
284 |
women_boxes.append(bbox)
|
285 |
|
286 |
# 3) שלב SAM2 (עבור בוקסים של נשים)
|
287 |
+
# אין צורך לאתחל Hydra, פשוט משתמשים ב-sam2_predictor
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
288 |
if sam2_predictor is None:
|
289 |
print("[process_image] SAM2 לא זמין/נטען. מחזירים תמונה ללא טשטוש.")
|
290 |
raise ValueError("SAM2 model is not loaded.")
|
checkpoints/sam2.1_hiera_tiny.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7402e0d864fa82708a20fbd15bc84245c2f26dff0eb43a4b5b93452deb34be69
|
3 |
+
size 156008466
|
instruct.txt
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
C:.
|
2 |
+
│ .gitattributes
|
3 |
+
│ .gitignore
|
4 |
+
│ app.py
|
5 |
+
│ backend.py
|
6 |
+
│ README.md
|
7 |
+
│ requirements.txt
|
8 |
+
│
|
9 |
+
├───checkpoints
|
10 |
+
├───configs
|
11 |
+
│ sam2.1_hiera_t.yaml
|
12 |
+
│
|
13 |
+
├───example_images
|
14 |
+
│ example.jpg
|
15 |
+
│
|
16 |
+
├───sam2.1
|
17 |
+
│ ├───checkpoints
|
18 |
+
│ └───configs
|
19 |
+
│ └───sam2.1
|
20 |
+
│ sam2.1_hiera_b+.yaml
|
21 |
+
│ sam2.1_hiera_l.yaml
|
22 |
+
│ sam2.1_hiera_s.yaml
|
23 |
+
│ sam2.1_hiera_t.yaml
|
24 |
+
│
|
25 |
+
└───__pycache__
|
26 |
+
app.cpython-310.pyc
|
27 |
+
backend.cpython-310.pyc
|
28 |
+
webui.cpython-310.pyc
|
requirements.txt
CHANGED
@@ -6,8 +6,7 @@ Pillow
|
|
6 |
requests
|
7 |
ultralytics
|
8 |
scipy
|
9 |
-
|
10 |
torchvision
|
11 |
supervision
|
12 |
-
git+https://github.com/facebookresearch/sam2.git
|
13 |
-
omegaconf
|
|
|
6 |
requests
|
7 |
ultralytics
|
8 |
scipy
|
9 |
+
omegaconf
|
10 |
torchvision
|
11 |
supervision
|
12 |
+
git+https://github.com/facebookresearch/sam2.git
|
|