Conv1d lstm stroke classifier

From wenmin-wu/ds-skills · View interactive version

Conv1d lstm stroke classifier is an AI agent skill from the GitHub repository wenmin-wu/ds-skills. Stack 1D convolutions for local feature extraction before bidirectional LSTMs to classify variable-length stroke sequences into hundreds of doodle categories

How to use this skill

Skill file

Conv1D-LSTM Stroke Classifier

Overview

Sketches can be represented as sequences of (x, y, stroke_id) points rather than rasterized images. A Conv1D-LSTM architecture processes this raw sequence: 1D convolutions extract local patterns (corners, curves), then LSTMs capture long-range stroke order dependencies. This approach works directly on stroke coordinates without rendering, preserving resolution-independent information.

Quick Start

from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import (Conv1D, LSTM, Dense,
    Dropout, BatchNormalization)

n_classes = 340
max_points = 128

model = Sequential([
    BatchNormalization(input_shape=(max_points, 3)),
    Conv1D(48, 5, activation="relu"),
    Dropout(0.3),
    Conv1D(64, 5, activation="relu"),
    Dropout(0.3),
    Conv1D(96, 3, activation="relu"),
    Dropout(0.3),
    LSTM(128, return_sequences=True),
    Dropout(0.3),
    LSTM(128, return_sequences=False),
    Dropout(0.3),
    Dense(512, activation="relu"),
    Dropout(0.3),
    Dense(n_classes, activation="softmax"),
])
model.compile(optimizer="adam", loss="categorical_crossentropy",
              metrics=["accuracy"])

Workflow

  1. Parse strokes into Nx3 matrix: (x, y, stroke_flag) where flag marks stroke boundaries
  2. Pad or truncate to fixed length (128-256 points)
  3. Normalize x, y coordinates to [0, 1]
  4. Feed through Conv1D layers (increasing filters: 48→64→96) for local pattern extraction
  5. Feed through stacked LSTMs for sequential modeling
  6. Dense layers → softmax over N classes

Key Decisions

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.