Cell Detection with PyTorch.
Project description
Cell Detection
⭐ Showcase
NeurIPS 22 Cell Segmentation Competition
https://openreview.net/forum?id=YtgRjBw-7GJ
Nuclei of U2OS cells in a chemical screen
https://bbbc.broadinstitute.org/BBBC039 (CC0)
P. vivax (malaria) infected human blood
https://bbbc.broadinstitute.org/BBBC041 (CC BY-NC-SA 3.0)
🛠 Install
Make sure you have PyTorch installed.
PyPI
pip install -U celldetection
GitHub
pip install git+https://github.com/FZJ-INM1-BDA/celldetection.git
💾 Trained models
model = cd.fetch_model(model_name, check_hash=True)
| model name | training data |
|---|---|
ginoro_CpnResNeXt101UNet-fbe875f1a3e5ce2c |
BBBC039, BBBC038, Omnipose, Cellpose, Sartorius - Cell Instance Segmentation, Livecell, NeurIPS 22 CellSeg Challenge |
Run a demo with a pretrained model
import torch, cv2, celldetection as cd
from skimage.data import coins
from matplotlib import pyplot as plt
# Load pretrained model
device = 'cuda' if torch.cuda.is_available() else 'cpu'
model = cd.fetch_model('ginoro_CpnResNeXt101UNet-fbe875f1a3e5ce2c', check_hash=True).to(device)
model.eval()
# Load input
img = coins()
img = cv2.cvtColor(img, cv2.COLOR_GRAY2RGB)
print(img.dtype, img.shape, (img.min(), img.max()))
# Run model
with torch.no_grad():
x = cd.to_tensor(img, transpose=True, device=device, dtype=torch.float32)
x = x / 255 # ensure 0..1 range
x = x[None] # add batch dimension: Tensor[3, h, w] -> Tensor[1, 3, h, w]
y = model(x)
# Show results for each batch item
contours = y['contours']
for n in range(len(x)):
cd.imshow_row(x[n], x[n], figsize=(16, 9), titles=('input', 'contours'))
cd.plot_contours(contours[n])
plt.show()
🔬 Architectures
import celldetection as cd
Contour Proposal Networks
cd.models.CPNcd.models.CpnU22cd.models.CPNCorecd.models.CpnResUNetcd.models.CpnSlimU22cd.models.CpnWideU22cd.models.CpnResNet18FPNcd.models.CpnResNet34FPNcd.models.CpnResNet50FPNcd.models.CpnResNeXt50FPNcd.models.CpnResNet101FPNcd.models.CpnResNet152FPNcd.models.CpnResNet18UNetcd.models.CpnResNet34UNetcd.models.CpnResNet50UNetcd.models.CpnResNeXt101FPNcd.models.CpnResNeXt152FPNcd.models.CpnResNeXt50UNetcd.models.CpnResNet101UNetcd.models.CpnResNet152UNetcd.models.CpnResNeXt101UNetcd.models.CpnResNeXt152UNetcd.models.CpnWideResNet50FPNcd.models.CpnWideResNet101FPNcd.models.CpnMobileNetV3LargeFPNcd.models.CpnMobileNetV3SmallFPN
PyTorch Image Models (timm)
Also have a look at Timm Documentation.
import timm
timm.list_models(filter='*') # explore available models
Segmentation Models PyTorch (smp)
import segmentation_models_pytorch as smp
smp.encoders.get_encoder_names() # explore available models
encoder = cd.models.SmpEncoder(encoder_name='mit_b5', pretrained='imagenet')
Find a list of Smp Encoders in the smp documentation.
U-Nets
# U-Nets are available in 2D and 3D
import celldetection as cd
model = cd.models.ResNeXt50UNet(in_channels=3, out_channels=1, nd=3)
cd.models.U22cd.models.U17cd.models.U12cd.models.UNetcd.models.WideU22cd.models.SlimU22cd.models.ResUNetcd.models.UNetEncodercd.models.ResNet50UNetcd.models.ResNet18UNetcd.models.ResNet34UNetcd.models.ResNet152UNetcd.models.ResNet101UNetcd.models.ResNeXt50UNetcd.models.ResNeXt152UNetcd.models.ResNeXt101UNetcd.models.WideResNet50UNetcd.models.WideResNet101UNetcd.models.MobileNetV3SmallUNetcd.models.MobileNetV3LargeUNet
MA-Nets
# Many MA-Nets are available in 2D and 3D
import celldetection as cd
encoder = cd.models.ConvNeXtSmall(in_channels=3, nd=3)
model = cd.models.MaNet(encoder, out_channels=1, nd=3)
Feature Pyramid Networks
cd.models.FPNcd.models.ResNet18FPNcd.models.ResNet34FPNcd.models.ResNet50FPNcd.models.ResNeXt50FPNcd.models.ResNet101FPNcd.models.ResNet152FPNcd.models.ResNeXt101FPNcd.models.ResNeXt152FPNcd.models.WideResNet50FPNcd.models.WideResNet101FPNcd.models.MobileNetV3LargeFPNcd.models.MobileNetV3SmallFPN
ConvNeXt Networks
# ConvNeXt Networks are available in 2D and 3D
import celldetection as cd
model = cd.models.ConvNeXtSmall(in_channels=3, nd=3)
Residual Networks
# Residual Networks are available in 2D and 3D
import celldetection as cd
model = cd.models.ResNet50(in_channels=3, nd=3)
Mobile Networks
🤗 Hugging Face Spaces
Find us on Hugging Face and upload your own images for segmentation: https://huggingface.co/spaces/ericup/celldetection
Hugging Face API
Python
import requests
response = requests.post("https://ericup-celldetection.hf.space/run/predict", json={
"data": [
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg==",
"ginoro_CpnResNeXt101UNet-fbe875f1a3e5ce2c",
]
}).json()
data = response["data"]
Javascript
const response = await fetch("https://ericup-celldetection.hf.space/run/predict", {
method: "POST",
headers: {"Content-Type": "application/json"},
body: JSON.stringify({
data: [
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg==",
"ginoro_CpnResNeXt101UNet-fbe875f1a3e5ce2c",
]
})
});
const data = await response.json();
🧑💻 Napari Plugin
Find our Napari Plugin here: https://github.com/FZJ-INM1-BDA/celldetection-napari
Find out more about Napari here: https://napari.org
You can install it via pip:
pip install git+https://github.com/FZJ-INM1-BDA/celldetection-napari.git
🏆 Awards
- NeurIPS 2022 Cell Segmentation Challenge: Winner Finalist Award
📝 Citing
If you find this work useful, please consider giving a star ⭐️ and citation:
@article{UPSCHULTE2022102371,
title = {Contour proposal networks for biomedical instance segmentation},
journal = {Medical Image Analysis},
volume = {77},
pages = {102371},
year = {2022},
issn = {1361-8415},
doi = {https://doi.org/10.1016/j.media.2022.102371},
url = {https://www.sciencedirect.com/science/article/pii/S136184152200024X},
author = {Eric Upschulte and Stefan Harmeling and Katrin Amunts and Timo Dickscheid},
keywords = {Cell detection, Cell segmentation, Object detection, CPN},
}
🔗 Links
🧑🔬 Thanks!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file CellDetection-0.4.1.tar.gz.
File metadata
- Download URL: CellDetection-0.4.1.tar.gz
- Upload date:
- Size: 109.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5098e5643d10ad7087766a8cd666a5b0c06e662ff5c0bafcf968a0aba0c35c3d
|
|
| MD5 |
a30e82874e8cb86d259a209fe22a5952
|
|
| BLAKE2b-256 |
1823b9668c2b7907a9ad994d2e852c4267b01ac137315efac745e9e213257a41
|
File details
Details for the file CellDetection-0.4.1-py3-none-any.whl.
File metadata
- Download URL: CellDetection-0.4.1-py3-none-any.whl
- Upload date:
- Size: 123.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
270bf3385f97ab0cb95fcf63fd7574719f601870bcfe5b4335ad118af5bcddc2
|
|
| MD5 |
5a1b01bb7df846980a084684b726c316
|
|
| BLAKE2b-256 |
c57178251f1ec2825ce71556065f07813036bfea1ce34b3523095ff46b5c7169
|