Dual-View Reshape Forward

SkillDev tools

Reshape dual-view stacked channels into doubled batch dimension for shared backbone, then concatenate with tabular features for classification

Available today. Use it from your connected AI after setup.

Connect ahel once, and every AI you use reads what you have installed.

Then ask your AI: use the Dual-View Reshape Forward skill

What this skill tells your AI

The instructions your AI receives, as published by wenmin-wu/ds-skills in skills/cv/dual-view-reshape-forward/SKILL.md and read by ahel’s review.

Overview

When two camera views (e.g., Endzone + Sideline) are stacked as channels in a single tensor, a shared backbone can process both views by reshaping: split channels in half, double the batch size, run the backbone once, then reshape back. This avoids duplicating the backbone while preserving view-specific features. Tabular features (tracking data, distances) are processed through a separate MLP and concatenated before the final classifier.

Quick Start

import torch
import torch.nn as nn
import timm

class DualViewModel(nn.Module):
    def __init__(self, model_name='tf_efficientnetv2_s', n_frames=13, n_features=18):
        super().__init__()
        self.backbone = timm.create_model(model_name, pretrained=True,
                                          num_classes=500, in_chans=n_frames)
        self.mlp = nn.Sequential(
            nn.Linear(n_features, 64), nn.LayerNorm(64),
            nn.ReLU(), nn.Dropout(0.2))
        self.fc = nn.Linear(500 * 2 + 64, 1)

    def forward(self, img, feature):
        b, c, h, w = img.shape
        img = img.reshape(b * 2, c // 2, h, w)   # split views
        img = self.backbone(img).reshape(b, -1)    # (B, 500*2)
        feature = self.mlp(feature)                # (B, 64)
        return self.fc(torch.cat([img, feature], dim=1))

pred = model(dual_view_tensor, tracking_features)

Workflow

  1. Stack temporal frames from two views as channels: (B, 2*N_frames, H, W)
  2. Reshape to (2*B, N_frames, H, W) — each view becomes a separate batch element
  3. Forward through shared backbone → (2*B, embed_dim)
  4. Reshape back to (B, 2*embed_dim) — concatenated view features
  5. Concatenate with MLP-processed tabular features and classify

Key Decisions

  • Shared vs separate backbones: shared halves parameters; separate allows view-specific learning
  • Channel split: assumes equal frames per view; pad if asymmetric
  • Tabular branch: LayerNorm + Dropout stabilizes the small MLP
  • vs late fusion: this mid-fusion approach lets the classifier see both view embeddings jointly

References

Signals

GitHub stars
60
Forks
4
Last commit
Apr 2026
Advanced
Catalog kind
skill
Gateway key
cv-dual-view-reshape-forward
Source
github.com/wenmin-wu/ds-skills