Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -239,12 +239,19 @@ class ForgeryDetector:
|
|
| 239 |
logits, decoder_features = self.model(image_tensor)
|
| 240 |
prob_map = torch.sigmoid(logits).cpu().numpy()[0, 0]
|
| 241 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 242 |
# Refine mask
|
| 243 |
-
binary_mask = (
|
| 244 |
-
refined_mask = self.mask_refiner.refine(
|
| 245 |
|
| 246 |
# Extract regions
|
| 247 |
-
regions = self.region_extractor.extract(refined_mask,
|
| 248 |
|
| 249 |
# Classify regions
|
| 250 |
results = []
|
|
@@ -461,7 +468,7 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 461 |
input_file = gr.Image(
|
| 462 |
label="Document (Image or PDF)",
|
| 463 |
type="filepath",
|
| 464 |
-
sources=["upload"]
|
| 465 |
)
|
| 466 |
|
| 467 |
with gr.Row():
|
|
|
|
| 239 |
logits, decoder_features = self.model(image_tensor)
|
| 240 |
prob_map = torch.sigmoid(logits).cpu().numpy()[0, 0]
|
| 241 |
|
| 242 |
+
# Resize probability map to match original image size to avoid index mismatch errors
|
| 243 |
+
prob_map_resized = cv2.resize(
|
| 244 |
+
prob_map,
|
| 245 |
+
(original_image.shape[1], original_image.shape[0]),
|
| 246 |
+
interpolation=cv2.INTER_LINEAR
|
| 247 |
+
)
|
| 248 |
+
|
| 249 |
# Refine mask
|
| 250 |
+
binary_mask = (prob_map_resized > 0.5).astype(np.uint8)
|
| 251 |
+
refined_mask = self.mask_refiner.refine(prob_map_resized, original_size=original_image.shape[:2])
|
| 252 |
|
| 253 |
# Extract regions
|
| 254 |
+
regions = self.region_extractor.extract(refined_mask, prob_map_resized, original_image)
|
| 255 |
|
| 256 |
# Classify regions
|
| 257 |
results = []
|
|
|
|
| 468 |
input_file = gr.Image(
|
| 469 |
label="Document (Image or PDF)",
|
| 470 |
type="filepath",
|
| 471 |
+
sources=["upload", "webcam"]
|
| 472 |
)
|
| 473 |
|
| 474 |
with gr.Row():
|