mn-DINO
Project description
mn-DINO
Detecting micronuclei in images using DINOv2 backbone
Refer to tutorial notebook for real examples
Install package
pip install mn-dino
Load the model
import torch
from mn-dino import mnmodel
from huggingface_hub import hf_hub_download
model_path = hf_hub_download(repo_id="yifanren/mn-DINO", filename="latest.pth")
device = "cuda" if torch.cuda.is_available() else "cpu"
model = mnmodel.MicronucleiModel(device=device)
model.load(model_path)
Make predictions
import skimage
import numpy as np
STEP = 64 # recommended value
PREDICTION_BATCH = 4
THRESHOLD = 0.5
im = skimage.io.imread(your_image_path)
im = np.array((im - np.min(im))/(np.max(im) - np.min(im)), dtype="float32") # normalize image
probabilities = model.predict(im, stride=1, step=STEP, batch_size=PREDICTION_BATCH)
mn_predictions = probabilities[0,:,:] > THRESHOLD
nuclei_predictions = probabilities[1,:,:] > THRESHOLD
Evaluation
import skimage
from mn-dino import evaluation
mn_gt = skimage.io.imread(your_annotated_image_path) # make sure the annotations are masks
evaluation.segmentation_report(imid='My_Image', predictions=mn_predictions, gt=mn_gt, intersection_ratio=0.1)
Train your own specialist model
- Expected file extension of training images and nuclei masks is
.tif, the corresponding training masks is.png. Following values are tunable if retraining on non-micronucleus subcellular datasets. - Combined loss = 0.8 * subcellular loss + 0.2 * nuclei loss.
device = f"cuda:{gpu}" if torch.cuda.is_available() else 'cpu'
model = mnmodel.MicronucleiModel(
device=device,
data_dir=DIRECTORY,
patch_size=256,
scale_factor=1.0,
gaussian=True
)
model.train(epochs=20,
batch_size=4,
learning_rate=1e-5,
loss_fn='combined',
finetune=True,
weight_decay=1e-6,
wandb_mode=False
)
model.save(outdir=OUTPUT_DIR, model_name=MODEL_NAME)
Reproducing mn-dino Training Experiment
git pull git@github.com:CaicedoLab/micronuclei-detection.git
cd micronuclei-detection
Training
python3 training_model.py --path 'path to micronuclei dataset' --gpu 0 --epochs 20 --loss_fn 'combined' --lr 1e-6 --scale 1.0 --finetune --gaussian
Prediction
python3 prediction.py --path 'path to micronuclei dataset' --gpu 0 --step 64 --batch_size 4 --prob_threshold 0.5 --iou_threshold 0.1 --scale 1
Add --wandb_mode if user wants to show loss on Weights and Biases
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
mndino-0.0.0.1.tar.gz
(19.7 kB
view details)
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
mndino-0.0.0.1-py3-none-any.whl
(22.4 kB
view details)
File details
Details for the file mndino-0.0.0.1.tar.gz.
File metadata
- Download URL: mndino-0.0.0.1.tar.gz
- Upload date:
- Size: 19.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7562dcf1ace14f12811f2931ecc85e739c50041e671c77569d205e4c25c17b95
|
|
| MD5 |
d7bc286f14e9ab8fa59bb89bd71aae8b
|
|
| BLAKE2b-256 |
77c11530a22c2002f01e7d02659ac8095d6fb2ed41298223b0321f76c65863f7
|
File details
Details for the file mndino-0.0.0.1-py3-none-any.whl.
File metadata
- Download URL: mndino-0.0.0.1-py3-none-any.whl
- Upload date:
- Size: 22.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
55a9516aefc43dd54be4d626ec8b42c93b3c2efce0885b8782a74d58cfb0d06a
|
|
| MD5 |
3050b167ba0710b8df60eef7c3ae6433
|
|
| BLAKE2b-256 |
5ef6ae63b00b81e4c870d2bd9284dd8a682b0db31889f1fb51b043f608fe0742
|