skills/cv/bev-conv1-channel-expansion/SKILL.md
Replace a pretrained ResNet's conv1 with a wider input conv to accept stacked BEV raster channels (semantic map + agent history) while keeping downstream weights
npx skillsauth add wenmin-wu/ds-skills cv-bev-conv1-channel-expansionInstall 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.
Pretrained ImageNet backbones expect 3 RGB channels. Bird's-eye-view motion prediction rasters need many more: 3 for the semantic map plus (history_frames + 1) * 2 channels for stacked ego + agent masks at past timesteps — typically 10-30 channels. Instead of retraining from scratch, swap only the first conv to the new input width. Downstream layers (conv2, blocks, etc.) retain ImageNet pretraining and still converge fast. The new conv1 is randomly initialized, so give it a slightly higher learning rate during warmup.
import torch.nn as nn
from torchvision.models import resnet34
class BEVBackbone(nn.Module):
def __init__(self, history_num_frames, num_map_channels=3, pretrained=True):
super().__init__()
num_history_channels = (history_num_frames + 1) * 2
num_in_channels = num_map_channels + num_history_channels
self.backbone = resnet34(pretrained=pretrained)
old = self.backbone.conv1
self.backbone.conv1 = nn.Conv2d(
in_channels=num_in_channels,
out_channels=old.out_channels,
kernel_size=old.kernel_size,
stride=old.stride,
padding=old.padding,
bias=False,
)
# Optional: copy RGB weights onto the first 3 planes
if pretrained:
with torch.no_grad():
self.backbone.conv1.weight[:, :3] = old.weight
def forward(self, x):
return self.backbone(x)
num_in_channels = map_channels + (history_frames + 1) * 2conv1 with a new Conv2d matching the old kernel size/stride/padding but the new in_channelsbias=False (BN follows).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