Skip to content

Commit 5373c43

Browse files
committed
core\refac: #68 mv and staple experiments
- included mv and staple experiments for oxford pet - enhanced model building in experiments
1 parent 0eda316 commit 5373c43

File tree

26 files changed

+2319
-316
lines changed

26 files changed

+2319
-316
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ notebooks/**/.ipynb_checkpoints
1010
core/dist
1111
__data__
1212
**/results/**
13+
tuner_results/

.vscode/launch.json

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,73 @@
1919
"name": "Poetry: Oxford pet scalar experiment",
2020
"type": "debugpy",
2121
"request": "launch",
22-
"module": "seg_tgce.experiments.scalar",
22+
"module": "seg_tgce.experiments.pets.scalar",
23+
"console": "integratedTerminal",
24+
"justMyCode": true,
25+
"env": {
26+
"PYTHONPATH": "${workspaceFolder}"
27+
}
28+
},
29+
{
30+
"name": "Poetry: Oxford pet features experiment",
31+
"type": "debugpy",
32+
"request": "launch",
33+
"module": "seg_tgce.experiments.pets.features",
34+
"console": "integratedTerminal",
35+
"justMyCode": true,
36+
"env": {
37+
"PYTHONPATH": "${workspaceFolder}"
38+
}
39+
},
40+
{
41+
"name": "Poetry: Oxford pet pixel experiment",
42+
"type": "debugpy",
43+
"request": "launch",
44+
"module": "seg_tgce.experiments.pets.pixel",
45+
"console": "integratedTerminal",
46+
"justMyCode": true,
47+
"env": {
48+
"PYTHONPATH": "${workspaceFolder}"
49+
}
50+
},
51+
{
52+
"name": "Poetry: Histology scalar experiment",
53+
"type": "debugpy",
54+
"request": "launch",
55+
"module": "seg_tgce.experiments.histology.scalar",
56+
"console": "integratedTerminal",
57+
"justMyCode": true,
58+
"env": {
59+
"PYTHONPATH": "${workspaceFolder}"
60+
}
61+
},
62+
{
63+
"name": "Poetry: Histology features experiment",
64+
"type": "debugpy",
65+
"request": "launch",
66+
"module": "seg_tgce.experiments.histology.features",
67+
"console": "integratedTerminal",
68+
"justMyCode": true,
69+
"env": {
70+
"PYTHONPATH": "${workspaceFolder}"
71+
}
72+
},
73+
{
74+
"name": "Poetry: Histology pixel experiment",
75+
"type": "debugpy",
76+
"request": "launch",
77+
"module": "seg_tgce.experiments.histology.pixel",
78+
"console": "integratedTerminal",
79+
"justMyCode": true,
80+
"env": {
81+
"PYTHONPATH": "${workspaceFolder}"
82+
}
83+
},
84+
{
85+
"name": "Poetry: Crowd seg",
86+
"type": "debugpy",
87+
"request": "launch",
88+
"module": "seg_tgce.data.crowd_seg.__main__",
2389
"console": "integratedTerminal",
2490
"justMyCode": true,
2591
"env": {
@@ -36,6 +102,28 @@
36102
"env": {
37103
"PYTHONPATH": "${workspaceFolder}"
38104
}
105+
},
106+
{
107+
"name": "Poetry: Majority voting",
108+
"type": "debugpy",
109+
"request": "launch",
110+
"module": "seg_tgce.experiments.pets.mv",
111+
"console": "integratedTerminal",
112+
"justMyCode": true,
113+
"env": {
114+
"PYTHONPATH": "${workspaceFolder}"
115+
}
116+
},
117+
{
118+
"name": "Poetry: Staple",
119+
"type": "debugpy",
120+
"request": "launch",
121+
"module": "seg_tgce.experiments.pets.staple",
122+
"console": "integratedTerminal",
123+
"justMyCode": true,
124+
"env": {
125+
"PYTHONPATH": "${workspaceFolder}"
126+
}
39127
}
40128
]
41129
}

core/poetry.lock

Lines changed: 83 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/pyproject.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22
description = "Framework for handling image segmentation in the context of multiple annotators"
33
name = "seg_tgce"
4-
version = "0.2.0.dev3"
4+
version = "0.2.1.dev3"
55
readme = "README.md"
66
authors = [{ name = "Brandon Lotero", email = "blotero@gmail.com" }]
77
maintainers = [{ name = "Brandon Lotero", email = "blotero@gmail.com" }]
@@ -15,7 +15,7 @@ Issues = "https://github.com/blotero/seg_tgce/issues"
1515

1616
[tool.poetry]
1717
name = "seg_tgce"
18-
version = "0.2.0.dev3"
18+
version = "0.2.1.dev3"
1919
authors = ["Brandon Lotero <blotero@gmail.com>"]
2020
description = "A package for the SEG TGCE project"
2121
readme = "README.md"
@@ -29,7 +29,7 @@ repository = "https://github.com/blotero/seg_tgce"
2929

3030
[tool.poetry.dependencies]
3131
python = ">=3.10,<3.12"
32-
numpy = "^1.26.4"
32+
numpy = "2.0.2"
3333
keras = "3.8.0"
3434
tensorflow = "2.18.0"
3535
matplotlib = "^3.8.4"
@@ -39,6 +39,7 @@ boto3 = "^1.34.130"
3939
pydot = "^3.0.4"
4040
keras-hub = "^0.20.0"
4141
keras-tuner = { extras = ["bayesian"], version = "^1.4.7" }
42+
simpleitk = "^2.5.0"
4243

4344

4445
[tool.poetry.group.test.dependencies]

core/seg_tgce/data/crowd_seg/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Tuple
22

3-
from .generator import DataSchema, ImageDataGenerator
3+
from .generator import CrowdSegDataGenerator, DataSchema
44
from .stage import Stage
55

66
DEFAULT_TARGET_SIZE = (512, 512)
@@ -12,13 +12,13 @@ def get_all_data(
1212
shuffle: bool = False,
1313
with_sparse_data: bool = False,
1414
trim_n_scorers: int | None = None,
15-
) -> Tuple[ImageDataGenerator, ...]:
15+
) -> Tuple[CrowdSegDataGenerator, ...]:
1616
"""
1717
Retrieve all data generators for the crowd segmentation task.
1818
returns a tuple of ImageDataGenerator instances for the train, val, and test stages.
1919
"""
2020
return tuple(
21-
ImageDataGenerator(
21+
CrowdSegDataGenerator(
2222
batch_size=batch_size,
2323
image_size=image_size,
2424
shuffle=shuffle,
@@ -36,11 +36,11 @@ def get_stage_data(
3636
batch_size: int = 32,
3737
shuffle: bool = False,
3838
with_sparse_data: bool = False,
39-
) -> ImageDataGenerator:
39+
) -> CrowdSegDataGenerator:
4040
"""
4141
Retrieve a data generator for a specific stage of the crowd segmentation task.
4242
"""
43-
return ImageDataGenerator(
43+
return CrowdSegDataGenerator(
4444
batch_size=batch_size,
4545
image_size=image_size,
4646
shuffle=shuffle,
Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,35 @@
1+
from matplotlib import pyplot as plt
2+
13
from seg_tgce.data.crowd_seg import get_all_data
2-
from seg_tgce.data.crowd_seg.generator import ImageDataGenerator
4+
from seg_tgce.data.crowd_seg.generator import CrowdSegDataGenerator
35

46

57
def main() -> None:
68
print("Loading data...")
79
train, val, test = get_all_data(batch_size=16)
8-
fig = val.visualize_sample(
9-
batch_index=75, sample_indexes=[2, 5, 8, 15], scorers=["NP8", "expert"]
10-
)
10+
11+
# Get a sample batch from each generator
12+
train_batch = next(iter(train))
13+
val_batch = next(iter(val))
14+
test_batch = next(iter(test))
15+
16+
# Print shapes
17+
print("\nTrain data shapes:")
18+
print(f"Images shape: {train_batch[0].shape}")
19+
print(f"Ground truth mask shape: {train_batch[1].shape}")
20+
print(f"Labeler masks shape: {train_batch[2].shape}")
21+
22+
print("\nValidation data shapes:")
23+
print(f"Images shape: {val_batch[0].shape}")
24+
print(f"Ground truth mask shape: {val_batch[1].shape}")
25+
print(f"Labeler masks shape: {val_batch[2].shape}")
26+
27+
print("\nTest data shapes:")
28+
print(f"Images shape: {test_batch[0].shape}")
29+
print(f"Ground truth mask shape: {test_batch[1].shape}")
30+
print(f"Labeler masks shape: {test_batch[2].shape}")
31+
32+
fig = val.visualize_sample(batch_index=75, sample_indexes=[0, 1, 4, 5])
1133
fig.tight_layout()
1234
fig.savefig(
1335
"/home/brandon/unal/maestria/master_thesis/Cap1/Figures/multiannotator-segmentation.png"
@@ -17,11 +39,12 @@ def main() -> None:
1739
print(f"Test: {len(test)} batches, {len(test) * test.batch_size} samples")
1840

1941
print("Loading train data with trimmed scorers...")
20-
train = ImageDataGenerator(
42+
train = CrowdSegDataGenerator(
2143
batch_size=8,
2244
trim_n_scorers=6,
2345
)
2446
print(f"Train: {len(train)} batches, {len(train) * train.batch_size} samples")
47+
print(f"Train scorers tags: {train.scorers_tags}")
2548

2649

2750
main()

0 commit comments

Comments
 (0)