Skip to content

Commit 7a2d4e8

Browse files
committed
Docs. (#223)
1 parent 29c9050 commit 7a2d4e8

2 files changed

Lines changed: 34 additions & 73 deletions

File tree

README.md

Lines changed: 33 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -19,60 +19,6 @@ ideas. MIP Candy takes care of all the rest, so you can focus on only the key ex
1919

2020
:link: [Docs](https://mipcandy-docs.projectneura.org)
2121

22-
## Key Features
23-
24-
Why MIP Candy? :thinking:
25-
26-
<details>
27-
<summary>Easy adaptation to fit your needs</summary>
28-
We provide tons of easy-to-use techniques for training that seamlessly support your customized experiments.
29-
30-
- Sliding window
31-
- ROI inspection
32-
- ROI cropping to align dataset shape (100% or 33% foreground)
33-
- Automatic padding
34-
- ...
35-
36-
You only need to override one method to create a trainer for your network architecture.
37-
38-
```python
39-
from typing import override
40-
41-
from torch import nn
42-
from mipcandy import SegmentationTrainer
43-
44-
45-
class MyTrainer(SegmentationTrainer):
46-
@override
47-
def build_network(self, example_shape: tuple[int, ...]) -> nn.Module:
48-
...
49-
```
50-
</details>
51-
52-
<details>
53-
<summary>Satisfying command-line UI design</summary>
54-
<img src="home/assets/console-outputs.png" alt="cmd-ui"/>
55-
</details>
56-
57-
<details>
58-
<summary>Built-in 2D and 3D visualization for intuitive understanding</summary>
59-
<img src="home/assets/visualization.png" alt="visualization"/>
60-
</details>
61-
62-
<details>
63-
<summary>High availability with interruption tolerance</summary>
64-
Interrupted experiments can be resumed with ease.
65-
<img src="home/assets/recovery.png" alt="recovery"/>
66-
</details>
67-
68-
<details>
69-
<summary>Support of various frontend platforms for remote monitoring</summary>
70-
71-
MIP Candy Supports [Notion](https://mipcandy-projectneura.notion.site), WandB, and TensorBoard.
72-
73-
<img src="home/assets/notion.png" alt="notion"/>
74-
</details>
75-
7622
## Citation
7723

7824
Should you find our work helpful to you, please cite our publication.
@@ -99,30 +45,46 @@ pip install "mipcandy[standard]"
9945

10046
## Quick Start
10147

102-
Below is a simple example of a nnU-Net style training. The batch size is set to 1 due to the varying shape of the
103-
dataset, although you can use a `ROIDataset` to align the shapes.
48+
Below is an example using the ACDC dataset. The example code replicates most of nnU-Net's features but without
49+
augmentations.
10450

10551
```python
10652
from typing import override
53+
from os.path import exists
10754

108-
import torch
109-
from mipcandy_bundles.unet import UNetTrainer
55+
from monai.networks.nets import DynUNet
56+
from torch import nn
11057
from torch.utils.data import DataLoader
11158

112-
from mipcandy import download_dataset, NNUNetDataset
59+
from mipcandy import SegmentationTrainer, AmbiguousShape, auto_device, download_dataset, NNUNetDataset, inspect, \
60+
load_inspection_annotations, RandomROIDataset
11361

11462

115-
class PH2(NNUNetDataset):
63+
class UNetTrainer(SegmentationTrainer):
11664
@override
117-
def load(self, idx: int) -> tuple[torch.Tensor, torch.Tensor]:
118-
image, label = super().load(idx)
119-
return image.squeeze(0).permute(2, 0, 1), label
120-
121-
122-
download_dataset("nnunet_datasets/PH2", "tutorial/datasets/PH2")
123-
dataset, val_dataset = PH2("tutorial/datasets/PH2", device="cuda").fold()
124-
dataloader = DataLoader(dataset, 1, shuffle=True)
125-
val_dataloader = DataLoader(val_dataset, 1, shuffle=False)
126-
trainer = UNetTrainer("tutorial", dataloader, val_dataloader, device="cuda")
127-
trainer.train(1000, note="a nnU-Net style example")
65+
def build_network(self, example_shape: AmbiguousShape) -> nn.Module:
66+
kernel_size = [[3, 3, 3]] * 5
67+
strides = [[1, 1, 1]] + [[2, 2, 2]] * 4
68+
return DynUNet(spatial_dims=3, in_channels=example_shape[0], out_channels=self.num_classes,
69+
kernel_size=kernel_size, strides=strides, upsample_kernel_size=strides,
70+
deep_supervision=self.deep_supervision, deep_supr_num=2, res_block=True)
71+
72+
73+
if __name__ == "__main__":
74+
device = auto_device()
75+
download_dataset("nnunet_datasets/ACDC", "tutorial/datasets/ACDC")
76+
dataset = NNUNetDataset("tutorial/datasets/ACDC", align_spacing=True)
77+
if exists("tutorial/datasets/ACDC/annotations.json"):
78+
annotations = load_inspection_annotations("tutorial/datasets/ACDC/annotations.json", dataset)
79+
else:
80+
dataset.device(device=device)
81+
annotations = inspect(dataset)
82+
dataset.device(device="cpu")
83+
annotations.save("tutorial/datasets/ACDC/annotations.json")
84+
dataset = RandomROIDataset(annotations, 2)
85+
train, val = dataset.fold()
86+
train_loader = DataLoader(train, 2, True, num_workers=2, prefetch_factor=2, persistent_workers=True)
87+
val_loader = DataLoader(val, 1, False)
88+
trainer = UNetTrainer("tutorial", train_loader, val_loader, device=device)
89+
trainer.train(1000, note="example with the ACDC dataset")
12890
```

home/index.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,8 +891,7 @@ <h2 class="section-title">Live Notion dashboard</h2>
891891
<h2 class="text-block-title">Train like a <b class="gradient-text">Pro</b> in a few lines</h2>
892892
<p class="text-block-body">
893893
Download a dataset, create a dataset wrapper, and hand it to a trainer. Below is an example using
894-
the ACDC dataset. The example code to the right replicates most of nnU-Net's features but without
895-
augmentations.
894+
the ACDC dataset. The example code replicates most of nnU-Net's features but without augmentations.
896895
</p>
897896
</div>
898897
<div class="code-card">

0 commit comments

Comments
 (0)