skills/cv/slice-as-channel-2d-cnn/SKILL.md
Resample a 3D medical volume to a fixed depth N (e.g. 32) and feed the N slices as input *channels* to a 2D CNN with `in_chans=N` instead of using a 3D conv backbone — gets the volumetric context for a fraction of the memory and lets you use any timm 2D pretrained model
npx skillsauth add wenmin-wu/ds-skills cv-slice-as-channel-2d-cnnInstall 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.
3D CNNs are memory hungry, train slowly, and lack pretrained weights. For many volumetric tasks (RSNA Aneurysm Detection, RSNA Cervical Spine, brain CTA panels) you can collapse the depth dimension into the channel dimension: zoom the volume to a fixed (N, H, W) shape, transpose to (H, W, N), and feed it to a 2D CNN created with timm.create_model(..., in_chans=N). The model sees all N slices simultaneously per spatial position and learns inter-slice features through its 2D convs. You give up some explicit Z-axis structure but gain ImageNet-pretrained weights, smaller model, faster training, and the option to use any 2D backbone (EfficientNetV2, ConvNeXt, Swin).
import numpy as np
from scipy import ndimage
import timm
import torch
def to_slice_channels(volume, depth=32, h=384, w=384):
z = (depth/volume.shape[0], h/volume.shape[1], w/volume.shape[2])
v = ndimage.zoom(volume, z, order=1) # (depth, h, w)
return v.astype(np.float32) / 255.0 # use as channel-first directly
model = timm.create_model('tf_efficientnetv2_s',
num_classes=14, in_chans=32, pretrained=True)
x = torch.from_numpy(to_slice_channels(volume))[None] # (1, 32, 384, 384)
logits = model(x) # one forward pass for the whole volume
(N, H, W) with linear (or trilinear) zoom; pad/crop edgesin_chans=N — timm initializes the new conv1 by averaging the 3 ImageNet channels and tilingin_chans.in_chans weight init: it averages the RGB pretrained conv1 and replicates — usually better than random for the new channels.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