Flat Multi-Condition Head
SkillAI & modelsModels multiple conditions with a single flat output layer of N_labels × N_classes logits, sliced into per-condition softmax at inference.
Available today. Use it from your connected AI after setup.
No other account needed.
Connect ahel once, and every AI you use reads what you have installed.
Then ask your AI: use the Flat Multi-Condition Head skill
What this skill tells your AI
The instructions your AI receives, as published by wenmin-wu/ds-skills in skills/cv/flat-multicondition-head/SKILL.md and read by ahel’s review.
Overview
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.
Quick Start
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)
Workflow
- Set
num_classes = N_labels × N_classesin the backbone - Train with CE loss on reshaped
(B × N_labels, N_classes)logits - At inference, slice flat output into per-label chunks
- Apply softmax per chunk to get per-condition probability distributions
Key Decisions
- Flat vs multi-head: Flat is simpler; multi-head allows per-condition learning rates
- Loss weighting: Weight rare conditions higher with class weights in CE loss
- Shared backbone: All conditions share features — works well when inputs overlap
- Label ordering: Keep consistent ordering between training labels and output slicing
References
Signals
- GitHub stars
- 60
- Forks
- 4
- Last commit
- Apr 2026
Advanced
- Catalog kind
- skill
- Gateway key
cv-flat-multicondition-head- Source
- github.com/wenmin-wu/ds-skills