Run this model with HF Jobs

Run lukeingawesome/LUCAS-CT 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/lukeingawesome/LUCAS-CT. 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/lukeingawesome/LUCAS-CT 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.

LUCAS-CT

Code for training, adaptation and data preparation: github.com/lukeingawesome/LUCAS

Chest radiograph encoder trained against the paired CT volume. Each radiograph is aligned with features of its paired chest CT volume, taken from a frozen CT encoder. No report text is used.

Training used 167,427 frontal chest radiographs, each paired with a chest CT of the same patient taken within one day, from a Korean hospital. The architecture is DINOv2 ViT-B/14 at 560 x 560 pixels.

The encoder is meant to be used frozen, with a small head trained for the task at hand, or fine-tuned.

Preprocessing

Pad the radiograph to a square with black borders, resize to 560 x 560 (bicubic), scale to [0, 1] and normalise with mean 0.5307 and standard deviation 0.2583 on every channel. lucas_inference.preprocess does this.

Radiographs converted from DICOM should be windowed with the VOI LUT and inverted when MONOCHROME1, as in the conversion script of the LUCAS code repository.

Features

from huggingface_hub import snapshot_download
import sys
sys.path.insert(0, snapshot_download("lukeingawesome/LUCAS-CT"))
from lucas_inference import load, embed

model = load("lukeingawesome/LUCAS-CT", device="cuda")
features = embed(model, ["cxr_001.png", "cxr_002.png"])   # (2, 1536), L2-normalised

The feature is the CLS token joined with the mean of the patch tokens. With transformers only:

import torch
from transformers import AutoModel
model = AutoModel.from_pretrained("lukeingawesome/LUCAS-CT").eval()
tokens = model(pixel_values=pixel_values, interpolate_pos_encoding=True).last_hidden_state   # pixel_values: (N, 3, 560, 560)
features = torch.cat([tokens[:, 0], tokens[:, 1:].mean(1)], dim=1)

Seeds

The model was trained with three seeds (42, 43 and 44). The repository root holds seed 44, the seed with the best mean performance on the validation split of the training hospital; seed42/, seed43/ and seed44/ hold each seed.

from transformers import AutoModel
model = AutoModel.from_pretrained("lukeingawesome/LUCAS-CT")                                  # seed 44
model = AutoModel.from_pretrained("lukeingawesome/LUCAS-CT", trust_remote_code=True, seed=43)  # seed 42, 43 or 44
model = AutoModel.from_pretrained("lukeingawesome/LUCAS-CT", subfolder="seed43")              # same, without remote code

lucas_inference.load(..., seed=43) and finetune.py --model-seed 43 do the same.

Linear probe

Fit a logistic regression on the L2-normalised features:

from sklearn.linear_model import LogisticRegression
head = LogisticRegression(C=1.0, class_weight="balanced", max_iter=2000).fit(train_features, train_labels)
scores = head.decision_function(test_features)

Fine-tuning

finetune.py trains a classification head from a CSV with an image_path column and one 0/1 column per label.

pip install -r requirements.txt
python finetune.py --model lukeingawesome/LUCAS-CT --train train.csv --val val.csv --labels label --mode probe --out runs/probe
python finetune.py --model lukeingawesome/LUCAS-CT --train train.csv --val val.csv --labels label --mode lora --out runs/lora
python finetune.py --model lukeingawesome/LUCAS-CT --train train.csv --val val.csv --labels label --mode full --out runs/full

probe keeps the encoder frozen, lora adds rank-16 LoRA adapters to the encoder, and full trains every weight. The checkpoint with the best mean validation AUROC is written to <out>/best.pt.

Limitations

The encoder was trained on radiographs from one hospital. Performance on other populations, scanners or acquisition protocols should be measured before use. The model produces image features; it does not make diagnoses.

Licence

CC BY-NC 4.0 (non-commercial use).

Downloads last month
59
Safetensors
Model size
86.8M params
Tensor type
F32
ยท
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support