Skip to content

Commit 4d2647d

Browse files
committed
modified readme for huggingface space and docker image
1 parent 39c7d36 commit 4d2647d

1 file changed

Lines changed: 129 additions & 47 deletions

File tree

README.md

Lines changed: 129 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,205 @@
11
# 🐭 Lungs segmentation in mice CT scans
22

3-
We provide a neural network model for segmenting the lungs of the mice. The model is based on the [U-Net](https://lmb.informatik.uni-freiburg.de/people/ronneber/u-net/) architecture.
3+
Neural network for segmenting mouse lungs in CT scans, based on the classic [U-Net](https://lmb.informatik.uni-freiburg.de/people/ronneber/u-net/) architecture.
44

55
<p align="center">
6-
<img src="https://raw.githubusercontent.com/qchapp/lungs-segmentation/refs/heads/master/images/main_fig.png" height="500">
6+
<img src="https://raw.githubusercontent.com/qchapp/lungs-segmentation/refs/heads/master/images/main_fig.png" height="500" alt="Model overview">
77
</p>
88

9-
The goal of our tool is to provid a reliable way to segment the lungs in mouse CT scans. The U-net model produces a binary mask representing the segmentation of the lungs.
9+
The goal is to provide a reliable, easy-to-use tool to obtain **binary lung masks** from mouse CT scans.
1010

11-
## Try the model
11+
---
1212

13-
- [Install the package](#installation)
14-
- [Follow the usage instructions](#usage-in-napari)
13+
## Quick links
14+
15+
- [Try in your browser (Hugging Face Space)](#try-in-your-browser-hugging-face-space)
16+
- [Installation](#installation)
17+
- [Use in napari (GUI)](#usage-in-napari)
18+
- [Use as a Python library](#usage-as-a-library)
19+
- [Use from the command line](#usage-as-a-cli)
20+
- [Run with Docker (GHCR)](#run-with-docker-ghcr)
21+
- [Models & weights](#models)
22+
- [Dataset](#dataset)
23+
- [Issues](#issues)
24+
- [License](#license)
25+
- [Acknowledgments](#acknowledgments)
26+
- [Carbon footprint](#carbon-footprint-of-this-project)
27+
28+
---
29+
30+
## Try in your browser (Hugging Face Space)
31+
32+
No local installation needed — test the model directly in your browser:
33+
34+
➡️ **https://huggingface.co/spaces/qchapp/3d-lungs-segmentation**
35+
36+
Upload a mouse CT scan, run the segmentation, visualize and download the resulting lung mask.
37+
38+
---
1539

1640
## Installation
1741

18-
We recommend performing the installation in a clean Python environment.
42+
We recommend using a fresh Python environment.
1943

20-
The code requires `python>=3.9`, as well as `pytorch>=2.0`. Please install Pytorch first and separately following the instructions for your platform on [pytorch.org](https://pytorch.org/get-started/locally/).
44+
- **Requirements:** `python>=3.9`, `pytorch>=2.0`
45+
Please install PyTorch first for your platform following the instructions on [pytorch.org](https://pytorch.org/get-started/locally/).
2146

22-
Install `unet_lungs_segmentation` using *pip* after you've installed Pytorch:
47+
Install the package from PyPI:
2348

24-
```sh
49+
```bash
2550
pip install unet_lungs_segmentation
2651
```
2752

28-
or clone the repository and install with:
53+
Or install from source:
2954

30-
```sh
55+
```bash
3156
git clone https://github.com/qchapp/lungs-segmentation.git
57+
cd lungs-segmentation
3258
pip install -e .
3359
```
3460

35-
## Models
61+
---
3662

37-
The model weights (~1 GB) will be automatically downloaded from [Hugging Face](https://huggingface.co/qchapp/unet-lungs-segmentation-weights).
63+
## Usage in napari
3864

65+
[Napari](https://napari.org/stable/) is a multidimensional image viewer for Python.
3966

40-
## Usage in Napari
67+
1. Launch napari:
4168

42-
[Napari](https://napari.org/stable/) is a multi-dimensional image viewer for python. To use our model in Napari, start the viewer with
43-
44-
```sh
45-
napari
46-
```
69+
```bash
70+
napari
71+
```
4772

48-
To open an image, use `File > Open files` or drag-and-drop an image into the viewer window. If you want to open medical image formats such as NIFTI directly, consider installing the [napari-medical-image-formats](https://pypi.org/project/napari-medical-image-formats/) plugin.
73+
2. Open an image via **File → Open files…** or drag & drop into the viewer.
74+
To open formats like **NIfTI** directly, consider installing the plugin
75+
[`napari-medical-image-formats`](https://pypi.org/project/napari-medical-image-formats/).
4976

50-
**Sample data**: To test the model, you can run it on our provided sample image. In Napari, open the image from `File > Open Sample > Mouse lung CT scan`.
77+
3. **Sample data:** In napari, go to **File Open Sample Mouse lung CT scan** to try the model.
5178

52-
Next, in the menu bar select `Plugins > Lungs segmentation (unet_lungs_segmentation)`. Select an image and run it by pressing the "Segment lungs" button.
79+
4. Run the plugin via **Plugins → Lungs segmentation (unet_lungs_segmentation)**.
80+
Select the image layer and click **Segment lungs**.
5381

5482
<p align="center">
55-
<img src="https://raw.githubusercontent.com/qchapp/lungs-segmentation/refs/heads/master/images/napari-screenshot.png" height="500">
83+
<img src="https://raw.githubusercontent.com/qchapp/lungs-segmentation/refs/heads/master/images/napari-screenshot.png" height="500" alt="napari plugin screenshot">
5684
</p>
5785

86+
---
87+
5888
## Usage as a library
5989

60-
You can run a model in just a few lines of code to produce a segmentation mask from an image (represented as a numpy array).
90+
Run the model in a few lines to obtain a binary mask (NumPy array):
6191

62-
```py
92+
```python
6393
from unet_lungs_segmentation import LungsPredict
6494

6595
lungs_predict = LungsPredict()
66-
mask = lungs_predict.segment_lungs(your_image)
96+
mask = lungs_predict.segment_lungs(your_image) # your_image: NumPy array
6797
```
68-
or if you want to apply a specific `threshold` (`float` between 0 and 1):
69-
```py
70-
mask = lungs_predict.segment_lungs(your_image, threshold)
98+
99+
Specify a custom probability `threshold` (float in `[0, 1]`) if desired:
100+
101+
```python
102+
mask = lungs_predict.segment_lungs(your_image, threshold=0.5)
71103
```
72104

105+
---
106+
73107
## Usage as a CLI
74108

75-
Run inference on an image from the command-line. For example:
109+
Run inference on a single image:
76110

77-
```sh
111+
```bash
78112
uls_predict_image -i /path/to/folder/image_001.tif [-t <threshold>]
79113
```
80114

81-
The `<threshold>` will be applied to the predicted image in order to have a binary mask. A default threshold of 0.5 will be applied if none is given. Should be a `float` between 0 and 1.
115+
- If `-t`/`--threshold` is provided, it binarizes the prediction at that value (default: `0.5` in `[0,1]`).
116+
- The output mask is saved next to the input image:
82117

83-
The command will save the segmentation next to the image:
84118
```
85119
folder/
86-
├── image_001.tif
87-
── image_001_mask.tif
120+
├── image_001.tif
121+
── image_001_mask.tif
88122
```
89123

90-
Run inference in batch on all images in a folder:
124+
Batch-process a folder:
91125

92-
```sh
126+
```bash
93127
uls_predict_folder -i /path/to/folder/ [-t <threshold>]
94128
```
95-
Will produce:
129+
130+
Produces, e.g.:
131+
96132
```
97133
folder/
98-
├── image_001.tif
99-
├── image_001_mask.tif
100-
├── image_002.tif
101-
├── image_002_mask.tif
134+
├── image_001.tif
135+
├── image_001_mask.tif
136+
├── image_002.tif
137+
└── image_002_mask.tif
138+
```
139+
140+
---
141+
142+
## Run with Docker (GHCR)
143+
144+
You can run the tool without a local Python setup using our container on **GitHub Container Registry**.
145+
146+
1. **Pull the image:**
147+
148+
```bash
149+
docker pull ghcr.io/qchapp/unet-lungs-segmentation:latest
150+
```
151+
152+
2. **Run on a single image** (mount a data folder into the container):
153+
154+
```bash
155+
docker run --rm -v /path/to/data:/data ghcr.io/qchapp/unet-lungs-segmentation:latest \
156+
-i /data/image_001.tif -t 0.5
102157
```
103158

159+
3. **Run on a folder:**
160+
161+
```bash
162+
docker run --rm -v /path/to/data:/data ghcr.io/qchapp/unet-lungs-segmentation:latest \
163+
uls_predict_folder -i /data
164+
```
165+
166+
> **Note:** The container’s entrypoint is `uls_predict_image`.
167+
> For folder mode, prefix the command explicitly as shown above.
168+
169+
---
170+
171+
## Models
172+
173+
The model weights (~1 GB) are downloaded automatically on first use from
174+
[Hugging Face](https://huggingface.co/qchapp/unet-lungs-segmentation-weights).
175+
176+
---
177+
104178
## Dataset
105179

106-
Our model was trained using a dataset of `355` images coming from 17 different experiments, 2 different scanners and validated on `62` images.
180+
The model was trained on **355** images from 17 different experiments and 2 scanners, and validated on **62** images.
181+
182+
---
107183

108184
## Issues
109185

110-
If you encounter any problems, please fill an issue along with a detailed description.
186+
If you encounter problems, please open an issue with a clear description and, if possible, a minimal reproducible example.
187+
188+
---
111189

112190
## Acknowledgments
113191

114192
This project was developed as part of a **Bachelor’s project** at the *EPFL Center for Imaging*.
115193
It was carried out under the supervision of **Mallory Wittwer** and **Edward Andò**, whom we sincerely thank for their guidance and support.
116194

195+
---
196+
117197
## License
118198

119-
This model is licensed under the [BSD-3](LICENSE.txt) license.
199+
This model is released under the [BSD-3](LICENSE.txt) license.
200+
201+
---
120202

121203
## Carbon footprint of this project
122204

123-
As per the online tool [*Green algorithms*](http://calculator.green-algorithms.org/), the footprint of training this model was estimated to be around 584 g CO2e.
205+
As estimated by [Green Algorithms](http://calculator.green-algorithms.org/), training this model emitted approximately **584 g CO₂e**.

0 commit comments

Comments
 (0)