Skip to content

Commit 3d03a66

Browse files
author
Robert Muchsel
authored
Check that sample input is int64; add conversion script (#151)
1 parent ff43689 commit 3d03a66

File tree

5 files changed

+34
-4
lines changed

5 files changed

+34
-4
lines changed

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# MAX78000 Model Training and Synthesis
22

3-
_July 16, 2021_
3+
_July 19, 2021_
44

55
The Maxim Integrated AI project is comprised of five repositories:
66

@@ -2131,9 +2131,13 @@ Adding new datasets to the Network Loader is implemented as follows:
21312131
fc.linear.bias
21322132
```
21332133
2134-
3. Provide a sample input. The sample input is used to generate a known-answer test (self test). The sample input is provided as a NumPy “pickle” — add `sample_dset.npy` for the dataset named `dset` to the `tests` directory. This file can be generated by saving a sample in CHW format (no batch dimension) using `numpy.save()`, see below.
2134+
3. Provide a sample input. The sample input is used to generate a known-answer test (self test) against the predicted label. The purpose of the sample input is to ensure that the generated code matches the model — it does <u>*not*</u> ensure that the model is of good quality. However, it can help finding issues in the YAML description of the model.
21352135
2136-
For example, the MNIST 1×28×28 image sample would be stored in `tests/sample_mnist.npy` in an `np.array` with shape `[1, 28, 28]` and datatype `<i8`. The file can be random, or can be obtained from the `train.py` software.
2136+
The sample input is provided as a NumPy “pickle” — add `sample_dset.npy` for the dataset named `dset` to the `tests` directory. This file can be generated by saving a sample in CHW format (no batch dimension) using `numpy.save()`, see below.
2137+
2138+
For example, the MNIST 1×28×28 image sample would be stored in `tests/sample_mnist.npy` in an `np.array` with shape `[1, 28, 28]` and datatype `>i8` (`np.int64`). The file can contain random integers, or it can be obtained from the `train.py` software.
2139+
2140+
*Note: To convert an existing sample input file to `np.int64`, use the `tests/convert_sample.py` script.*
21372141
21382142
#### Generating a Random Sample Input
21392143
@@ -2147,7 +2151,8 @@ a = np.random.randint(-128, 127, size=(1, 28, 28), dtype=np.int64)
21472151
np.save(os.path.join('tests', 'sample_mnist'), a, allow_pickle=False, fix_imports=False)
21482152
```
21492153
2150-
For RGB image inputs, there are three channels. For example, a 3×80×60 (C×H×W) input is created using `size=(3, 80, 60)`.
2154+
For RGB image inputs, there are three channels. For example, a 3×80×60 (C×H×W) input is created using `size=(3, 80, 60)`.
2155+
**Note:** The array must be of data type `np.int64`.
21512156
21522157
#### Saving a Sample Input from Training Data
21532158

README.pdf

-12.4 KB
Binary file not shown.

izer/sampledata.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ def get(
2828
# allow_pickle=False, fix_imports=False)
2929

3030
data = np.load(filename)
31+
if data.dtype.type is not np.dtype('int64').type:
32+
eprint(f'The sample data array in {filename} is of type {data.dtype}, rather than '
33+
'int64!')
34+
3135
if synthesize_input is not None:
3236
# Every 8 (or synthesize_words) words, add data to the
3337
# combined 32-bit word for up to 4 channels

tests/convert_sample.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env python3
2+
###################################################################################################
3+
# Copyright (C) Maxim Integrated Products, Inc. All Rights Reserved.
4+
#
5+
# Maxim Integrated Products, Inc. Default Copyright Notice:
6+
# https://www.maximintegrated.com/en/aboutus/legal/copyrights.html
7+
###################################################################################################
8+
"""
9+
Convert sample input data to int64.
10+
"""
11+
import argparse
12+
13+
import numpy as np
14+
15+
parser = argparse.ArgumentParser(description='Convert sample input to int64')
16+
parser.add_argument('input', help='path to the input sample data')
17+
parser.add_argument('output', help='path to the output file (converted data)')
18+
args = parser.parse_args()
19+
20+
d = np.int64(np.load(args.input))
21+
np.save(args.output, d, allow_pickle=False, fix_imports=False)

tests/sample_test_tfrock-bias.npy

48 KB
Binary file not shown.

0 commit comments

Comments
 (0)