# Agent brief: Kotlin clothing classifier UI

- **Lesson id:** 05
- **Goal:** Prepare a Bitmap the same way Python does, run LiteRT buffers, and show the top label and confidence.
- **Prerequisites:** Lesson 04 app and model, [human lesson](05-kotlin-clothing-ui.html).
- **Inputs:** A Bitmap and a reusable `ClothingClassifier`.
- **Outputs/artifacts:** Kotlin classifier wrapper, grayscale NCHW float array, softmax result, Compose UI.

## Steps

1. Keep the fixed ten-label list and one `CompiledModel` with buffers you create once.
2. Resize or draw to 28×28, compute grayscale luminance, divide by 255, and write row-major values into `[1,1,28,28]`.
3. Call `inputs.get(0).writeFloat(input)`, `run`, and `outputs.get(0).readFloat()`.
4. Check that you have ten finite logits. Apply softmax for the displayed confidence and map argmax to labels.
5. Call this from a simple Compose screen. In a finished app, run inference off the main thread.

## Constraints

Do not feed 0–255 bytes, switch to NHWC, or treat logits as probabilities. Link the [human lesson](05-kotlin-clothing-ui.html).

## Key concepts

- `ClothingClassifier` wraps one `CompiledModel` and buffers created once.
- Resize to 28x28, compute grayscale, scale to 0-1, write row-major into the NCHW channel.
- Write input floats, call `compiledModel.run`, then read ten output floats.
- Softmax is for displayed confidence only. Labels stay in the fixed Python order.

## Takeaways

- Do not feed 0-255 bytes. Do not treat logits as probabilities. Do not switch to NHWC.
- In a finished app, run inference off the main thread.
- Phone photos may need crop or contrast. The tensor contract stays 28x28, one channel, float32 0-1.

## Acceptance checks

The bundled sample produces a label and confidence. The model and buffers are reused across taps.
