kk
Browse files- Acnes_model.pth +2 -2
- app.py +12 -4
Acnes_model.pth
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c58a6af6fb622d916e4aa788d9f620d59df4a42209f655ce4a9db49686c05697
|
| 3 |
+
size 97920000
|
app.py
CHANGED
|
@@ -12,8 +12,17 @@ MODEL_PATH = "Acnes_model.pth"
|
|
| 12 |
MASK_OPACITY = 0.9
|
| 13 |
DEVICE = torch.device("cpu")
|
| 14 |
|
| 15 |
-
# -----------------
|
| 16 |
-
model
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
model.to(DEVICE)
|
| 18 |
model.eval()
|
| 19 |
|
|
@@ -66,7 +75,6 @@ def predict(image):
|
|
| 66 |
predicted_mask = predict_mask(model, input_tensor)
|
| 67 |
overlayed_image = overlay_mask(original_image, predicted_mask, color=(255, 0, 0), alpha=MASK_OPACITY)
|
| 68 |
|
| 69 |
-
# Save to disk for classification model (transformers pipeline accepts paths)
|
| 70 |
temp_path = "/tmp/temp_image.jpg"
|
| 71 |
cv2.imwrite(temp_path, cv2.cvtColor(original_image, cv2.COLOR_RGB2BGR))
|
| 72 |
|
|
@@ -85,7 +93,7 @@ demo = gr.Interface(
|
|
| 85 |
gr.Image(label="Segmentation Overlay"),
|
| 86 |
gr.Text(label="Acne Severity Prediction")
|
| 87 |
],
|
| 88 |
-
title="Acne Segmentation & Severity Classification",
|
| 89 |
description="Upload a facial image to detect acne regions and predict severity level using UNet and a pretrained classifier."
|
| 90 |
)
|
| 91 |
|
|
|
|
| 12 |
MASK_OPACITY = 0.9
|
| 13 |
DEVICE = torch.device("cpu")
|
| 14 |
|
| 15 |
+
# ----------------- Rebuild Model & Load Weights -----------------
|
| 16 |
+
# Recreate your model (same as in training)
|
| 17 |
+
model = smp.Unet(
|
| 18 |
+
encoder_name="resnet34",
|
| 19 |
+
encoder_weights=None,
|
| 20 |
+
in_channels=3,
|
| 21 |
+
classes=1
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
# Load weights only (safe)
|
| 25 |
+
model.load_state_dict(torch.load(MODEL_PATH, map_location=DEVICE))
|
| 26 |
model.to(DEVICE)
|
| 27 |
model.eval()
|
| 28 |
|
|
|
|
| 75 |
predicted_mask = predict_mask(model, input_tensor)
|
| 76 |
overlayed_image = overlay_mask(original_image, predicted_mask, color=(255, 0, 0), alpha=MASK_OPACITY)
|
| 77 |
|
|
|
|
| 78 |
temp_path = "/tmp/temp_image.jpg"
|
| 79 |
cv2.imwrite(temp_path, cv2.cvtColor(original_image, cv2.COLOR_RGB2BGR))
|
| 80 |
|
|
|
|
| 93 |
gr.Image(label="Segmentation Overlay"),
|
| 94 |
gr.Text(label="Acne Severity Prediction")
|
| 95 |
],
|
| 96 |
+
title="🧼 Acne Segmentation & Severity Classification",
|
| 97 |
description="Upload a facial image to detect acne regions and predict severity level using UNet and a pretrained classifier."
|
| 98 |
)
|
| 99 |
|