Run this model with HF Jobs
Run KidsWithTokens/Medical-Adapter-Zoo on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/KidsWithTokens/Medical-Adapter-Zoo. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/KidsWithTokens/Medical-Adapter-Zoo on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use KidsWithTokens/Medical-Adapter-Zoo with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Adapters
How to use KidsWithTokens/Medical-Adapter-Zoo with Adapters:
from adapters import AutoAdapterModel model = AutoAdapterModel.from_pretrained("<base-model-id>") model.load_adapter("KidsWithTokens/Medical-Adapter-Zoo", set_active=True) - Notebooks
- Google Colab
- Kaggle
Welcome to Medical Adapters Zoo (Med-Adpt Zoo)!
Med-Adpt Zoo Map πππ¦π¦π¦¨π¦π¦₯
Lung Nodule (CT)
Melanoma (Skin Photo)
OpticCup (Fundus Image)
OpticDisc (Fundus Image)
Thyroid Nodule (UltraSound)
Aorta (Abdominal Image)
Esophagus (Abdominal Image)
Gallbladder (Abdominal Image)
Inferior Vena Cava (Abdominal Image)
Left Adrenal Gland (Abdominal Image)
Right Adrenal Gland (Abdominal Image)
Left Kidney (Abdominal Image)
Right kidney (Abdominal Image)
Liver (Abdominal Image)
Pancreas (Abdominal Image)
Spleen (Abdominal Image)
Stomach (Abdominal Image)
Portal Vein and Splenic Vein (Abdominal Image)
Edematous Tissue (Brain Tumor mpMRI)
Enhancing Tumor (Brain Tumor mpMRI)
Necrotic (Brain Tumor mpMRI)
Inferior Alveolar Nerve (CBCT)
Surgical Instrument (Surgical Video)
Kidney Tumor (MRI)
Liver (Liver Tumor CE-MRI)
Tumor (Liver Tumor CE-MRI)
Mandible (XRay)
Retina Vessel (Fundus Image)
White Blood Cell (MicroScope)
Download the Adapters you need here
What
Here are the pre-trained Adapters to transfer SAM (Segment Anything Model) for segmenting various organs/lesions from the medical images. Check our paper: Medical SAM Adapter for the details.
Why
SAM (Segment Anything Model) is one of the most popular open models for image segmentation. Unfortunately, it does not perform well on the medical images. An efficient way to solve it is using Adapters, i.e., some layers with a few parameters to be added to the pre-trained SAM model to fine-tune it to the target down-stream tasks. Medical image segmentation includes many different organs, lesions, and abnormalities as the targets. So we are training different adapters for each of the targets, and sharing them here for the easy usage in the community.
Download an adapter for your target diseaseβtrained on organs, lesions, and abnormalitiesβand effortlessly enhance SAM.
One adapter transfers your SAM to a medical domain expert. Give it a try!
How to Use
- Download the code of our MedSAM-Adapter here.
- Download the weights of the original SAM model.
- Load the original model and our adapter for downstream tasks.
import torch
import torchvision.transforms as transforms
import cfg
from utils import *
# set your own configs
args = cfg.parse_args()
GPUdevice = torch.device('cuda', args.gpu_device)
# load the original SAM model
net = get_network(args, args.net, use_gpu=args.gpu, gpu_device=GPUdevice, distribution = args.distributed)
net.eval()
sam_weights = 'checkpoint/sam/sam_vit_b_01ec64.pth' # load the original SAM weight
with open(sam_weights, "rb") as f:
state_dict = torch.load(f)
new_state_dict = {k: v for k, v in state_dict.items() if k in net.state_dict() and net.state_dict()[k].shape == v.shape}
net.load_state_dict(new_state_dict, strict = False)
# load task-specific adapter
adapter_path = 'OpticCup_Fundus_SAM_1024.pth'
checkpoint_file = os.path.join(adapter_path)
assert os.path.exists(checkpoint_file)
loc = 'cuda:{}'.format(args.gpu_device)
checkpoint = torch.load(checkpoint_file, map_location=loc)
state_dict = checkpoint['state_dict']
if args.distributed != 'none':
from collections import OrderedDict
new_state_dict = OrderedDict()
for k, v in state_dict.items():
# name = k[7:] # remove `module.`
name = 'module.' + k
new_state_dict[name] = v
# load params
else:
new_state_dict = state_dict
net.load_state_dict(new_state_dict,strict = False)
Authorship
Ziyue Wang (NUS): Adapters Training
Junde Wu (Oxford): Lead the project
Yueming Jin (NUS): Supervisor
- Downloads last month
- -