V4ldeLund commited on
Commit
d72d900
·
verified ·
1 Parent(s): 1be8e93

Remove mask output; keep heatmap overlay only

Browse files
Files changed (1) hide show
  1. app.py +2 -20
app.py CHANGED
@@ -93,27 +93,10 @@ def infer(ref_files, test_file, use_sam3, sam_prompt):
93
  model.fit(ref_paths, n_ref=len(ref_paths))
94
  image, amap, score = model.predict(test_path)
95
 
96
- # Default empty mask for UI (in case SAM3 is off or fails)
97
- fg_mask_img = Image.fromarray(np.zeros((image.shape[0], image.shape[1]), dtype=np.uint8))
98
- if segmenter is not None:
99
- # Compute full-resolution mask for visualization and for suppressing background
100
- fg_mask = segmenter.get_object_mask(image)
101
- # Resize mask to anomaly map resolution
102
- fg_mask_resized = fg_mask
103
- if fg_mask.shape != amap.shape:
104
- fg_mask_resized = cv2.resize(
105
- fg_mask.astype(np.float32),
106
- (amap.shape[1], amap.shape[0]),
107
- interpolation=cv2.INTER_NEAREST,
108
- ) > 0.5
109
- # Apply mask to anomaly map to suppress background leakage
110
- amap = amap * fg_mask_resized
111
- fg_mask_img = Image.fromarray((fg_mask.astype(np.uint8) * 255))
112
-
113
  overlay = _make_overlay(image, amap)
114
 
115
  status_text = "\n".join(status_lines) if status_lines else f"Ran on {device}."
116
- return overlay, fg_mask_img, float(score), status_text
117
 
118
 
119
  def build_demo():
@@ -138,14 +121,13 @@ def build_demo():
138
 
139
  run_btn = gr.Button("Run", variant="primary")
140
  overlay_out = gr.Image(label="Heatmap overlay", type="pil")
141
- mask_out = gr.Image(label="Foreground mask (if SAM3)", type="pil", image_mode="L")
142
  score_out = gr.Number(label="Image anomaly score (mean top 1% distance)")
143
  status_out = gr.Markdown(label="Status / tips")
144
 
145
  run_btn.click(
146
  infer,
147
  inputs=[ref_in, test_in, use_sam, sam_prompt],
148
- outputs=[overlay_out, mask_out, score_out, status_out],
149
  )
150
 
151
  return demo
 
93
  model.fit(ref_paths, n_ref=len(ref_paths))
94
  image, amap, score = model.predict(test_path)
95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  overlay = _make_overlay(image, amap)
97
 
98
  status_text = "\n".join(status_lines) if status_lines else f"Ran on {device}."
99
+ return overlay, float(score), status_text
100
 
101
 
102
  def build_demo():
 
121
 
122
  run_btn = gr.Button("Run", variant="primary")
123
  overlay_out = gr.Image(label="Heatmap overlay", type="pil")
 
124
  score_out = gr.Number(label="Image anomaly score (mean top 1% distance)")
125
  status_out = gr.Markdown(label="Status / tips")
126
 
127
  run_btn.click(
128
  infer,
129
  inputs=[ref_in, test_in, use_sam, sam_prompt],
130
+ outputs=[overlay_out, score_out, status_out],
131
  )
132
 
133
  return demo