Skip to content
Back to skills

Cnn Transformer Multimodal Fusion

ASecurity

Process multiple sensor modalities through separate CNN branches then fuse via a transformer with CLS token for classification

  • 61 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added September 12, 2026
developmentpython

Security analysis

A100/100

Scanned September 12, 2026

npx -y skills add wenmin-wu/ds-skills --skill cnn-transformer-multimodal-fusion --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Cnn Transformer Multimodal Fusion?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Cnn Transformer Multimodal Fusion
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/wenmin-wu-cnn-transformer-multimodal-fusion/badge)](https://www.skillsdirectory.com/skills/wenmin-wu-cnn-transformer-multimodal-fusion)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: timeseries-cnn-transformer-multimodal-fusion
description: Process multiple sensor modalities through separate CNN branches then fuse via a transformer with CLS token for classification
domain: timeseries
---

# CNN-Transformer Multimodal Fusion

## Overview

For multi-sensor systems (IMU + thermal + depth), process each modality through its own CNN branch to extract temporal features, concatenate along the feature dimension, prepend a learnable CLS token, and feed into a transformer encoder. The CLS token output is used for classification.

## Quick Start

```python
import torch
import torch.nn as nn
from transformers import BertConfig, BertModel

class MultiModalFusion(nn.Module):
    def __init__(self, modality_dims, hidden_dim, n_classes, n_layers=4):
        super().__init__()
        self.branches = nn.ModuleList([
            nn.Sequential(
                nn.Conv1d(dim, hidden_dim, 7, padding=3),
                nn.BatchNorm1d(hidden_dim), nn.GELU(),
                nn.Conv1d(hidden_dim, hidden_dim, 5, stride=2, padding=2),
                nn.BatchNorm1d(hidden_dim), nn.GELU(),
            ) for dim in modality_dims
        ])
        self.cls_token = nn.Parameter(torch.randn(1, 1, hidden_dim * len(modality_dims)))
        config = BertConfig(hidden_size=hidden_dim * len(modality_dims),
                           num_hidden_layers=n_layers, num_attention_heads=8)
        self.transformer = BertModel(config)
        self.head = nn.Linear(config.hidden_size, n_classes)

    def forward(self, *modalities):
        feats = [branch(m.permute(0, 2, 1)) for branch, m in
                 zip(self.branches, modalities)]
        fused = torch.cat(feats, dim=1).permute(0, 2, 1)  # (B, T, C)
        cls = self.cls_token.expand(fused.size(0), -1, -1)
        x = torch.cat([cls, fused], dim=1)
        out = self.transformer(inputs_embeds=x).last_hidden_state[:, 0]
        return self.head(out)
```

## Key Decisions

- **Separate branches**: each modality has different sampling rates and feature spaces
- **CLS token**: aggregates sequence into a fixed-size vector for classification
- **Stride-2 conv**: reduces temporal resolution before transformer to manage memory

## References

- Source: [cmi-detect-behavior-with-sensor-data](https://www.kaggle.com/code/nina2025/cmi-detect-behavior-with-sensor-data)
- Competition: CMI - Detect Behavior with Sensor Data

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.