huggingface.co
Total runs: 2.7K
24-hour runs: 2
7-day runs: 431
30-day runs: -2.0K
Model's Last Updated: 4月 19 2024
feature-extraction

Introduction of SegVol

Model Details of SegVol

image/jpeg

Language: [EN / ZH]

The SegVol is a universal and interactive model for volumetric medical image segmentation. SegVol accepts point, box, and text prompts while output volumetric segmentation. By training on 90k unlabeled Computed Tomography (CT) volumes and 6k labeled CTs, this foundation model supports the segmentation of over 200 anatomical categories.

SegVol是用于体积医学图像分割的通用交互式模型,可以使用点,框和文本作为prompt驱动模型,输出分割结果。

通过在90k个无标签CT和6k个有标签CT上进行训练,该基础模型支持对200多个解剖类别进行分割。

Paper , Code 和 Demo 已发布。

Keywords : 3D medical SAM, volumetric image segmentation

Quicktart
Requirements
conda create -n segvol_transformers python=3.8
conda activate segvol_transformers

pytorch v1.11.0 or higher version is required. Please also install the following support packages:

需要 pytorch v1.11.0 或更高版本。另外请安装如下支持包:

pip install 'monai[all]==0.9.0'
pip install einops==0.6.1
pip install transformers==4.18.0
pip install matplotlib
Test script
from transformers import AutoModel, AutoTokenizer
import torch
import os

# get device
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")

# load model
clip_tokenizer = AutoTokenizer.from_pretrained("BAAI/SegVol")
model = AutoModel.from_pretrained("BAAI/SegVol", trust_remote_code=True, test_mode=True)
model.model.text_encoder.tokenizer = clip_tokenizer
model.eval()
model.to(device)
print('model load done')

# set case path
ct_path = 'path/to/Case_image_00001_0000.nii.gz'
gt_path = 'path/to/Case_label_00001.nii.gz'

# set categories, corresponding to the unique values(1, 2, 3, 4, ...) in ground truth mask
categories = ["liver", "kidney", "spleen", "pancreas"]

# generate npy data format
ct_npy, gt_npy = model.processor.preprocess_ct_gt(ct_path, gt_path, category=categories)
# IF you have download our 25 processed datasets, you can skip to here with the processed ct_npy, gt_npy files

# go through zoom_transform to generate zoomout & zoomin views
data_item = model.processor.zoom_transform(ct_npy, gt_npy)

# add batch dim manually
data_item['image'], data_item['label'], data_item['zoom_out_image'], data_item['zoom_out_label'] = \
data_item['image'].unsqueeze(0).to(device), data_item['label'].unsqueeze(0).to(device), data_item['zoom_out_image'].unsqueeze(0).to(device), data_item['zoom_out_label'].unsqueeze(0).to(device)

# take liver as the example
cls_idx = 0

# text prompt
text_prompt = [categories[cls_idx]]

# point prompt
point_prompt, point_prompt_map = model.processor.point_prompt_b(data_item['zoom_out_label'][0][cls_idx], device=device)   # inputs w/o batch dim, outputs w batch dim

# bbox prompt
bbox_prompt, bbox_prompt_map = model.processor.bbox_prompt_b(data_item['zoom_out_label'][0][cls_idx], device=device)   # inputs w/o batch dim, outputs w batch dim

print('prompt done')

# segvol test forward
# use_zoom: use zoom-out-zoom-in
# point_prompt_group: use point prompt
# bbox_prompt_group: use bbox prompt
# text_prompt: use text prompt
logits_mask = model.forward_test(image=data_item['image'],
      zoomed_image=data_item['zoom_out_image'],
      # point_prompt_group=[point_prompt, point_prompt_map],
      bbox_prompt_group=[bbox_prompt, bbox_prompt_map],
      text_prompt=text_prompt,
      use_zoom=True
      )

# cal dice score
dice = model.processor.dice_score(logits_mask[0][0], data_item['label'][0][cls_idx], device)
print(dice)

# save prediction as nii.gz file
save_path='./Case_preds_00001.nii.gz'
model.processor.save_preds(ct_path, save_path, logits_mask[0][0], 
                           start_coord=data_item['foreground_start_coord'], 
                           end_coord=data_item['foreground_end_coord'])
print('done')
Training script
from transformers import AutoModel, AutoTokenizer
import torch
import os

# get device
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")

# load model
clip_tokenizer = AutoTokenizer.from_pretrained("BAAI/SegVol")
model = AutoModel.from_pretrained("BAAI/SegVol", trust_remote_code=True, test_mode=False)
model.model.text_encoder.tokenizer = clip_tokenizer
model.train()
model.to(device)
print('model load done')

# set case path
ct_path = 'path/to/Case_image_00001_0000.nii.gz'
gt_path = 'path/to/Case_label_00001.nii.gz'

# set categories, corresponding to the unique values(1, 2, 3, 4, ...) in ground truth mask
categories = ["liver", "kidney", "spleen", "pancreas"]

# generate npy data format
ct_npy, gt_npy = model.processor.preprocess_ct_gt(ct_path, gt_path, category=categories)
# IF you have download our 25 processed datasets, you can skip to here with the processed ct_npy, gt_npy files

# go through train transform
data_item = model.processor.train_transform(ct_npy, gt_npy)

# training example
# add batch dim manually
image, gt3D = data_item["image"].unsqueeze(0).to(device), data_item["label"].unsqueeze(0).to(device) # add batch dim

loss_step_avg = 0
for cls_idx in range(len(categories)):
    # optimizer.zero_grad()
    organs_cls = categories[cls_idx]
    labels_cls = gt3D[:, cls_idx]
    loss = model.forward_train(image, train_organs=organs_cls, train_labels=labels_cls)
    loss_step_avg += loss.item()
    loss.backward()
    # optimizer.step()

loss_step_avg /= len(categories)
print(f'AVG loss {loss_step_avg}')

# save ckpt
model.save_pretrained('./ckpt')
Start with M3D-Seg dataset

We have released 25 open source datasets(M3D-Seg) for training SegVol, and these preprocessed data have been uploaded to ModelScope and HuggingFace . You can use the following script to easily load cases and insert them into Test script and Training script.

我们已经发布了用于训练SegVol的25个开源数据集(M3D-Seg),并将预处理后的数据上传到了 ModelScope 和 HuggingFace 。 您可以使用下面的script方便地载入,并插入到Test script和Training script中。

import json, os
M3D_Seg_path = 'path/to/M3D-Seg'

# select a dataset
dataset_code = '0000'

# load json dict
json_path = os.path.join(M3D_Seg_path, dataset_code, dataset_code + '.json')
with open(json_path, 'r') as f:
    dataset_dict = json.load(f)

# get a case
ct_path = os.path.join(M3D_Seg_path, dataset_dict['train'][0]['image'])
gt_path = os.path.join(M3D_Seg_path, dataset_dict['train'][0]['label'])

# get categories
categories_dict = dataset_dict['labels']
categories = [x for _, x in categories_dict.items() if x != "background"]

# load npy data format
ct_npy, gt_npy = model.processor.load_uniseg_case(ct_path, gt_path)

Runs of BAAI SegVol on huggingface.co

2.7K
Total runs
2
24-hour runs
-313
3-day runs
431
7-day runs
-2.0K
30-day runs

More Information About SegVol huggingface.co Model

SegVol huggingface.co

SegVol huggingface.co is an AI model on huggingface.co that provides SegVol's model effect (), which can be used instantly with this BAAI SegVol model. huggingface.co supports a free trial of the SegVol model, and also provides paid use of the SegVol. Support call SegVol model through api, including Node.js, Python, http.

SegVol huggingface.co Url

https://huggingface.co/BAAI/SegVol

BAAI SegVol online free

SegVol huggingface.co is an online trial and call api platform, which integrates SegVol's modeling effects, including api services, and provides a free online trial of SegVol, you can try SegVol online for free by clicking the link below.

BAAI SegVol online free url in huggingface.co:

https://huggingface.co/BAAI/SegVol

SegVol install

SegVol is an open source model from GitHub that offers a free installation service, and any user can find SegVol on GitHub to install. At the same time, huggingface.co provides the effect of SegVol install, users can directly use SegVol installed effect in huggingface.co for debugging and trial. It also supports api for free installation.

SegVol install url in huggingface.co:

https://huggingface.co/BAAI/SegVol

Url of SegVol

SegVol huggingface.co Url

Provider of SegVol huggingface.co

BAAI
ORGANIZATIONS

Other API from BAAI

huggingface.co

Total runs: 31.0M
Run Growth: -6.3M
Growth Rate: -20.25%
Updated:7月 03 2024
huggingface.co

Total runs: 9.0M
Run Growth: -1.3M
Growth Rate: -14.01%
Updated:2月 21 2024
huggingface.co

Total runs: 2.5M
Run Growth: 298.7K
Growth Rate: 12.17%
Updated:4月 17 2024
huggingface.co

Total runs: 339.8K
Run Growth: -700.6K
Growth Rate: -206.17%
Updated:4月 02 2024
huggingface.co

Total runs: 328.6K
Run Growth: -477.3K
Growth Rate: -145.26%
Updated:10月 12 2023
huggingface.co

Total runs: 168.7K
Run Growth: -38.3K
Growth Rate: -22.72%
Updated:12月 13 2023
huggingface.co

Total runs: 111.9K
Run Growth: 63.7K
Growth Rate: 56.93%
Updated:10月 12 2023
huggingface.co

Total runs: 66.7K
Run Growth: 13.2K
Growth Rate: 19.79%
Updated:10月 12 2023
huggingface.co

Total runs: 61.0K
Run Growth: 11.8K
Growth Rate: 19.39%
Updated:11月 14 2023
huggingface.co

Total runs: 31.8K
Run Growth: -33.9K
Growth Rate: -106.50%
Updated:7月 13 2026
huggingface.co

Total runs: 28.2K
Run Growth: -10.8K
Growth Rate: -36.77%
Updated:1月 15 2025
huggingface.co

Total runs: 9.2K
Run Growth: -59.8K
Growth Rate: -647.98%
Updated:10月 12 2023
huggingface.co

Total runs: 9.2K
Run Growth: -7.0K
Growth Rate: -76.44%
Updated:4月 16 2025
huggingface.co

Total runs: 3.5K
Run Growth: -1.1K
Growth Rate: -32.68%
Updated:5月 20 2025
huggingface.co

Total runs: 3.4K
Run Growth: -6.8K
Growth Rate: -199.62%
Updated:10月 12 2023
huggingface.co

Total runs: 2.2K
Run Growth: 2.1K
Growth Rate: 100.00%
Updated:10月 01 2026
huggingface.co

Total runs: 1.7K
Run Growth: -75
Growth Rate: -4.86%
Updated:4月 10 2026
huggingface.co

Total runs: 1.5K
Run Growth: -421
Growth Rate: -27.83%
Updated:1月 15 2025
huggingface.co

Total runs: 1.4K
Run Growth: -1.6K
Growth Rate: -117.32%
Updated:9月 11 2026
huggingface.co

Total runs: 1.1K
Run Growth: -1.2K
Growth Rate: -106.25%
Updated:12月 31 2022
huggingface.co

Total runs: 1.1K
Run Growth: -541
Growth Rate: -46.08%
Updated:4月 10 2026
huggingface.co

Total runs: 992
Run Growth: -1.0K
Growth Rate: -103.23%
Updated:11月 28 2024
huggingface.co

Total runs: 790
Run Growth: 727
Growth Rate: 97.98%
Updated:10月 13 2025
huggingface.co

Total runs: 679
Run Growth: -43
Growth Rate: -6.33%
Updated:2月 07 2024
huggingface.co

Total runs: 522
Run Growth: 23
Growth Rate: 4.41%
Updated:7月 13 2026
huggingface.co

Total runs: 513
Run Growth: -119
Growth Rate: -23.20%
Updated:10月 23 2024
huggingface.co

Total runs: 490
Run Growth: 248
Growth Rate: 50.61%
Updated:4月 02 2024
huggingface.co

Total runs: 461
Run Growth: 39
Growth Rate: 8.46%
Updated:7月 13 2026
huggingface.co

Total runs: 450
Run Growth: 180
Growth Rate: 40.27%
Updated:12月 25 2025
huggingface.co

Total runs: 423
Run Growth: -322
Growth Rate: -75.76%
Updated:5月 23 2025
huggingface.co

Total runs: 420
Run Growth: 146
Growth Rate: 34.76%
Updated:3月 07 2024
huggingface.co

Total runs: 412
Run Growth: 45
Growth Rate: 10.92%
Updated:7月 13 2026
huggingface.co

Total runs: 399
Run Growth: -64
Growth Rate: -16.04%
Updated:4月 18 2023
huggingface.co

Total runs: 396
Run Growth: 49
Growth Rate: 12.07%
Updated:8月 11 2026
huggingface.co

Total runs: 381
Run Growth: 19
Growth Rate: 4.82%
Updated:8月 11 2026
huggingface.co

Total runs: 367
Run Growth: -9.9K
Growth Rate: -2561.04%
Updated:9月 16 2026
huggingface.co

Total runs: 319
Run Growth: -375
Growth Rate: -117.55%
Updated:10月 24 2024
huggingface.co

Total runs: 318
Run Growth: 75
Growth Rate: 23.58%
Updated:7月 13 2026
huggingface.co

Total runs: 301
Run Growth: -45
Growth Rate: -14.95%
Updated:7月 13 2026
huggingface.co

Total runs: 299
Run Growth: 84
Growth Rate: 28.09%
Updated:7月 13 2026
huggingface.co

Total runs: 282
Run Growth: 99
Growth Rate: 35.11%
Updated:7月 13 2026
huggingface.co

Total runs: 279
Run Growth: 25
Growth Rate: 8.96%
Updated:8月 18 2026
huggingface.co

Total runs: 269
Run Growth: 54
Growth Rate: 19.64%
Updated:6月 06 2025
huggingface.co

Total runs: 268
Run Growth: 99
Growth Rate: 36.94%
Updated:11月 28 2023
huggingface.co

Total runs: 256
Run Growth: -205
Growth Rate: -78.54%
Updated:4月 10 2026
huggingface.co

Total runs: 250
Run Growth: -33
Growth Rate: -13.20%
Updated:7月 13 2026
huggingface.co

Total runs: 247
Run Growth: -50
Growth Rate: -20.24%
Updated:12月 25 2025
huggingface.co

Total runs: 243
Run Growth: 61
Growth Rate: 25.31%
Updated:10月 23 2024
huggingface.co

Total runs: 238
Run Growth: 64
Growth Rate: 26.89%
Updated:7月 13 2026
huggingface.co

Total runs: 213
Run Growth: 55
Growth Rate: 25.82%
Updated:5月 13 2024
huggingface.co

Total runs: 213
Run Growth: -18
Growth Rate: -8.53%
Updated:7月 17 2026
huggingface.co

Total runs: 212
Run Growth: -1.1K
Growth Rate: -512.50%
Updated:9月 11 2026
huggingface.co

Total runs: 210
Run Growth: 51
Growth Rate: 24.29%
Updated:5月 13 2024
huggingface.co

Total runs: 207
Run Growth: 53
Growth Rate: 25.60%
Updated:5月 13 2024
huggingface.co

Total runs: 207
Run Growth: 57
Growth Rate: 27.54%
Updated:5月 31 2024
huggingface.co

Total runs: 204
Run Growth: 57
Growth Rate: 27.94%
Updated:12月 21 2023
huggingface.co

Total runs: 203
Run Growth: 20
Growth Rate: 9.85%
Updated:6月 24 2024
huggingface.co

Total runs: 195
Run Growth: 42
Growth Rate: 21.54%
Updated:12月 21 2023
huggingface.co

Total runs: 195
Run Growth: 37
Growth Rate: 18.97%
Updated:6月 24 2024
huggingface.co

Total runs: 190
Run Growth: 21
Growth Rate: 11.05%
Updated:7月 13 2026