Examples
Practical code examples demonstrating Tiny-DL-Inference capabilities.
Overview
This section contains complete, working examples that show how to use Tiny-DL-Inference for common tasks. Each example includes step-by-step explanations and can be run directly from the /examples directory in the repository.
Available Examples
MNIST Digit Recognition
A complete digit classification pipeline using a convolutional neural network. Learn how to:
- Initialize the inference engine
- Define and load a CNN model
- Prepare image input tensors
- Run inference and interpret predictions
- Clean up resources properly
Custom Model Loading
Build and load a custom model from scratch. Covers:
- Defining model architecture with layers
- Creating and assigning weight tensors
- Understanding layer connections and parameters
- Validating model structure
Web Integration
Integrate Tiny-DL-Inference into a web application. Demonstrates:
- HTML setup and file input handling
- Loading models via fetch API
- Processing images with canvas
- Displaying inference results with timing
- Error handling and status updates
Performance Benchmarking
Measure and compare operator performance. Shows how to:
- Benchmark individual operators
- Compare kernel fusion vs. separate execution
- Evaluate NCHW vs. NHWC memory layouts
- Calculate speedup and memory traffic reduction
Running Examples
Clone the repository and install dependencies:
git clone https://github.com/LessUp/tiny-dl-inference.git
cd tiny-dl-inference
npm install2
3
Run an example (requires WebGPU-enabled browser):
npx ts-node examples/mnist-demo.ts
npx ts-node examples/benchmark-demo.ts2
Note
These demos require a browser with WebGPU support, such as Chrome 113+ or Edge 113+.
Example Source Files
All examples are located in the /examples directory:
| File | Description |
|---|---|
mnist-demo.ts | MNIST digit classification with CNN |
benchmark-demo.ts | Kernel fusion and memory layout benchmarks |
Next Steps
- Read the Quick Start Guide for a basic introduction
- Explore the API Reference for detailed method documentation
- Learn about Memory Layout for performance optimization