Kidney Tubule Segmentation & Classification

基于 CellPose + CPSAM (SAM ViT-L) 的肾小管自动分割与近端/远端分类模型。

模型概览

本仓库包含两个模型:

模型 架构 大小 用途
cpsam_v2_fold3/best_model CPSAM (SAM ViT-L + CellPose) 1.22 GB 肾小管实例分割
classifier/cnn_classifier_fold0.pth ResNet18 43 MB 近端/远端分类

性能

5-fold 交叉验证,46 张 H&E 染色肾组织图像:

指标 5-fold 均值 最佳 Fold (fold 3)
IoU 0.844 0.858
Dice 0.914 0.923
mIoU 0.678 0.708
AP@0.5 0.845 ± 0.017 0.871

最佳单图 AP@0.5: 0.964 (Captured 32, fold 0)

数据

  • 类型: 小鼠肾脏 H&E 染色切片
  • 数量: 46 张图像
  • 标注: GeoJSON 多边形(class 0=proximal, 1=distal, 2=other)
  • 分辨率: 0.25 μm/pixel

训练

分割模型

  • 预训练: CPSAM (CellPose + SAM ViT-L encoder)
  • 学习率: 0.0001
  • Epochs: 200
  • 5-fold cross-validation
  • Fold 3 表现最佳,作为发布模型

分类器

  • 架构: ResNet18
  • 输入: per-instance 裁剪 patch (64x64 px)
  • 类别: proximal (0), distal (1)
  • 训练: fold 0 数据

使用方法

安装依赖

conda create -n cellpose python=3.10
conda activate cellpose
pip install cellpose==4.2.1 torch opencv-python numpy huggingface_hub

下载模型

huggingface-cli download MEIPork/kidney-tubule-cpsam --local-dir models/

国内网络: export HF_ENDPOINT=https://hf-mirror.com

推理

from cellpose import models
import cv2, numpy as np

# 加载分割模型
model = models.CellposeModel(
    gpu=True,
    pretrained_model='models/cpsam_v2_fold3/best_model'
)

# 推理
img = cv2.imread('kidney_section.jpg')
masks, flows, styles = model.eval(
    img,
    diameter=414,
    flow_threshold=0.3,
    cellprob_threshold=-0.5,
    channels=[0, 0]
)

或使用项目配套脚本:

python predict_tubule.py \
    --img_dir data/test_images \
    --seg_model models/cpsam_v2_fold3/best_model \
    --cls_model models/classifier/cnn_classifier_fold0.pth \
    --out_dir results/output \
    --flow_threshold 0.3 \
    --cellprob_threshold -0.5

输出

  • *_classified.png — 分割+分类叠加图(红=近端,蓝=远端)
  • *_analysis.csv — 每实例的类别、置信度、面积、bbox
  • summary.json — 批次汇总

推理参数

参数 推荐值 说明
flow_threshold 0.3 越低越敏感(更多细小结构)
cellprob_threshold -0.5 越低 mask 越大
diameter 414 肾小管平均直径 (px)

硬件要求

  • GPU: NVIDIA GPU (≥8GB VRAM) 推荐
  • CPU 可用但较慢(CPSAM ViT-L 计算量大)

代码

GitHub: MEIPork1/kidney_tubule_seg

引用

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support
Free AI Image Generator No sign-up. Instant results. Open Now