Skip to content

Commit 9c1f058

Browse files
committed
Refactor code and add new functionalities
1 parent 230ecc6 commit 9c1f058

File tree

113 files changed

+4562
-1345
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+4562
-1345
lines changed

.github/workflows/pre-commit.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ jobs:
1313
python-version: ["3.9"]
1414
steps:
1515
- name: Checkout repository
16-
uses: actions/checkout@v3
16+
uses: actions/checkout@v4
1717
- name: Set up Python ${{ matrix.python-version }}
18-
uses: actions/setup-python@v4
18+
uses: actions/setup-python@v5
1919
with:
2020
python-version: ${{ matrix.python-version }}
2121
check-latest: true

.github/workflows/unit-test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ jobs:
1616

1717
steps:
1818
- name: Checkout repository
19-
uses: actions/checkout@v3
19+
uses: actions/checkout@v4
2020
- name: Set up Python ${{ matrix.python-version }}
21-
uses: actions/setup-python@v4
21+
uses: actions/setup-python@v5
2222
with:
2323
check-latest: true
2424
python-version: ${{ matrix.python-version }}
@@ -28,9 +28,9 @@ jobs:
2828
docker/environment_mac_m1.yml
2929
docker/Dockerfile
3030
docker/requirements.txt
31+
pyproject.toml
3132
- name: Install dependencies
3233
run: |
33-
python -m pip install --upgrade pip
3434
pip install tensorflow-cpu==2.12.0
3535
pip install jax==0.4.20
3636
pip install jaxlib==0.4.20

.pre-commit-config.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ repos:
2424
files: "docker/requirements.txt"
2525
- id: trailing-whitespace
2626
- repo: https://github.com/PyCQA/isort
27-
rev: 5.12.0
27+
rev: 5.13.2
2828
hooks:
2929
- id: isort
3030
- repo: https://github.com/psf/black
31-
rev: 23.11.0
31+
rev: 23.12.1
3232
hooks:
3333
- id: black
3434
args:
3535
- --line-length=100
3636
- repo: https://github.com/pre-commit/mirrors-mypy
37-
rev: v1.7.1
37+
rev: v1.8.0
3838
hooks: # https://github.com/python/mypy/issues/4008#issuecomment-582458665
3939
- id: mypy
4040
name: mypy
@@ -54,15 +54,15 @@ repos:
5454
--warn-unreachable,
5555
]
5656
- repo: https://github.com/pre-commit/mirrors-prettier
57-
rev: v3.1.0
57+
rev: v4.0.0-alpha.8
5858
hooks:
5959
- id: prettier
6060
args:
6161
- --print-width=100
6262
- --prose-wrap=always
6363
- --tab-width=2
6464
- repo: https://github.com/charliermarsh/ruff-pre-commit
65-
rev: "v0.1.6"
65+
rev: "v0.1.9"
6666
hooks:
6767
- id: ruff
6868
- repo: https://github.com/pre-commit/mirrors-pylint

Makefile

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ pip:
33

44
test:
55
pytest --cov=imgx -n 4 imgx
6-
pytest --cov=imgx_datasets -n 4 imgx_datasets
76

87
build_dataset:
9-
tfds build imgx_datasets/male_pelvic_mr
10-
tfds build imgx_datasets/amos_ct
11-
tfds build imgx_datasets/muscle_us
12-
tfds build imgx_datasets/brats2021_mr
8+
tfds build imgx/datasets/male_pelvic_mr
9+
tfds build imgx/datasets/amos_ct
10+
tfds build imgx/datasets/muscle_us
11+
tfds build imgx/datasets/brats2021_mr

README.md

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,8 @@ This repository includes the implementation of the following work
88
- [Importance of Aligning Training Strategy with Evaluation for Diffusion Models in 3D Multiclass Segmentation](https://arxiv.org/abs/2303.06040)
99

1010
:construction: **The codebase is still under active development for more enhancements and
11-
applications.** :construction:
12-
13-
- November 2023:
14-
- :warning: Upgraded to JAX to 0.4.20.
15-
- :warning: Removed Haiku-specific modification to convolutional layers. This may impact model
16-
performance.
17-
- :smiley: Added example notebooks for inference on a single image without TFDS.
18-
- Added integration tests for training, validation, and testing.
19-
- Refactored config.
20-
- Added `patch_size` and `scale_factor` to data config.
21-
- Moved loss config from the main config to task config.
22-
- Refactored code, including defining `imgx/task` submodule.
23-
- October 2023:
24-
- :blush: Migrated from [Haiku](https://github.com/google-deepmind/dm-haiku) to
25-
[Flax](https://github.com/google/flax) following Google DeepMind's recommendation.
11+
applications. Please check [release notes](https://github.com/mathpluscode/ImgX-DiffSeg/releases)
12+
for more information. ** :construction:
2613

2714
:mailbox: Please feel free to
2815
[create an issue](https://github.com/mathpluscode/ImgX-DiffSeg/issues/new/choose) to request
@@ -38,7 +25,7 @@ Current supported functionalities are summarized as follows.
3825

3926
**Data sets**
4027

41-
See the [readme](imgx_datasets/README.md) for further details.
28+
See the [readme](imgx/datasets/README.md) for further details.
4229

4330
- Muscle ultrasound from [Marzola et al. 2021](https://data.mendeley.com/datasets/3jykz7wz8d/1).
4431
- Male pelvic MR from [Li et al. 2022](https://zenodo.org/record/7013610#.Y1U95-zMKrM).
@@ -68,6 +55,10 @@ See the [readme](imgx_datasets/README.md) for further details.
6855
**Training**
6956

7057
- Patch-based training.
58+
- Data augmentation with anisotropic support, including
59+
- Random affine: rotation, scaling, shearing, shifting.
60+
- Random gamma adjustment.
61+
- Random flip.
7162
- Multi-device training (one model per device) with
7263
[`pmap`](https://jax.readthedocs.io/en/latest/_autosummary/jax.pmap.html).
7364
- Mixed precision training.
@@ -284,7 +275,6 @@ Run the command below to test and get a coverage report. As JAX tests require tw
284275

285276
```bash
286277
pytest --cov=imgx -n 4 imgx -k "not integration"
287-
pytest --cov=imgx_datasets -n 4 imgx_datasets
288278
```
289279

290280
`-k "not integration"` excludes integration tests, which require downloading muscle ultrasound and

docker/requirements.txt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
SimpleITK==2.3.1
22
chex==0.1.8
3-
coverage==7.3.2
3+
coverage==7.3.3
44
flax==0.7.5
55
hydra-core==1.3.2
66
kaggle==1.5.16
7+
matplotlib==3.8.2
78
nbmake==1.4.6
89
numpy==1.26.2
910
opencv-python==4.8.1.78
1011
optax==0.1.7
11-
pandas==2.1.3
12-
pre-commit==3.5.0
12+
pandas==2.1.4
13+
pre-commit==3.6.0
1314
protobuf==3.20.3 # https://github.com/tensorflow/datasets/issues/4858
1415
pytest-cov==4.1.0
1516
pytest-mock==3.12.0
@@ -19,8 +20,9 @@ pytest-xdist==3.5.0
1920
pytest==7.4.3
2021
rdkit-pypi==2022.9.5
2122
rich==13.7.0
22-
ruff==0.1.6
23+
ruff==0.1.8
2324
tensorflow-datasets==4.9.3
24-
torch==2.1.1 # for testing only
25-
wandb==0.16.0
25+
tomli==2.0.1
26+
torch==2.1.2 # for testing only
27+
wandb==0.16.1
2628
wily==1.25.0

examples/segmentation/config.yaml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ data:
99
- 0
1010
- 0
1111
data_augmentation:
12-
max_rotation:
13-
- 0.088
14-
max_translation:
15-
- 10
16-
- 10
17-
max_scaling:
18-
- 0.15
19-
- 0.15
12+
max_rotation: 30
13+
max_zoom: 0.2
14+
max_shear: 30
15+
max_shift: 0.3
16+
max_log_gamma: 0.3
17+
v_min: 0.0
18+
v_max: 1.0
19+
p: 0.5
2020
trainer:
2121
max_num_samples: 512000
2222
batch_size: 64
@@ -40,6 +40,7 @@ task:
4040
scale_factor:
4141
- 2
4242
- 2
43+
num_res_blocks: 2
4344
num_channels:
4445
- 8
4546
- 16
@@ -49,10 +50,11 @@ task:
4950
num_heads: 8
5051
widening_factor: 4
5152
num_transform_layers: 1
53+
dropout: 0.1
5254
loss:
5355
dice: 1.0
5456
cross_entropy: 0.0
55-
focal: 20.0
57+
focal: 1.0
5658
early_stopping:
5759
metric: mean_binary_dice_score_without_background
5860
mode: max
-11.2 MB
Binary file not shown.
8.36 MB
Binary file not shown.

examples/segmentation/inference.ipynb

Lines changed: 13 additions & 11 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)