Views
No views yet
M3_best_v2.h5 (~98 MB, full Keras 3 model) · License: MIT[rgb 224×224×3, ela 224×224×3]| Metric | Value | Ablation | AUC-ROC | |
|---|---|---|---|---|
| AUC-ROC (test) | 0.9774 | RGB only | 0.5822 | |
| Test accuracy | ~92% | ELA only | 0.9807 | |
| Error rate | ~8% | Dual (M3) | 0.9774 |
tf.image.decode_jpeg → bilinear resize → ÷255.1import io, numpy as np, tensorflow as tf
2from PIL import Image, ImageChops, ImageEnhance
3from huggingface_hub import hf_hub_download
4
5IMG = (224, 224)
6model = tf.keras.models.load_model(hf_hub_download(
7 repo_id="salmanzaman777/digital-image-forgery-detection-model",
8 filename="M3_best_v2.h5"), compile=False)
9
10def ela(img, q=90, scale=15):
11 img = img.convert("RGB"); buf = io.BytesIO(); img.save(buf, "JPEG", quality=q); buf.seek(0)
12 d = ImageEnhance.Brightness(ImageChops.difference(img, Image.open(buf).convert("RGB"))).enhance(scale)
13 out = io.BytesIO(); d.save(out, "JPEG", quality=75)
14 x = tf.image.resize(tf.image.decode_jpeg(out.getvalue(), channels=3), IMG)
15 return (tf.cast(x, tf.float32) / 255.0).numpy()
16
17image = Image.open("test.jpg").convert("RGB")
18rgb = np.array(image.resize(IMG, Image.LANCZOS), np.float32)[np.newaxis] / 255.0
19pred = float(model.predict([rgb, ela(image)[np.newaxis]], verbose=0)[0][0])
20print("FORGED" if pred > 0.5 else "AUTHENTIC", f"(score={pred:.4f})")