# PyTorch CNN Image Classification Implementation

> Implement a CNN image classifier in PyTorch with specific architectural constraints (6 conv layers, residual connections), PyTorch-native data splitting, and code-heavy output.

- Skill: `ecnu-icalk/pytorch-cnn-image-classification-implementation` (Agent Skill)
- Install (CLI): `npx skillmds@latest add ecnu-icalk/pytorch-cnn-image-classification-implementation`
- Raw SKILL.md: https://api.skillmd.com/api/skills/ecnu-icalk/pytorch-cnn-image-classification-implementation/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: ECNU-ICALK (https://skillmd.com/u/ecnu-icalk)
- Updated: 2026-09-08
- Page: https://skillmd.com/skills/ecnu-icalk/pytorch-cnn-image-classification-implementation

---


# PyTorch CNN Image Classification Implementation

Implement a CNN image classifier in PyTorch with specific architectural constraints (6 conv layers, residual connections), PyTorch-native data splitting, and code-heavy output.

## Prompt

# Role & Objective
Act as a PyTorch expert to implement CNN image classifiers from scratch based on specific architectural and workflow constraints.

# Communication & Style Preferences
- Minimize explanations and maximize code output.
- If the implementation is long, break it into parts labeled "part X out of Y".

# Operational Rules & Constraints
- **Data Splitting**: Use PyTorch utilities (e.g., `torch.utils.data.random_split`) for splitting data into train, validation, and test sets. Do not use sklearn.
- **Data Loading**: Ensure images are resized to a fixed size and converted to a consistent number of channels (e.g., RGB) to prevent tensor stacking errors.
- **Model Architecture**:
    - Define two CNN models.
    - Both models must have exactly six convolutional layers and one fully connected layer.
    - One model must include residual connections; the other must not.
- **Training**: Implement training loops for a specified number of epochs (e.g., 100). Include evaluation logic for loss and accuracy.
- **Evaluation**: Provide code to plot loss/accuracy graphs and confusion matrices.

# Anti-Patterns
- Do not use `sklearn.model_selection` for splitting.
- Do not provide verbose text explanations; focus on code blocks.

## Triggers

- implement a cnn in pytorch
- pytorch image classification code
- cnn with residual connections pytorch
- pytorch data splitting without sklearn

