Skip to content

Commit 94f963b

Browse files
authored
[onert] Add brief doc for training example Python script (#16335)
This commit adds documentation for train_step_with_dataset.py script. It shows how to prepare input and label files in the format expected by the script. ONE-DCO-1.0-Signed-off-by: Arkadiusz Bokowy <a.bokowy@samsung.com>
1 parent c643f66 commit 94f963b

File tree

5 files changed

+51
-3
lines changed

5 files changed

+51
-3
lines changed

runtime/onert/sample/minimal-python/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ It assumes model of float32 tensor type as an input.
88

99
## Usage
1010

11-
```
12-
$ python3 minimal.py path_to_nnpackage_directory
11+
```bash
12+
python3 minimal.py path_to_nnpackage_directory
1313
```

runtime/onert/sample/minimal-python/dynamic_shape_inference.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Demonstrates how to run inference on a model with dynamic input dimensions (`-1`) by supplying random concrete shapes on-the-fly.
44

55
## Purpose
6+
67
- Load an `.nnpackage` model
78
- Query the model’s input tensorinfo (which may include `-1` for dynamic dims)
89
- Perform 10 successive inference calls, each time replacing any `-1` dimension with a random integer in [1, 10]
@@ -20,5 +21,6 @@ Demonstrates how to run inference on a model with dynamic input dimensions (`-1`
2021
```bash
2122
python3 dynamic_shape_inference.py /path/to/your_model.nnpackage [backends]
2223
```
24+
2325
- `/path/to/your_model.nnpackage` — path to the NNFW package or model file
2426
- `backends` (optional) — backend string (e.g. "cpu", "gpu"); defaults to "cpu"
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# train_step_with_dataset.py - Single Step Training Example
2+
3+
## Purpose
4+
5+
- Load an `.nnpackage` model
6+
- Load training dataset from `.npy` file
7+
- Load corresponding labels from `.npy` file
8+
- Create optimizer (Stochastic Gradient Descent or Adam)
9+
- Create loss function (Mean Squared Error or Categorical Cross-Entropy)
10+
- Run `session.train_step(...)` and report progress
11+
12+
## Example Dataset Preparation
13+
14+
Input and output (label) shapes should match the model's expected input and
15+
output shapes. In this example, the model expects input shape `(1, 224, 224, 3)`
16+
and output shape `(1, 112, 112, 32)`. To prepare a sample dataset and labels,
17+
one can use the following code snippet to generate random data and save them as
18+
`.npy` files:
19+
20+
```python
21+
import numpy as np
22+
23+
# Create random dataset (64 samples of shape 224x224x3)
24+
data = np.random.rand(64, 224, 224, 3).astype(np.float32)
25+
np.save('dataset.npy', data)
26+
27+
# Create random labels (64 samples of shape 112x112x32)
28+
labels = np.random.rand(64, 112, 112, 32).astype(np.float32)
29+
np.save('labels.npy', labels)
30+
```
31+
32+
## Running the Example
33+
34+
To run the training step example with the prepared dataset and labels, use the
35+
following command:
36+
37+
```bash
38+
python train_step_with_dataset.py \
39+
--nnpkg=<ONE-ROOT>/nnpackage/examples/v1.3.0/two_tflites/mv1.0.tflite \
40+
--input=dataset.npy \
41+
--label=labels.npy \
42+
--data_length=64
43+
```

runtime/onert/sample/minimal-python/inference_benchmark.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ python inference_benchmark.py <nnpackage_path> [--backends BACKENDS] [--input-sh
2525
| `--repeat` | Number of timed inference repetitions (after 3 warm-up runs). Default: `5` |
2626

2727
## Example
28+
2829
```bash
2930
# Measure on CPU with default shapes, 5 repeats
3031
python inference_benchmark.py /path/to/model.nnpackage
@@ -51,7 +52,8 @@ Uses `psutil` to sample `RSS` before model load, after prepare, and after execut
5152

5253
4. Reporting
5354
Prints latency statistics and memory deltas:
54-
```
55+
56+
```text
5557
======= Inference Benchmark =======
5658
- Warmup runs : 3
5759
- Measured runs : 5

runtime/onert/sample/minimal-python/minimal.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ Demonstrates the simplest Python-API workflow to load an NNFW model, allocate in
1515
```bash
1616
python minimal.py /path/to/your_model.nnpackage [backends]
1717
```
18+
1819
- `/path/to/your_model.nnpackage` – path to your NNFW package or model file
1920
- `backends` (optional) – backend string (e.g. "cpu", "gpu"); defaults to "cpu"

0 commit comments

Comments
 (0)