Train a receipt-image classifier, then check identity splits, tensor contracts, validation arithmetic, recovery and serving behavior.
Project: classify receipt image quality with a checked training contract
Define the task
Choose labels such as readable, blurred and cut-off. Record how annotators handle a photo with more than one defect: use a priority rule or a multi-label target with a matching loss. For single-label training, pin class order and image input format. Split original receipt identities before augmentation. Tensor checks] and split checks] must run.
Train against a baseline
Start with class prevalence and a simple image model. Show a tiny-batch overfit check, then train under a fixed optimizer and epoch budget. Log examples seen, loss, invalid gradients and validation counts. Use raw logits for cross-entropy and the correct evaluation mode. The loss contract] and weighted validation] are review criteria.
Exercise recovery and serving
Interrupt training after a checkpoint and resume with the same class mapping and input manifest. Compare one fixed-batch update. Publish an inference manifest with preprocessing and maximum request size. Reject a corrupt image and oversized request; measure loaded high-percentile latency at a stated concurrency. Serving] must match the selected checkpoint.
Report failure slices
Show a confusion table and error examples for dim light, angled photos and duplicate captures. State the count per slice; do not give percentages without denominators. Compare the selected model with the baseline on an untouched test partition once. Submit code, run manifest, sample IDs and failure-case outputs so another engineer can reproduce the decision.
Implementation
def check_image_project(train_ids, validation_ids, test_ids, class_names):
partitions = [set(train_ids), set(validation_ids), set(test_ids)]
if any(not group for group in partitions):
raise ValueError("empty image partition")
if any(partitions[left] & partitions[right]
for left, right in ((0, 1), (0, 2), (1, 2))):
raise ValueError("identity leaked across partitions")
if len(class_names) != len(set(class_names)):
raise ValueError("duplicate class label")Performance and operating cost
Each training epoch reads O(N) images; decoding and augmentation may dominate loader CPU. Include peak device memory, total training time and loaded inference tail latency in the project report.
Common Mistakes
- Do not split variants independently of original receipts.
- Do not promote a checkpoint without preprocessing metadata.
- Do not hide tiny failure slices behind overall accuracy.
