책 『밑바닥부터 만드는 추론 엔진: Rust로 배우는 AI 인퍼런스 엔지니어링』
(Building an Inference Engine from Scratch) 26장에서 쓰는 손글씨 숫자 분류
모델 둘입니다. .tflite 파일이고, 책의 그래프 해석기가 처음으로 읽는
파일입니다.
Two tiny MNIST classifiers in the .tflite format, used in chapter 26 of the
book. They are the first files read by the graph interpreter of the book's
inference engine, badak.
mlp.tflite |
residual.tflite |
|
|---|---|---|
| 구조 / Architecture | 784 → 128 → 10, ReLU | 784 → 256, 잔차 블록 3개(256 → 512 → 256), 256 → 10 |
| 파라미터 / Parameters | 101,770 | 992,266 |
| 연산 / Operators | FULLY_CONNECTED × 2, SOFTMAX |
FULLY_CONNECTED × 8, ADD × 3, SOFTMAX |
| 시험 정확도 / Test accuracy | 97.64% (9,764 / 10,000) | 97.73% (9,773 / 10,000) |
두 모델 모두 입력은 0과 1 사이의 픽셀 값 (1, 784)이고, 출력은 숫자 0~9의
확률 (1, 10)입니다. 정규화 (x − 0.1307) / 0.3081은 그래프 안에 들어
있습니다(변환기가 첫 층의 가중치에 접어 넣었습니다).
Both take pixel values in [0, 1] with shape (1, 784) and return ten
probabilities. The normalization is part of the graph.
mlp.tflite의 가중치는
mnist-mlp와
같습니다.
| 파일 | 내용 |
|---|---|
mlp.tflite |
7장의 모델을 그래프로 옮긴 것 |
residual.tflite |
잔차 연결이 있는 모델 |
reference.safetensors |
LiteRT가 계산한 정답. 모델마다 앞의 16장에 대한 확률(mlp.probabilities, residual.probabilities)과 시험 데이터 전체의 예측(mlp.predictions, residual.predictions) |
저장소의 reference/ch26_make_tflite.py로 만들었습니다. PyTorch 2.14.1,
litert-torch 0.10.0, ai-edge-litert 2.3.0. 잔차 모델은 난수 씨앗 0,
Adam(학습률 0.001), 배치 64, 4 에폭, CPU로 학습했습니다.
sh scripts/download_mnist.sh
sh scripts/download_ch07.sh
pip install -r reference/requirements_ch26.txt
python reference/ch26_make_tflite.py
같은 스크립트를 실행해도 기계와 도구의 버전에 따라 파일이 조금 다를 수 있습니다. 책의 숫자를 그대로 재현하려면 이 저장소의 파일을 쓰십시오.
학습 재료를 보여 주기 위한 작은 모델입니다. MNIST와 같은 방식으로 가운데 정렬된 흰 숫자, 검은 배경의 28 × 28 그림에서만 잘 동작합니다.