skills/cv/mixup-label-smoothing/SKILL.md
Combines mixup augmentation (linear interpolation of image pairs and their labels) with label smoothing in a single training pipeline for regularization.
npx skillsauth add wenmin-wu/ds-skills cv-mixup-label-smoothingInstall 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.
Mixup and label smoothing both soften training targets to reduce overfitting, but through different mechanisms. Mixup creates virtual training examples by linearly blending two images and their labels: img = λ·img1 + (1-λ)·img2, label = λ·y1 + (1-λ)·y2. Label smoothing shifts hard labels toward uniform: y_smooth = (1-ε)·y + ε/K. Combining both provides complementary regularization — mixup smooths the input space while label smoothing prevents overconfident predictions. Together they typically improve generalization by 0.5–1.5% accuracy.
import numpy as np
import torch
class MixupLabelSmoothingDataset(torch.utils.data.Dataset):
def __init__(self, dataset, mixup_prob=0.5, mixup_alpha=0.2,
label_smoothing=0.05, num_classes=2):
self.dataset = dataset
self.mixup_prob = mixup_prob
self.alpha = mixup_alpha
self.eps = label_smoothing
self.K = num_classes
def smooth_label(self, label):
"""Apply label smoothing: shift toward uniform."""
one_hot = torch.zeros(self.K)
one_hot[label] = 1.0
return one_hot * (1 - self.eps) + self.eps / self.K
def __getitem__(self, idx):
img1, label1 = self.dataset[idx]
target1 = self.smooth_label(label1)
if np.random.random() < self.mixup_prob:
j = np.random.randint(len(self.dataset))
img2, label2 = self.dataset[j]
target2 = self.smooth_label(label2)
lam = np.random.beta(self.alpha, self.alpha)
img = lam * img1 + (1 - lam) * img2
target = lam * target1 + (1 - lam) * target2
else:
img, target = img1, target1
return img, target
mixup_prob, sample a second example and blenddata-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