Skip to content

Commit 9772cfb

Browse files
authored
Update run_patchcore.py
Test
1 parent 156bc38 commit 9772cfb

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

bin/run_patchcore.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -174,33 +174,34 @@ def mask_transform(mask):
174174
)
175175

176176
LOGGER.info("Computing evaluation metrics.")
177-
auroc = patchcore.metrics.compute_imagewise_retrieval_metrics(
178-
scores, anomaly_labels
179-
)["auroc"]
180-
181-
# Compute PRO score & PW Auroc for all images
182-
pixel_scores = patchcore.metrics.compute_pixelwise_retrieval_metrics(
183-
segmentations, masks_gt
184-
)
185-
full_pixel_auroc = pixel_scores["auroc"]
186-
187-
# Compute PRO score & PW Auroc only images with anomalies
188-
sel_idxs = []
189-
for i in range(len(masks_gt)):
190-
if np.sum(masks_gt[i]) > 0:
191-
sel_idxs.append(i)
192-
pixel_scores = patchcore.metrics.compute_pixelwise_retrieval_metrics(
193-
[segmentations[i] for i in sel_idxs],
194-
[masks_gt[i] for i in sel_idxs],
177+
# 计算Image-level指标
178+
imagewise_metrics = patchcore.metrics.compute_imagewise_retrieval_metrics(scores, anomaly_labels)
179+
instance_auroc = imagewise_metrics['auroc']
180+
image_ap = imagewise_metrics['image_ap'] # 新增
181+
182+
# 计算Pixel-level指标
183+
pixelwise_metrics = patchcore.metrics.compute_pixelwise_retrieval_metrics(segmentations, masks_gt)
184+
full_pixel_auroc = pixelwise_metrics['auroc']
185+
full_pro = pixelwise_metrics['pro_score'] # 新增
186+
pixel_ap = pixelwise_metrics['pixel_ap'] # 新增
187+
188+
# 仅针对异常图像的Pixel指标
189+
sel_idxs = [i for i in range(len(masks_gt)) if np.sum(masks_gt[i]) > 0]
190+
anomaly_pixel_metrics = patchcore.metrics.compute_pixelwise_retrieval_metrics(
191+
[segmentations[i] for i in sel_idxs], [masks_gt[i] for i in sel_idxs]
195192
)
196-
anomaly_pixel_auroc = pixel_scores["auroc"]
197-
193+
anomaly_pixel_auroc = anomaly_pixel_metrics['auroc']
194+
195+
# 更新结果收集字典
198196
result_collect.append(
199197
{
200198
"dataset_name": dataset_name,
201-
"instance_auroc": auroc,
199+
"instance_auroc": instance_auroc,
200+
"image_ap": image_ap, # 新增
202201
"full_pixel_auroc": full_pixel_auroc,
202+
"full_pro": full_pro, # 新增
203203
"anomaly_pixel_auroc": anomaly_pixel_auroc,
204+
"pixel_ap": pixel_ap # 新增
204205
}
205206
)
206207

0 commit comments

Comments
 (0)