Skip to content

Commit c5a3d9c

Browse files
Update validation scripts
1 parent c1530f2 commit c5a3d9c

File tree

3 files changed

+87
-1
lines changed

3 files changed

+87
-1
lines changed

scripts/validation/analyze.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import pandas as pd
2+
3+
# TODO more logic to separate by annotator etc.
4+
# For now this is just a simple script for global eval
5+
table = pd.read_csv("./results.csv")
6+
print(table)
7+
8+
tp = table.tps.sum()
9+
fp = table.fps.sum()
10+
fn = table.fns.sum()
11+
12+
# precision =
13+
# recall =
14+
# f1_score =
15+
#
16+
# print("Precision:", precision)
17+
# print("Recall:", recall)
18+
# print("F1-Score:", f1_score)
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import os
2+
from glob import glob
3+
4+
import pandas as pd
5+
from flamingo_tools.validation import (
6+
fetch_data_for_evaluation, parse_annotation_path, compute_scores_for_annotated_slice
7+
)
8+
9+
ROOT = "/mnt/vast-nhr/projects/nim00007/data/moser/cochlea-lightsheet/AnnotatedImageCrops/F1Validation"
10+
ANNOTATION_FOLDERS = ["AnnotationsEK", "AnnotationsAMD"]
11+
12+
13+
def run_evaluation(root, annotation_folders, result_file, cache_folder):
14+
# TODO load existing result file and initialize
15+
results = {
16+
"annotator": [],
17+
"cochlea": [],
18+
"slice": [],
19+
"tps": [],
20+
"fps": [],
21+
"fns": [],
22+
}
23+
24+
if cache_folder is not None:
25+
os.makedirs(cache_folder, exist_ok=True)
26+
27+
for folder in annotation_folders:
28+
annotator = folder[len("Annotations"):]
29+
annotations = sorted(glob(os.path.join(root, folder, "*.csv")))
30+
for annotation_path in annotations:
31+
cochlea, slice_id = parse_annotation_path(annotation_path)
32+
# We don't have this cochlea in MoBIE yet
33+
if cochlea == "M_LR_000169_R":
34+
continue
35+
36+
# TODO skip if this is already in the results
37+
print("Run evaluation for", annotator, cochlea, slice_id)
38+
segmentation, annotations = fetch_data_for_evaluation(
39+
annotation_path, components_for_postprocessing=[1],
40+
cache_path=None if cache_folder is None else os.path.join(cache_folder, f"{cochlea}_{slice_id}.tif")
41+
)
42+
scores = compute_scores_for_annotated_slice(segmentation, annotations)
43+
results["annotator"].append(annotator)
44+
results["cochlea"].append(cochlea)
45+
results["slice"].append(slice_id)
46+
results["tps"].append(scores["tp"])
47+
results["fps"].append(scores["fp"])
48+
results["fns"].append(scores["fn"])
49+
table = pd.DataFrame(results)
50+
table.to_csv(result_file, index=False)
51+
print(table)
52+
53+
54+
def main():
55+
import argparse
56+
parser = argparse.ArgumentParser()
57+
parser.add_argument("-i", "--input", default=ROOT)
58+
parser.add_argument("--folders", default=ANNOTATION_FOLDERS)
59+
parser.add_argument("--result_file", default="results.csv")
60+
parser.add_argument("--cache_folder")
61+
args = parser.parse_args()
62+
run_evaluation(args.input, args.folders, args.result_file, args.cache_folder)
63+
64+
65+
if __name__ == "__main__":
66+
main()

scripts/validation/visualize_validation.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212

1313
def main():
1414
image = imageio.imread(os.path.join(ROOT, "MAMD58L_PV_z771_base_full.tif"))
15-
segmentation, annotations = fetch_data_for_evaluation(TEST_ANNOTATION, cache_path="./seg.tif")
15+
segmentation, annotations = fetch_data_for_evaluation(
16+
TEST_ANNOTATION, cache_path="./seg.tif", components_for_postprocessing=[1],
17+
)
1618

1719
# v = napari.Viewer()
1820
# v.add_image(image)

0 commit comments

Comments
 (0)