|
1 | 1 | --- |
2 | 2 | title: "Touchpad Digit Recognition Based on ESP-DL" |
3 | 3 | date: 2025-06-18 |
4 | | -showAuthor: false |
5 | 4 | summary: "This article demonstrates how to implement a touchpad-based digit recognition system using ESP-DL on ESP32 series chips. It covers the complete workflow from data collection and preprocessing to model training, quantization, and deployment, showcasing ESP-DL's capabilities in edge AI applications." |
6 | 5 | authors: |
7 | 6 | - yan-ke |
@@ -73,7 +72,7 @@ The Interpolated touch dataset contains ten categories from digit 0 to 9, with a |
73 | 72 |
|
74 | 73 | ### Dataset Preparation |
75 | 74 |
|
76 | | -Before model training, the interpolated touch data is preprocessed using the `torchvision.transforms` module from `PyTorch`. First, the images are converted to single-channel grayscale images, and random affine transformations (rotation of ±10 degrees, translation of ±10%) are applied to enhance data diversity. Subsequently, the images are converted to tensor format and normalized with a mean of 0.5 and standard deviation of 0.5. |
| 75 | +Before model training, the interpolated touch data is preprocessed using the `torchvision.transforms` module from `PyTorch`. First, the images are converted to single-channel grayscale images, and random affine transformations (rotation of ±10 degrees, translation of ±10%) are applied to enhance data diversity. Subsequently, the images are converted to tensor format and normalized with a mean of 0.5 and standard deviation of 0.5. |
77 | 76 |
|
78 | 77 | After data processing, the dataset is loaded using `ImageFolder`, a PyTorch utility that organizes images into labeled datasets based on folder names. It is then randomly split into training and test sets with an 8:2 ratio. |
79 | 78 |
|
@@ -173,13 +172,13 @@ def train_epoch(model, train_loader, criterion, optimizer, device): |
173 | 172 |
|
174 | 173 | for inputs, labels in train_loader: |
175 | 174 | inputs, labels = inputs.to(device), labels.to(device) |
176 | | - |
| 175 | + |
177 | 176 | optimizer.zero_grad() |
178 | 177 | outputs = model(inputs) |
179 | 178 | loss = criterion(outputs, labels) |
180 | 179 | loss.backward() |
181 | 180 | optimizer.step() |
182 | | - |
| 181 | + |
183 | 182 | running_loss += loss.item() |
184 | 183 | _, predicted = torch.max(outputs.data, 1) |
185 | 184 | total += labels.size(0) |
@@ -342,7 +341,7 @@ To avoid inconsistencies between the actual inference results and PC inference r |
342 | 341 |
|
343 | 342 | ```info |
344 | 343 | test outputs value: |
345 | | -%23, shape: [1, 10], exponents: [0], |
| 344 | +%23, shape: [1, 10], exponents: [0], |
346 | 345 | value: array([4.78089300e-25, 1.05306175e-20, 3.62514101e-34, 9.60267995e-24, |
347 | 346 | 9.60267995e-24, 6.47023468e-26, 3.97544995e-31, 1.15482239e-17, |
348 | 347 | 3.87399781e-21, 1.00000000e+00, 0.00000000e+00, 0.00000000e+00], |
@@ -390,7 +389,7 @@ void DataPreprocessor::process(const uint8_t* input_data, int8_t* quant_buffer) |
390 | 389 | } |
391 | 390 | ``` |
392 | 391 |
|
393 | | -After data preprocessing, the processed data needs to be fed into the model for inference. The entire inference process consists of three steps: |
| 392 | +After data preprocessing, the processed data needs to be fed into the model for inference. The entire inference process consists of three steps: |
394 | 393 |
|
395 | 394 | 1. Data Encapsulation. |
396 | 395 | 2. Model Execution. |
@@ -450,7 +449,7 @@ int DataPostprocessor::process() |
450 | 449 |
|
451 | 450 | ## Summary |
452 | 451 |
|
453 | | -This article introduces a handwritten digit recognition application implemented using the ESP-DL framework, demonstrating how to deploy deep learning models on ESP32 series chips. |
| 452 | +This article introduces a handwritten digit recognition application implemented using the ESP-DL framework, demonstrating how to deploy deep learning models on ESP32 series chips. |
454 | 453 |
|
455 | 454 | All the Python scripts for data processing, model training, quantization, as well as the C++ code for model inference and the pre-trained models mentioned in this article, are available in the esp-iot-solution GitHub repository: [touchpad_digit_recognition](https://github.com/espressif/esp-iot-solution/tree/master/examples/ai/esp_dl/touchpad_digit_recognition) |
456 | 455 |
|
|
0 commit comments