File size: 3,802 Bytes
5fdedf9
 
 
 
 
 
 
bce169b
5fdedf9
1d197a4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5fdedf9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
---
language:
- en
metrics:
- accuracy
- recall
- f1
pipeline_tag: image-segmentation
---
# IVUS-Segmentation

DeepIVUS pipeline for lumen segmentation and bifurcation frame classification on IVUS DICOMs.

## What This Repo Contains

- Runtime package: `deepivus/`
  - CLI entrypoints and pipeline orchestration
  - Lumen segmentation inference
  - Bifurcation classifier inference
  - Video/JSON/XML export utilities
- Data and annotations:
  - `data/`: source DICOM folders (`data/bifurcation`, `data/paul`)
  - `evals/frame_bank_merged/`: canonical annotation bank
  - `evals/splits/ivus_split_merged_600.json`: canonical train/val/test split
- Models:
  - `models/standalone/lumen/`: standalone lumen TF SavedModel
  - `models/standalone/bifurcation/best_bifurcation_classifier.keras`: standalone bifurcation classifier
  - `models/standalone/bifurcation/threshold.json`: selected inference threshold (from validation sweep)
- Training and evaluation scripts:
  - `scripts/finetune/bifurcation/`
  - `scripts/finetune/lumen/`
  - shared helpers: `scripts/finetune/shared/common.py`
  - data tooling: `scripts/data/frame_bank.py`

## Main Runtime Workflow

### 1) Segment a DICOM and classify branching

```bash
python DeepIVUS.py segment data/paul/FILE00005.dcm
```

Outputs are written under `output/<timestamp>/` and include:

- contours XML and JSONL
- top-confidence JSONL
- lumen overlay video
- bifurcation predictions JSONL + summary JSON
- overlay video with branch/non-branch flag

Notes:

- `--bifurcation-threshold` is optional.
- If omitted, threshold is loaded from `threshold.json` beside the selected bifurcation model.

### 2) Edit contour annotations in GUI

```bash
python DeepIVUS.py edit-annotations data/paul/FILE00005.dcm
```

## Bifurcation Model Workflow

### 1) Sample new frames for manual labeling

```bash
python -u scripts/finetune/bifurcation/sample_new_bifurcation_frames.py
```

### 2) Label sampled frames in GUI

```bash
python -u scripts/finetune/bifurcation/annotate_bifurcation_samples.py
```

### 3) Merge labels into canonical frame bank

```bash
python -u scripts/finetune/bifurcation/merge_bifurcation_annotations.py
```

### 4) Create/update canonical split

```bash
python -u scripts/finetune/bifurcation/create_bifurcation_splits.py
```

### 5) Train bifurcation classifier

```bash
python -u scripts/finetune/bifurcation/train_bifurcation_classifier.py
```

### 6) Evaluate on test and select threshold from validation

```bash
python -u scripts/finetune/bifurcation/run_bifurcation_test_inference.py
```

This writes test metrics and persists selected threshold to:

- `threshold.json` beside the evaluated classifier model file.

## Lumen Model Workflow

### 1) Identify lumen class index in SavedModel logits

```bash
python -u scripts/finetune/lumen/identify_lumen_class.py
```

### 2) Fine-tune lumen model

```bash
python -u scripts/finetune/lumen/finetune_lumen_from_saved_model.py \
  --output-model-dir models/standalone/lumen
```

### 3) Evaluate lumen model on test split

```bash
python -u scripts/finetune/lumen/run_test_inference.py \
  --model-dir models/standalone/lumen
```

### 4) Run single-DICOM lumen + bifurcation overlay inference

```bash
python -u scripts/finetune/lumen/run_single_dicom_inference.py \
  --dicom-path data/paul/FILE00005.dcm
```

## Repository Structure

- `DeepIVUS.py`: top-level CLI launcher
- `deepivus/`: runtime package
- `models/`: runtime models and threshold
- `evals/`: canonical annotation bank and split
- `scripts/`: training/eval/data utilities
- `output/`: generated artifacts (runs, metrics, videos)

## Environment

- Python project config: `pyproject.toml`
- Conda env file: `environment.yml`

Install dependencies with your preferred toolchain (`poetry`, `pip`, or `conda`) using those files.