Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -402,8 +402,15 @@ class ForgeryDetector:
|
|
| 402 |
# Extract regions
|
| 403 |
regions = self.region_extractor.extract(refined_mask, prob_map_resized, original_image)
|
| 404 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 405 |
# Classify regions
|
| 406 |
results = []
|
|
|
|
|
|
|
| 407 |
for region in regions:
|
| 408 |
# Get decoder features and handle shape
|
| 409 |
df = decoder_features[0].cpu() # Get first decoder feature
|
|
@@ -446,19 +453,36 @@ class ForgeryDetector:
|
|
| 446 |
elif current_features > expected_features:
|
| 447 |
features = features[:, :expected_features]
|
| 448 |
|
| 449 |
-
# Classify
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 453 |
|
| 454 |
# Lower confidence threshold to detect more regions
|
| 455 |
if confidence > 0.5:
|
|
|
|
| 456 |
results.append({
|
| 457 |
'region_id': region['region_id'],
|
| 458 |
'bounding_box': region['bounding_box'],
|
| 459 |
'forgery_type': CLASS_NAMES[forgery_type],
|
| 460 |
'confidence': confidence
|
| 461 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 462 |
|
| 463 |
# Create visualization
|
| 464 |
overlay = self._create_overlay(original_image, results)
|
|
|
|
| 402 |
# Extract regions
|
| 403 |
regions = self.region_extractor.extract(refined_mask, prob_map_resized, original_image)
|
| 404 |
|
| 405 |
+
print(f"[DEBUG] Regions extracted: {len(regions)}")
|
| 406 |
+
if len(regions) > 0:
|
| 407 |
+
print(f"[DEBUG] Region areas: {[r['area'] for r in regions]}")
|
| 408 |
+
print(f"[DEBUG] Region confidences: {[r.get('confidence', 0) for r in regions]}")
|
| 409 |
+
|
| 410 |
# Classify regions
|
| 411 |
results = []
|
| 412 |
+
classified_count = 0
|
| 413 |
+
rejected_count = 0
|
| 414 |
for region in regions:
|
| 415 |
# Get decoder features and handle shape
|
| 416 |
df = decoder_features[0].cpu() # Get first decoder feature
|
|
|
|
| 453 |
elif current_features > expected_features:
|
| 454 |
features = features[:, :expected_features]
|
| 455 |
|
| 456 |
+
# Classify - get probabilities for all classes
|
| 457 |
+
# Temporarily access model directly to get full probabilities
|
| 458 |
+
features_scaled = self.classifier.scaler.transform(features)
|
| 459 |
+
probabilities = self.classifier.model.predict(features_scaled)[0] # Shape: (3,)
|
| 460 |
+
|
| 461 |
+
forgery_type = int(probabilities.argmax())
|
| 462 |
+
confidence = float(probabilities.max())
|
| 463 |
+
|
| 464 |
+
# Log all class probabilities for debugging
|
| 465 |
+
prob_str = ", ".join([f"{CLASS_NAMES[i]}: {probabilities[i]:.3f}" for i in range(3)])
|
| 466 |
+
print(f"[DEBUG] Region {region['region_id']}: {CLASS_NAMES[forgery_type]} (confidence: {confidence:.3f})")
|
| 467 |
+
print(f" All probabilities: {prob_str}")
|
| 468 |
|
| 469 |
# Lower confidence threshold to detect more regions
|
| 470 |
if confidence > 0.5:
|
| 471 |
+
classified_count += 1
|
| 472 |
results.append({
|
| 473 |
'region_id': region['region_id'],
|
| 474 |
'bounding_box': region['bounding_box'],
|
| 475 |
'forgery_type': CLASS_NAMES[forgery_type],
|
| 476 |
'confidence': confidence
|
| 477 |
})
|
| 478 |
+
else:
|
| 479 |
+
rejected_count += 1
|
| 480 |
+
print(f" -> REJECTED (confidence {confidence:.3f} < 0.5)")
|
| 481 |
+
|
| 482 |
+
print(f"[DEBUG] Classification summary:")
|
| 483 |
+
print(f" - Total regions: {len(regions)}")
|
| 484 |
+
print(f" - Classified: {classified_count}")
|
| 485 |
+
print(f" - Rejected: {rejected_count}")
|
| 486 |
|
| 487 |
# Create visualization
|
| 488 |
overlay = self._create_overlay(original_image, results)
|