Fix ELA computation to match train.py (ImageChops.multiply, not Brightness)
Browse filesThe model trained on attenuated/dark ELA images (multiply divides by 255),
but app.py was amplifying them via Brightness.enhance, causing every image
to saturate the ELA branch and predict FORGED.
app.py
CHANGED
|
@@ -20,7 +20,12 @@ def compute_ela(original, quality=ELA_QUALITY, scale=ELA_SCALE):
|
|
| 20 |
compressed = Image.open(buf)
|
| 21 |
|
| 22 |
ela_image = ImageChops.difference(original, compressed)
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
return ela_image
|
| 25 |
|
| 26 |
def get_gradcam(model, input_data):
|
|
|
|
| 20 |
compressed = Image.open(buf)
|
| 21 |
|
| 22 |
ela_image = ImageChops.difference(original, compressed)
|
| 23 |
+
# Must match train.py exactly: ImageChops.multiply divides by 255 internally,
|
| 24 |
+
# so this attenuates (diff * scale / 255) rather than amplifies. The model was
|
| 25 |
+
# trained on these dark ELA images — using Brightness.enhance here breaks it.
|
| 26 |
+
ela_image = ImageChops.multiply(
|
| 27 |
+
ela_image, Image.new('RGB', ela_image.size, (scale, scale, scale))
|
| 28 |
+
)
|
| 29 |
return ela_image
|
| 30 |
|
| 31 |
def get_gradcam(model, input_data):
|