skills/cv/flat-multicondition-head/SKILL.md
Models multiple conditions with a single flat output layer of N_labels × N_classes logits, sliced into per-condition softmax at inference.
npx skillsauth add wenmin-wu/ds-skills cv-flat-multicondition-headInstall 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.
When predicting severity grades (Normal/Moderate/Severe) for multiple conditions simultaneously (e.g., 5 spinal conditions × 5 vertebral levels = 25 labels, each with 3 classes), a flat 75-dimensional output head avoids the complexity of multiple classification heads. During training, use cross-entropy on all 75 logits. At inference, slice the output into 25 groups of 3 and apply softmax per group. This is simpler to implement, faster to train, and often matches multi-head performance.
import torch
import torch.nn as nn
import timm
N_LABELS = 25 # conditions × levels
N_CLASSES = 3 # normal, moderate, severe
N_OUTPUT = N_LABELS * N_CLASSES # 75
class MultiConditionModel(nn.Module):
def __init__(self, model_name, in_chans=30):
super().__init__()
self.backbone = timm.create_model(
model_name, pretrained=True,
in_chans=in_chans, num_classes=N_OUTPUT, global_pool='avg'
)
def forward(self, x):
return self.backbone(x) # (B, 75)
# Training: reshape for per-label CE loss
logits = model(images) # (B, 75)
logits = logits.view(-1, N_LABELS, N_CLASSES) # (B, 25, 3)
loss = nn.CrossEntropyLoss()(logits.view(-1, N_CLASSES), labels.view(-1))
# Inference: per-condition softmax
logits = model(images)[0] # (75,)
for i in range(N_LABELS):
probs = logits[i*3:(i+1)*3].float().softmax(0).cpu().numpy()
predictions.append(probs)
num_classes = N_labels × N_classes in the backbone(B × N_labels, N_classes) logitsdata-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