skills/cv/per-modality-separate-model/SKILL.md
Trains one specialized model per imaging modality or series type, routing inputs by metadata at inference for modality-specific feature learning.
npx skillsauth add wenmin-wu/ds-skills cv-per-modality-separate-modelInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Different imaging modalities (CT vs MRI, or MRI T1 vs T2, or X-ray PA vs lateral) have fundamentally different contrast, resolution, and anatomy visibility. A single model must learn to handle all variations, diluting its capacity. Training separate models per modality lets each specialize — Sagittal T1 learns disc morphology while Axial T2 learns nerve root compression. At inference, series metadata routes each input to the correct model. Predictions are then aggregated per study.
import timm
import torch.nn as nn
MODALITIES = ['Sagittal T1', 'Sagittal T2/STIR', 'Axial T2']
# Train one model per modality
models = {}
optimizers = {}
for mod in MODALITIES:
model = timm.create_model('efficientnet_b3', pretrained=True,
num_classes=75, in_chans=1)
models[mod] = model.cuda()
optimizers[mod] = torch.optim.Adam(model.parameters(), lr=1e-4)
# Training loop: filter batches by modality
for images, labels, modality in dataloader:
model = models[modality]
optimizer = optimizers[modality]
model.train()
logits = model(images.cuda())
loss = criterion(logits, labels.cuda())
loss.backward()
optimizer.step()
optimizer.zero_grad()
# Inference: route by series_description
def predict_study(study_series):
predictions = {}
for series_desc, images in study_series.items():
model = models[series_desc]
model.eval()
with torch.no_grad():
predictions[series_desc] = model(images.cuda())
return aggregate(predictions)
data-ai
Scaled Pinball Loss (SPL) metric for evaluating quantile forecasts, normalized by mean absolute successive differences of training data
data-ai
Walk backward through a time series and multiplicatively rescale segments when jumps exceed a fraction of the running mean to correct data collection anomalies
testing
Transform forecasting target to next/current ratio minus one so that optimizing MAE or squared error implicitly minimizes SMAPE
tools
Convert point forecasts to prediction intervals by scaling with logit-transformed quantile ratios passed through a Normal CDF