husseinelsaadi commited on
Commit
ea539e1
·
verified ·
1 Parent(s): a61e448

judge the whole frame, not just the centre square

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -41,7 +41,7 @@ THRESHOLD_OVERRIDE = float(os.environ.get("THRESHOLD", "0.71"))
41
  TOKEN = os.environ.get("HF_TOKEN")
42
 
43
  sys.path.insert(0, snapshot_download(CODE_REPO, repo_type="dataset", token=TOKEN))
44
- from preprocess import canonical_pil, five_crops # noqa: E402
45
  from transforms import CLIP_MEAN, CLIP_STD # noqa: E402
46
  from models import build_model, load_checkpoint_into # noqa: E402
47
 
@@ -130,9 +130,11 @@ def predict(image: Image.Image):
130
  dev = "cuda" if torch.cuda.is_available() else "cpu"
131
  MODEL.to(dev)
132
 
133
- # Same pipeline as training, then 5 crops averaged in LOGIT space (averaging
134
- # probabilities would let one saturated crop dominate).
135
- crops = five_crops(image)
 
 
136
  batch = torch.stack([_to_tensor(c) for c in crops]).to(dev)
137
  logits = MODEL(batch).float().cpu().numpy() / TEMPERATURE
138
  logit = float(np.mean(logits))
@@ -150,8 +152,8 @@ def predict(image: Image.Image):
150
  f"**{verdict}**\n\n"
151
  f"- P(AI-generated) = **{p_ai:.1%}** (calibrated, T={TEMPERATURE:.2f})\n"
152
  f"- decision threshold = {THRESHOLD:.2f}, tuned on **unseen-generator** data\n"
153
- f"- agreement across the 5 crops: ±{spread:.1%} "
154
- f"{'(consistent)' if spread < 0.15 else '(crops disagree — treat with caution)'}\n\n"
155
  f"*Trained on {RUN}. Detectors are weaker on generators they have never seen; "
156
  f"treat this as evidence, not proof.*"
157
  )
 
41
  TOKEN = os.environ.get("HF_TOKEN")
42
 
43
  sys.path.insert(0, snapshot_download(CODE_REPO, repo_type="dataset", token=TOKEN))
44
+ from preprocess import canonical_pil, whole_frame_tiles # noqa: E402
45
  from transforms import CLIP_MEAN, CLIP_STD # noqa: E402
46
  from models import build_model, load_checkpoint_into # noqa: E402
47
 
 
130
  dev = "cuda" if torch.cuda.is_available() else "cpu"
131
  MODEL.to(dev)
132
 
133
+ # Windows spanning the WHOLE frame, each cropped at native resolution and then put
134
+ # through the training pipeline. Averaged in LOGIT space (averaging probabilities
135
+ # would let one saturated window dominate). See preprocess.whole_frame_tiles for
136
+ # why centre-only cropping was wrong.
137
+ crops = whole_frame_tiles(image)
138
  batch = torch.stack([_to_tensor(c) for c in crops]).to(dev)
139
  logits = MODEL(batch).float().cpu().numpy() / TEMPERATURE
140
  logit = float(np.mean(logits))
 
152
  f"**{verdict}**\n\n"
153
  f"- P(AI-generated) = **{p_ai:.1%}** (calibrated, T={TEMPERATURE:.2f})\n"
154
  f"- decision threshold = {THRESHOLD:.2f}, tuned on **unseen-generator** data\n"
155
+ f"- agreement across the {len(crops)} frame windows: ±{spread:.1%} "
156
+ f"{'(consistent)' if spread < 0.15 else '(windows disagree — treat with caution)'}\n\n"
157
  f"*Trained on {RUN}. Detectors are weaker on generators they have never seen; "
158
  f"treat this as evidence, not proof.*"
159
  )