Vivien Chappelier commited on
Commit
42100b6
1 Parent(s): ab3d5c6
Files changed (1) hide show
  1. detect_demo_pvalue.py +4 -3
detect_demo_pvalue.py CHANGED
@@ -12,11 +12,12 @@ calibration = hf_hub_download("imatag/stable-signature-bzh-detector-resnet18", f
12
  with safe_open(calibration, framework="pt") as f:
13
  calibration_logits = f.get_tensor("logits")
14
 
15
- img = Image.open(sys.argv[1]).convert("RGB")
 
16
  inputs = image_processor(img, return_tensors="pt")
17
  with torch.no_grad():
18
- p = model(**inputs).logits[...,0]
19
- p = (1 + torch.searchsorted(calibration_logits, p)) / calibration_logits.shape[0]
20
  p = p.item()
21
 
22
  print(f"approximate p-value: {p}")
 
12
  with safe_open(calibration, framework="pt") as f:
13
  calibration_logits = f.get_tensor("logits")
14
 
15
+ filename = sys.argv[1]
16
+ img = Image.open(filename).convert("RGB")
17
  inputs = image_processor(img, return_tensors="pt")
18
  with torch.no_grad():
19
+ p = model(**inputs).logits[...,0:1]
20
+ p = (1 + torch.sum(calibration_logits <= p, dim=-1)) / calibration_logits.shape[0]
21
  p = p.item()
22
 
23
  print(f"approximate p-value: {p}")