# The PyTorch to Core AI pipeline

- **Lesson ID:** 01
- **Goal:** Show the full path from training on Fashion-MNIST to a clothing label in SwiftUI, plus the two model files.
- **Human lesson:** [01-the-pipeline.html](01-the-pipeline.html)

## Prerequisites

- A Mac with Python, Xcode 27, and a target that can host a SwiftUI project.
- Basic Python, PyTorch, Swift, and Xcode navigation.

## Inputs, outputs, and artifacts

- **Inputs:** Fashion-MNIST; a Mac with Apple Silicon MPS or CPU; Xcode/Core AI SDK.
- **Outputs:** A tested clothing classifier path and a plan for the app.
- **Artifacts:** `clothing.pt` (PyTorch weights), `clothing.aimodel` (portable Core AI file), Xcode SwiftUI app.

## Agent build steps

1. Create a working directory and Python environment on the Mac.
2. Follow the fixed path: Fashion-MNIST → `ClothingCNN` → `clothing.pt` → `torch.export` → Core AI decompositions → `clothing.aimodel` → Core AI `NDArray` → SwiftUI label.
3. Keep training and app image prep the same: one grayscale channel, 28×28, float32 values in 0–1.
4. Load the model when the app starts, not when someone picks a photo. Measure timing on real hardware.
5. Use the lesson briefs in numeric order and save each file before you move on.

## Constraints

Mac MPS/CPU only; no CUDA. Use Core AI, not Core ML. The input is `[1,1,28,28]` float32 under `image`; output is `[1,10]` logits under `logits`. Keep the fixed Fashion-MNIST class order and prepare once.

## Key concepts

- The path is Fashion-MNIST to `ClothingCNN` to `clothing.pt` to export to `clothing.aimodel` to a SwiftUI label.
- This course uses Core AI, not Core ML.
- `clothing.pt` is PyTorch weights. `clothing.aimodel` is the portable file for Xcode.
- Train on a Mac with MPS or CPU. No CUDA.

## Takeaways

- You can name every step from training data to a label on screen.
- Keep `clothing.pt` for reload and export. Ship `clothing.aimodel` in the app.
- Prepare the model once at startup, not on every photo pick.

## Acceptance checks

- The agent can name both files and every step between them.
- The plan includes training, export/decomposition, conversion, Core AI NDArray inference, SwiftUI display, and profiling.
- [ ] Proceed to [lesson 02 brief](02-pytorch-from-scratch.llms.md).
