digital-pathology
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDigital Pathology
数字病理
Overview
概述
This skill teaches the agent to generate correct, runnable code for whole-slide image (WSI) pipelines. It covers TIAToolbox CLI and Python API, the H-optimus-0 foundation model, the standard tissue→tiles→features→aggregate→predict pattern, the CAMELYON datasets, and SageMaker deployment patterns for regulated workloads.
Default to TIAToolbox primitives (, , ) rather than reimplementing slide I/O. Default to H-optimus-0 at 0.5 mpp / 224×224 unless the task specifies otherwise.
WSIReaderPatchPredictorDeepFeatureExtractor本 skill 指导 Agent 生成正确、可运行的全切片图像(WSI)流水线代码。内容涵盖 TIAToolbox CLI 和 Python API、H-optimus-0 基础模型、标准的“组织→图块→特征→聚合→预测”流程、CAMELYON 数据集,以及面向受监管工作负载的 SageMaker 部署模式。
默认使用 TIAToolbox 原语(、、),而不是重新实现切片 I/O。除非任务另有说明,默认使用 H-optimus-0,分辨率为 0.5 mpp / 224×224。
WSIReaderPatchPredictorDeepFeatureExtractorUsage
用法
Invoke this skill when the user asks to:
- Inspect, tile, or stain-normalize a WSI (SVS, NDPI, MRXS, pyramidal TIFF).
- Extract features with a pathology foundation model.
- Build a slide-level classifier on CAMELYON or similar cohorts.
- Deploy a WSI model to AWS SageMaker.
Ask for clarification only if the resolution, model, or output artifact is ambiguous. Otherwise apply the defaults in the Resolution Rules section.
当用户要求执行以下操作时调用本 skill:
- 检查、切片或对 WSI(SVS、NDPI、MRXS、金字塔 TIFF)进行染色标准化。
- 使用病理基础模型提取特征。
- 在 CAMELYON 或类似队列上构建切片级分类器。
- 将 WSI 模型部署到 AWS SageMaker。
仅当分辨率、模型或输出产物不明确时才请求澄清。否则应用“分辨率规则”部分中的默认值。
Response Format
响应格式
- Lead with the command or code the user needs — explain after
- Structure as: confirm inputs → working code → key parameters explained → gotchas
- One complete working example per task; do not show every alternative
- Keep code comments minimal and functional (what, not why-it-exists)
- Target: 50-100 lines of code with brief surrounding explanation
- 先给出用户需要的命令或代码——之后再进行说明
- 结构:确认输入 → 可运行代码 → 关键参数说明 → 注意事项
- 每项任务提供一个完整可运行的示例;不要展示所有替代方案
- 代码注释应精简且实用(说明做什么,而非解释其存在原因)
- 目标:50–100 行代码,并附简短说明
Core Concepts
核心概念
- Pyramidal WSI: multi-resolution image (levels). = level 0 (native, finest). Addressing uses
baseline+resolution.units ∈ {mpp, power, level, baseline} - mpp: microns per pixel. ,
0.5 mpp ≈ 20×. Downsample =0.25 mpp ≈ 40×.baseline_mpp / target_mpp - Tissue mask: binary foreground mask computed at low resolution (e.g., Otsu at 1.25× or 4 mpp) to skip background tiles.
- Patch / tile: fixed-size crop (e.g., 224×224) read at a target mpp, used as model input.
- Foundation model embedding: per-tile feature vector from a pretrained ViT (H-optimus-0 → 1536-d).
- Aggregation: slide-level prediction from tile features (ABMIL, CLAM, TransMIL, SlideGraph).
- 金字塔 WSI:多分辨率图像(层级)。= 0 级(原生、最精细)。寻址使用
baseline+resolution。units ∈ {mpp, power, level, baseline} - mpp:每像素微米数。,
0.5 mpp ≈ 20×。下采样系数 =0.25 mpp ≈ 40×。baseline_mpp / target_mpp - 组织掩膜:在低分辨率下计算的二值前景掩膜(例如,在 1.25× 或 4 mpp 下使用 Otsu),用于跳过背景图块。
- Patch / tile:固定大小的裁剪区域(例如 224×224),按目标 mpp 读取,用作模型输入。
- 基础模型嵌入:预训练 ViT 为每个图块生成的特征向量(H-optimus-0 → 1536 维)。
- 聚合:根据图块特征生成切片级预测(ABMIL、CLAM、TransMIL、SlideGraph)。
Quick Reference — Standard Pipeline
快速参考——标准流水线
Copy-adapt this end-to-end pattern for any WSI classification task:
python
import torch
from tiatoolbox.wsicore.wsireader import WSIReader
from tiatoolbox.models.architecture.vanilla import TimmBackbone
from tiatoolbox.models.engine.semantic_segmentor import IOSegmentorConfig
from tiatoolbox.models.engine.patch_predictor import IOPatchPredictorConfig
from tiatoolbox.models import DeepFeatureExtractor
SLIDE = "slide.svs"
OUT = "./out"
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"复制并调整以下端到端模式,用于任意 WSI 分类任务:
python
import torch
from tiatoolbox.wsicore.wsireader import WSIReader
from tiatoolbox.models.architecture.vanilla import TimmBackbone
from tiatoolbox.models.engine.semantic_segmentor import IOSegmentorConfig
from tiatoolbox.models.engine.patch_predictor import IOPatchPredictorConfig
from tiatoolbox.models import DeepFeatureExtractor
SLIDE = "slide.svs"
OUT = "./out"
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"1. Inspect
1. Inspect
reader = WSIReader.open(SLIDE)
info = reader.info.as_dict()
print(info["mpp"], info["level_dimensions"])
reader = WSIReader.open(SLIDE)
info = reader.info.as_dict()
print(info["mpp"], info["level_dimensions"])
2. Tissue mask (Otsu at low res — do NOT pass as external mask)
2. Tissue mask (Otsu at low res — do NOT pass as external mask)
mask_reader = reader.tissue_mask(method="otsu", resolution=4, units="mpp")
mask_reader = reader.tissue_mask(method="otsu", resolution=4, units="mpp")
3. Tile + extract H-optimus-0 features @ 0.5 mpp, 224x224
3. Tile + extract H-optimus-0 features @ 0.5 mpp, 224x224
ioconfig = IOPatchPredictorConfig(
input_resolutions=[{"units": "mpp", "resolution": 0.5}],
patch_input_shape=[224, 224],
stride_shape=[224, 224],
)
extractor = DeepFeatureExtractor(
model=TimmBackbone("H-optimus-0", pretrained=True),
batch_size=16,
num_loader_workers=4,
)
output = extractor.run(
images=[SLIDE],
masks=[mask_reader],
patch_mode=False,
ioconfig=ioconfig,
save_dir=OUT,
device=DEVICE,
)
ioconfig = IOPatchPredictorConfig(
input_resolutions=[{"units": "mpp", "resolution": 0.5}],
patch_input_shape=[224, 224],
stride_shape=[224, 224],
)
extractor = DeepFeatureExtractor(
model=TimmBackbone("H-optimus-0", pretrained=True),
batch_size=16,
num_loader_workers=4,
)
output = extractor.run(
images=[SLIDE],
masks=[mask_reader],
patch_mode=False,
ioconfig=ioconfig,
save_dir=OUT,
device=DEVICE,
)
output[0] -> (positions.npy, features.npy)
output[0] -> (positions.npy, features.npy)
Then aggregate (ABMIL / SlideGraph / mean-pool) on `features.npy` for a slide-level prediction.
随后在 `features.npy` 上执行聚合(ABMIL / SlideGraph / mean-pool),生成切片级预测。TIAToolbox CLI
TIAToolbox CLI
All CLI commands accept (file or dir), , , , , .
--img-input--output-path--resolution--units--batch-size--device cudabash
undefined所有 CLI 命令都接受 (文件或目录)、、、、、。
--img-input--output-path--resolution--units--batch-size--device cudabash
undefinedSlide metadata
Slide metadata
tiatoolbox slide-info --img-input slide.svs --mode show
tiatoolbox slide-info --img-input slide.svs --mode show
Tissue mask (binary PNG)
Tissue mask (binary PNG)
tiatoolbox tissue-mask --img-input slide.svs --output-path ./mask --method otsu
--resolution 1.25 --units power
--resolution 1.25 --units power
tiatoolbox tissue-mask --img-input slide.svs --output-path ./mask --method otsu
--resolution 1.25 --units power
--resolution 1.25 --units power
Tile classification with built-in ResNet18 on Kather100k
Tile classification with built-in ResNet18 on Kather100k
tiatoolbox patch-predictor --img-input slide.svs
--pretrained-model resnet18-kather100k
--output-path ./pred --batch-size 32 --device cuda
--resolution 0.5 --units mpp
--pretrained-model resnet18-kather100k
--output-path ./pred --batch-size 32 --device cuda
--resolution 0.5 --units mpp
tiatoolbox patch-predictor --img-input slide.svs
--pretrained-model resnet18-kather100k
--output-path ./pred --batch-size 32 --device cuda
--resolution 0.5 --units mpp
--pretrained-model resnet18-kather100k
--output-path ./pred --batch-size 32 --device cuda
--resolution 0.5 --units mpp
Stain normalization (Reinhard / Macenko / Vahadane)
Stain normalization (Reinhard / Macenko / Vahadane)
tiatoolbox stain-norm --img-input tiles/ --method reinhard --output-path ./norm
Use `--units baseline` when inputs are pre-extracted PNG tiles to avoid an "unknown scale" warning.tiatoolbox stain-norm --img-input tiles/ --method reinhard --output-path ./norm
处理预先提取的 PNG 图块时,使用 `--units baseline`,以避免出现“unknown scale”警告。TIAToolbox Python API
TIAToolbox Python API
WSIReader
WSIReader
python
from tiatoolbox.wsicore.wsireader import WSIReader
reader = WSIReader.open("slide.svs")
reader.info.as_dict() # mpp, levels, vendor
reader.slide_dimensions(resolution=0.5, units="mpp")
tile = reader.read_rect(
location=(10000, 10000), # baseline coords
size=(224, 224),
resolution=0.5, units="mpp",
)
region = reader.read_bounds(
bounds=(0, 0, 4096, 4096),
resolution=2.0, units="mpp",
)
mask = reader.tissue_mask(method="otsu", resolution=4, units="mpp")python
from tiatoolbox.wsicore.wsireader import WSIReader
reader = WSIReader.open("slide.svs")
reader.info.as_dict() # mpp, levels, vendor
reader.slide_dimensions(resolution=0.5, units="mpp")
tile = reader.read_rect(
location=(10000, 10000), # baseline coords
size=(224, 224),
resolution=0.5, units="mpp",
)
region = reader.read_bounds(
bounds=(0, 0, 4096, 4096),
resolution=2.0, units="mpp",
)
mask = reader.tissue_mask(method="otsu", resolution=4, units="mpp")PatchPredictor
PatchPredictor
python
from tiatoolbox.models import PatchPredictor
from tiatoolbox.models.engine.patch_predictor import IOPatchPredictorConfig
ioconfig = IOPatchPredictorConfig(
input_resolutions=[{"units": "mpp", "resolution": 0.5}],
patch_input_shape=[224, 224],
stride_shape=[224, 224],
)
predictor = PatchPredictor(pretrained_model="resnet18-kather100k", batch_size=32)
out = predictor.run(
images=["slide.svs"], masks=[mask],
patch_mode=False, ioconfig=ioconfig,
save_dir="./pred", device="cuda",
)python
from tiatoolbox.models import PatchPredictor
from tiatoolbox.models.engine.patch_predictor import IOPatchPredictorConfig
ioconfig = IOPatchPredictorConfig(
input_resolutions=[{"units": "mpp", "resolution": 0.5}],
patch_input_shape=[224, 224],
stride_shape=[224, 224],
)
predictor = PatchPredictor(pretrained_model="resnet18-kather100k", batch_size=32)
out = predictor.run(
images=["slide.svs"], masks=[mask],
patch_mode=False, ioconfig=ioconfig,
save_dir="./pred", device="cuda",
)DeepFeatureExtractor + TimmBackbone
DeepFeatureExtractor + TimmBackbone
python
from tiatoolbox.models import DeepFeatureExtractor
from tiatoolbox.models.architecture.vanilla import TimmBackbone
extractor = DeepFeatureExtractor(
model=TimmBackbone("H-optimus-0", pretrained=True),
batch_size=16, num_loader_workers=4,
)python
from tiatoolbox.models import DeepFeatureExtractor
from tiatoolbox.models.architecture.vanilla import TimmBackbone
extractor = DeepFeatureExtractor(
model=TimmBackbone("H-optimus-0", pretrained=True),
batch_size=16, num_loader_workers=4,
)SlideGraph construction
SlideGraph 构建
python
import numpy as np
from tiatoolbox.tools.graph import SlideGraphConstructor
positions = np.load("out/0.position.npy") # (N, 4) x1,y1,x2,y2
features = np.load("out/0.features.npy") # (N, D)
graph = SlideGraphConstructor.build(
positions=positions[:, :2], features=features,
)python
import numpy as np
from tiatoolbox.tools.graph import SlideGraphConstructor
positions = np.load("out/0.position.npy") # (N, 4) x1,y1,x2,y2
features = np.load("out/0.features.npy") # (N, D)
graph = SlideGraphConstructor.build(
positions=positions[:, :2], features=features,
)graph -> {"x": features, "edge_index": (2,E), "coords": (N,2)}
graph -> {"x": features, "edge_index": (2,E), "coords": (N,2)}
undefinedundefinedStain normalization
染色标准化
python
from tiatoolbox.tools.stainnorm import get_normalizer
norm = get_normalizer("reinhard") # or "macenko", "vahadane"
norm.fit(target_tile) # RGB ndarray HxWx3
normed = norm.transform(source_tile)python
from tiatoolbox.tools.stainnorm import get_normalizer
norm = get_normalizer("reinhard") # or "macenko", "vahadane"
norm.fit(target_tile) # RGB ndarray HxWx3
normed = norm.transform(source_tile)H-optimus-0 Foundation Model
H-optimus-0 基础模型
1.1B-parameter ViT-G/14, input 224×224 RGB at 0.5 mpp, output 1536-d embedding. License is gated — accept terms on Hugging Face and run .
huggingface-cli login1.1B 参数规模的 ViT-G/14,输入为 0.5 mpp 下的 224×224 RGB 图像,输出为 1536 维嵌入。许可证受门控控制——需在 Hugging Face 上接受条款并运行 。
huggingface-cli loginDirect timm usage
直接使用 timm
python
import timm, torch
from torchvision import transforms
model = timm.create_model(
"hf-hub:bioptimus/H-optimus-0",
pretrained=True,
init_values=1e-5,
dynamic_img_size=False,
).eval().to("cuda")
preprocess = transforms.Compose([
transforms.ToTensor(),
transforms.Normalize(
mean=(0.707223, 0.578729, 0.703617),
std=(0.211883, 0.230117, 0.177517),
),
])
with torch.inference_mode(), torch.autocast("cuda", dtype=torch.float16):
feats = model(preprocess(tile).unsqueeze(0).to("cuda")) # (1, 1536)Use on a 24 GB GPU with fp16 autocast. Prefer inside — TIAToolbox applies the correct preprocessing automatically.
batch_size=16TimmBackbone("H-optimus-0", pretrained=True)DeepFeatureExtractorpython
import timm, torch
from torchvision import transforms
model = timm.create_model(
"hf-hub:bioptimus/H-optimus-0",
pretrained=True,
init_values=1e-5,
dynamic_img_size=False,
).eval().to("cuda")
preprocess = transforms.Compose([
transforms.ToTensor(),
transforms.Normalize(
mean=(0.707223, 0.578729, 0.703617),
std=(0.211883, 0.230117, 0.177517),
),
])
with torch.inference_mode(), torch.autocast("cuda", dtype=torch.float16):
feats = model(preprocess(tile).unsqueeze(0).to("cuda")) # (1, 1536)在配备 24 GB GPU 的设备上使用 并启用 fp16 autocast。优先在 中使用 ——TIAToolbox 会自动应用正确的预处理。
batch_size=16DeepFeatureExtractorTimmBackbone("H-optimus-0", pretrained=True)Resolution Rules
分辨率规则
| Model | mpp | Patch size |
|---|---|---|
| H-optimus-0 / UNI / Prov-GigaPath | 0.5 | 224×224 |
| HoVer-Net (PanNuke) | 0.25 | 256×256 |
| SlideGraph CNN features | 0.25 | 512×512 |
| Tissue mask (Otsu) | 4 mpp or 1.25× | — |
Downsample factor = . For a 0.25-mpp slide targeting 0.5 mpp, downsample by 2.
baseline_mpp / target_mpp| 模型 | mpp | Patch 大小 |
|---|---|---|
| H-optimus-0 / UNI / Prov-GigaPath | 0.5 | 224×224 |
| HoVer-Net(PanNuke) | 0.25 | 256×256 |
| SlideGraph CNN 特征 | 0.25 | 512×512 |
| 组织掩膜(Otsu) | 4 mpp 或 1.25× | — |
下采样系数 = 。对于原始分辨率为 0.25 mpp、目标分辨率为 0.5 mpp 的切片,按 2 倍下采样。
baseline_mpp / target_mppCAMELYON Datasets
CAMELYON 数据集
- Format: pyramidal , OpenSlide-compatible, ~100 000 × 100 000 px at baseline.
.tif - Annotations: ASAP XML, polygon coordinates in baseline (level-0) pixels.
- CAMELYON16: 270 training slides (+
normal/) + 130 test slides, labels intumor/. Task: slide-level tumor classification + tumor segmentation.reference.csv - CAMELYON17: 1000 slides across 100 patients (5 slides each). Patient-level pN-stage in . Official 5-fold split is by patient — never split by slide.
stages.csv
python
import xml.etree.ElementTree as ET
tree = ET.parse("slide.xml") # ASAP format
for ann in tree.iter("Annotation"):
pts = [(float(c.get("X")), float(c.get("Y")))
for c in ann.iter("Coordinate")] # baseline coords- 格式:金字塔 ,兼容 OpenSlide,原始层级约为 100 000 × 100 000 像素。
.tif - 标注:ASAP XML,多边形坐标采用 baseline(level-0)像素。
- CAMELYON16:270 张训练切片(+
normal/)+ 130 张测试切片,标签位于tumor/。任务:切片级肿瘤分类 + 肿瘤分割。reference.csv - CAMELYON17:来自 100 名患者的 1000 张切片(每名患者 5 张)。患者级 pN 分期位于 。官方 5 折划分按患者进行——绝不按切片划分。
stages.csv
python
import xml.etree.ElementTree as ET
tree = ET.parse("slide.xml") # ASAP format
for ann in tree.iter("Annotation"):
pts = [(float(c.get("X")), float(c.get("Y")))
for c in ann.iter("Coordinate")] # baseline coordsSageMaker Deployment
SageMaker 部署
WSIs are gigapixel — never send raw bytes through the invocation path. Pass an S3 URI in the request and let the container read via / .
s3fsboto3- Endpoint type: Async Inference (long-running, per-request) or Batch Transform (cohort scoring).
- Base container: extend .
763104351884.dkr.ecr.<region>.amazonaws.com/pytorch-inference:2.x-gpu-py310 - Apt packages: .
openslide-tools libpixman-1-dev libvips - Pip: .
tiatoolbox timm huggingface_hub s3fs - Instance: minimum for H-optimus-0 fp16 (24 GB A10G). Use
ml.g5.2xlargefor batches.ml.g5.12xlarge - Async config: ,
invocations_timeout=3600.max_concurrent_invocations_per_instance=2
python
from sagemaker.async_inference import AsyncInferenceConfig
async_config = AsyncInferenceConfig(
output_path="s3://bucket/async-out/",
max_concurrent_invocations_per_instance=2,
)
predictor = model.deploy(
instance_type="ml.g5.2xlarge", initial_instance_count=1,
async_inference_config=async_config,
)
predictor.predict_async(input_path="s3://bucket/slides/slide.svs")Dockerfile sketch:
dockerfile
FROM 763104351884.dkr.ecr.us-east-1.amazonaws.com/pytorch-inference:2.3.0-gpu-py310
RUN apt-get update && apt-get install -y openslide-tools libpixman-1-dev libvips \
&& rm -rf /var/lib/apt/lists/*
RUN pip install --no-cache-dir tiatoolbox timm huggingface_hub s3fsWSI 是十亿像素级图像——绝不通过调用路径发送原始字节。应在请求中传入 S3 URI,让容器通过 / 读取。
s3fsboto3- 端点类型:Async Inference(长时间运行、按请求执行)或 Batch Transform(队列评分)。
- 基础容器:基于 扩展。
763104351884.dkr.ecr.<region>.amazonaws.com/pytorch-inference:2.x-gpu-py310 - Apt 包:。
openslide-tools libpixman-1-dev libvips - Pip 包:。
tiatoolbox timm huggingface_hub s3fs - 实例:H-optimus-0 fp16 的最低配置为 (24 GB A10G)。批处理使用
ml.g5.2xlarge。ml.g5.12xlarge - 异步配置:,
invocations_timeout=3600。max_concurrent_invocations_per_instance=2
python
from sagemaker.async_inference import AsyncInferenceConfig
async_config = AsyncInferenceConfig(
output_path="s3://bucket/async-out/",
max_concurrent_invocations_per_instance=2,
)
predictor = model.deploy(
instance_type="ml.g5.2xlarge", initial_instance_count=1,
async_inference_config=async_config,
)
predictor.predict_async(input_path="s3://bucket/slides/slide.svs")Dockerfile 草图:
dockerfile
FROM 763104351884.dkr.ecr.us-east-1.amazonaws.com/pytorch-inference:2.3.0-gpu-py310
RUN apt-get update && apt-get install -y openslide-tools libpixman-1-dev libvips \
&& rm -rf /var/lib/apt/lists/*
RUN pip install --no-cache-dir tiatoolbox timm huggingface_hub s3fsCommon Mistakes
常见错误
-
Wrong: Using an old pixman library (<0.40) with OpenSlide Right:and rebuild, or use libvips ≥ 8.12 Why: Causes all-black tiles from
apt-get install libpixman-1-devdue to a rendering bugread_rect -
Wrong: Requesting a resolution finer than the slide's native mpp Right: Use a coarser, or check
resolutionfirst Why: Triggersreader.info.mppand produces upsampled (interpolated) dataUserWarning: Scale > 1 -
Wrong: Attempting to load H-optimus-0 without accepting the gated model terms Right: Accept terms on the Hugging Face model page, then runWhy: Results in
huggingface-cli loginauthentication failureOSError: 401 -
Wrong: Using a batch size too large for GPU memory in DeepFeatureExtractor Right: Lower(16→8→4) and ensure fp16 autocast is enabled Why: Causes CUDA out-of-memory errors
batch_size -
Wrong: Passing a non-pyramidal TIFF to OpenSlide Right: Convert first withWhy: Raises
vips tiffsave in.tif out.tif --tile --pyramid --compression jpegbecause OpenSlide requires pyramidal formatOpenSlideUnsupportedFormatError -
Wrong: Passing a numpy array as an external mask with shape not aligned to the WSI pyramid Right: Usedirectly and pass the returned reader object Why: Causes
reader.tissue_mask(...)due to resolution/shape mismatchDimensionMismatchError -
Wrong: Processing PNG tiles without specifying resolution units Right: Passand explicit
units="baseline"Why: Tiles lack mpp metadata, triggering an "unknown scale" warningresolution=1.0 -
Wrong: Splitting CAMELYON17 data by slide rather than by patient Right: Split by(5-fold) per the official protocol Why: Causes patient data leakage since each patient has 5 slides
patient_id -
Wrong: Skipping H-optimus-0 normalization (mean/std) when extracting features Right: Use(applies normalization automatically) or apply mean/std explicitly Why: Features look random and produce low AUC without proper input normalization
TimmBackbone -
Wrong: Using annotation coordinates at the wrong pyramid level Right: ASAP XML coordinates are always at baseline level — scale them when reading at lower resolution Why: Coordinates will be off by 2× or 4× if the level mismatch is not accounted for
-
错误: 使用过旧的 pixman 库(<0.40)与 OpenSlide 搭配 正确做法: 执行后重新构建,或使用 libvips ≥ 8.12 原因: 由于渲染 bug,
apt-get install libpixman-1-dev读取的所有图块都会变成全黑read_rect -
错误: 请求比切片原生 mpp 更精细的分辨率 正确做法: 使用更粗的,或先检查
resolution原因: 会触发reader.info.mpp,并生成上采样(插值)数据UserWarning: Scale > 1 -
错误: 尝试加载 H-optimus-0,但未接受受门控的模型条款 正确做法: 在 Hugging Face 模型页面上接受条款,然后运行原因: 导致
huggingface-cli login身份验证失败OSError: 401 -
错误: 在 DeepFeatureExtractor 中使用的批大小过大,超出 GPU 显存容量 正确做法: 降低(16→8→4),并确保启用 fp16 autocast 原因: 导致 CUDA 显存不足错误
batch_size -
错误: 向 OpenSlide 传入非金字塔 TIFF 正确做法: 先使用转换 原因: OpenSlide 要求金字塔格式,因此会抛出
vips tiffsave in.tif out.tif --tile --pyramid --compression jpegOpenSlideUnsupportedFormatError -
错误: 传入与 WSI 金字塔形状未对齐的 numpy 数组作为外部掩膜 正确做法: 直接使用,并传入其返回的 reader 对象 原因: 由于分辨率/形状不匹配,导致
reader.tissue_mask(...)DimensionMismatchError -
错误: 处理 PNG 图块时未指定分辨率单位 正确做法: 传入和明确的
units="baseline"原因: 图块缺少 mpp 元数据,触发“unknown scale”警告resolution=1.0 -
错误: 按切片而非按患者划分 CAMELYON17 数据 正确做法: 按官方协议,根据进行 5 折划分 原因: 每名患者有 5 张切片,按切片划分会造成患者数据泄漏
patient_id -
错误: 提取特征时跳过 H-optimus-0 的归一化(mean/std) 正确做法: 使用(自动应用归一化),或显式应用 mean/std 原因: 特征看起来像随机值,未进行正确的输入归一化会导致 AUC 较低
TimmBackbone -
错误: 使用了错误金字塔层级上的标注坐标 正确做法: ASAP XML 坐标始终位于 baseline 层级——以较低分辨率读取时必须进行缩放 原因: 如果未考虑层级差异,坐标会偏移 2× 或 4×
Minimal Dependency Set
最小依赖集
tiatoolbox>=1.5
timm>=1.0
torch>=2.1
openslide-python
huggingface_hubSystem: , , (for non-pyramidal TIFF conversion).
openslide-toolslibpixman-1-devlibvipstiatoolbox>=1.5
timm>=1.0
torch>=2.1
openslide-python
huggingface_hub系统依赖:、、(用于转换非金字塔 TIFF)。
openslide-toolslibpixman-1-devlibvipsReferences
参考资料
- TIAToolbox: Pocock et al. Commun Med 2022, https://doi.org/10.1038/s43856-022-00186-5
- H-optimus-0: Bioptimus, https://huggingface.co/bioptimus/H-optimus-0
- CAMELYON16: Bejnordi et al. JAMA 2017, https://doi.org/10.1001/jama.2017.14585
- CAMELYON17: Bandi et al. IEEE TMI 2019, https://doi.org/10.1109/TMI.2018.2867350
- TIAToolbox:Pocock 等,Commun Med 2022,https://doi.org/10.1038/s43856-022-00186-5
- H-optimus-0:Bioptimus,https://huggingface.co/bioptimus/H-optimus-0
- CAMELYON16:Bejnordi 等,JAMA 2017,https://doi.org/10.1001/jama.2017.14585
- CAMELYON17:Bandi 等,IEEE TMI 2019,https://doi.org/10.1109/TMI.2018.2867350