Skip to main content

Typer CLI package for the Vit medical multi-axis Vision Transformer project.

Project description

btvit-cli

基于 PyTorch 的三轴 ViT 医学影像二分类 CLI。

安装

pip install btvit-cli
vit --version

当前主线

项目现在只保留一条流程:

  1. axis 阶段分别训练 x / y / z 三个轴的单轴 ViT
  2. fusion 阶段复用三轴 encoder,训练患者级 fusion_nn
  3. pred 阶段支持两种患者级输出:
    • weighted_vote
    • fusion_nn
    • both

每个患者的每张 (16, 368) 灰度图都作为独立样本共享患者标签,不再使用旧的中间特征缓存或跨轴组合穷举训练流程。

快速开始

1. 导出模板

vit get --path ./configs

导出内容:

  • model_config.yaml
  • data_config.yaml
  • training_config.yaml
  • experiment_config.yaml
  • multi_axis_config.yaml
  • monitoring_config.yaml
  • USAGE.md

2. 训练三轴 ViT

vit train --config configs/base --stage axis --axis x --verbose
vit train --config configs/base --stage axis --axis y --verbose
vit train --config configs/base --stage axis --axis z --verbose

关键参数:

  • --stage axis
  • --axis x|y|z
  • --config <yaml_dir>
  • --data 可选。未提供时使用 multi_axis.axis_data_paths.<axis>
  • --label 可选。未提供时使用配置文件中的标签路径

3. 训练 fusion 头

vit train --config configs/base --stage fusion --verbose

fusion 阶段会默认解析:

  • experiments/<name>/axis-x/checkpoints/best_model.pth
  • experiments/<name>/axis-y/checkpoints/best_model.pth
  • experiments/<name>/axis-z/checkpoints/best_model.pth

也可以显式覆盖:

  • --axis-checkpoint-x
  • --axis-checkpoint-y
  • --axis-checkpoint-z

4. 患者级预测

vit pred --mode weighted_vote --config configs/base --data dataset/predict_root
vit pred --mode fusion_nn --config configs/base --data dataset/predict_root
vit pred --mode both --config configs/base --data dataset/predict_root --label dataset/label.csv

预测模式:

  • weighted_vote:单图概率 -> 轴内患者均值 -> 跨轴加权投票
  • fusion_nn:单图特征 -> 轴内患者均值 -> fusion head
  • both:同时输出两条分支

预测数据支持:

  1. 根目录包含 data-x/data-y/data-z/
  2. 平铺 PNG 目录,文件名为 {patient_id}_{Z}_{Y}_{X}.png

输出结构

训练输出:

experiments/<experiment_name>/
  axis-x/
    checkpoints/
    results/
    logs/
  axis-y/
    checkpoints/
    results/
    logs/
  axis-z/
    checkpoints/
    results/
    logs/
  fusion/
    checkpoints/
    results/
    logs/
  testset/
    data-x/
    data-y/
    data-z/
    label.csv

预测输出:

  • predictions.csv
  • prediction_summary.json
  • confusion_matrix_weighted_vote.png,当有标签且启用 weighted_vote
  • confusion_matrix_fusion_nn.png,当有标签且启用 fusion_nn

配置要点

  • training.common:设备、worker、混合精度等公共训练参数
  • training.axis:单轴 ViT 训练参数
  • training.fusion:fusion 头训练参数
  • multi_axis.patient_pooling:患者内均值聚合规则
  • multi_axis.weighted_vote:加权投票配置
  • multi_axis.fusion_head:患者级 fusion 头配置
  • monitoring.axis / monitoring.fusion / monitoring.prediction:分阶段监控与预测阈值

开发

conda activate Vit
pip install -e .
vit --help

构建:

conda run -n Vit python -m build

许可证

Apache-2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

btvit_cli-0.2.3.tar.gz (138.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

btvit_cli-0.2.3-py3-none-any.whl (126.5 kB view details)

Uploaded Python 3

File details

Details for the file btvit_cli-0.2.3.tar.gz.

File metadata

  • Download URL: btvit_cli-0.2.3.tar.gz
  • Upload date:
  • Size: 138.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for btvit_cli-0.2.3.tar.gz
Algorithm Hash digest
SHA256 538a07d58903c624c1fcb398d9a458422e16886d785fa9f60a45e8e63a44563f
MD5 2298f13d17f0e4ebda2e0f18709d620f
BLAKE2b-256 b2762f745afbd305a93627dd7b2811a1f804a1374d55338feb0eb219a1720a07

See more details on using hashes here.

File details

Details for the file btvit_cli-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: btvit_cli-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 126.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for btvit_cli-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 39053dc7acf6d8d20e3cf31c1fac0356fd0c6801bf00fa5d9943b7d671b33639
MD5 09b5f63336c46656d5f6b7414e23fbba
BLAKE2b-256 039582f309392fe7d99259341af9657ddf6733655ea6219214b01484930c0ed1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page