Skip to content

Commit 8317d41

Browse files
author
Robert Muchsel
authored
README: Describe 'models' data structure, clarify pyenv installation (#140)
1 parent 058be8c commit 8317d41

File tree

2 files changed

+38
-16
lines changed

2 files changed

+38
-16
lines changed

README.md

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

3-
_June 16, 2021_
3+
_June 21, 2021_
44

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

@@ -152,14 +152,20 @@ On Linux:
152152
$ curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash # NOTE: Verify contents of the script before running it!!
153153
```
154154

155-
Then, add to either `~/.bash_profile`, `~/.bashrc`, or `~/.profile` (as shown by the terminal output of the previous step):
156-
155+
Then, follow the terminal output of the pyenv-installer and add pyenv to your shell by modifying one or more of `~/.bash_profile`, `~/.bashrc`, `~/.zshrc`, `~/.profile`, or `~/.zprofile`. The instructions differ depending on the shell (bash or zsh). To display the instructions again at any later time:
157156
```shell
158-
eval "$(pyenv init -)"
159-
eval "$(pyenv virtualenv-init -)"
160-
```
157+
$ pyenv init
161158

162-
If you use zsh as the shell (default on macOS), add these same commands to `~/.zprofile` or `~/.zshrc` in addition to adding them to the bash startup scripts.
159+
# (The below instructions are intended for common
160+
# shell setups. See the README for more guidance
161+
# if they don't apply and/or don't work for you.)
162+
163+
# Add pyenv executable to PATH and
164+
# enable shims by adding the following
165+
# to ~/.profile and ~/.zprofile:
166+
...
167+
...
168+
```
163169

164170
Next, close the Terminal, open a new Terminal and install Python 3.8.10.
165171

@@ -677,7 +683,7 @@ Example:
677683

678684
#### CHW (Channels-Height-Width)
679685

680-
The input layer can alternatively also use the CHW format (a sequence of channels). The highest frequency in this data format is the width or X-axis (W), and the lowest frequency is the channel. Assuming an RGB input, all red pixels are followed by all green pixels, followed by all blue pixels.
686+
The input layer (and *only* the input layer) can alternatively also use the CHW format (a sequence of channels). The highest frequency in this data format is the width or X-axis (W), and the lowest frequency is the channel. Assuming an RGB input, all red pixels are followed by all green pixels, followed by all blue pixels.
681687

682688
Example:
683689

@@ -687,9 +693,11 @@ Example:
687693

688694
#### Considerations for Choosing an Input Format
689695

690-
The accelerator supports both HWC and CHW input formats to avoid unnecessary data manipulation. Internal layers always use the HWC format.
696+
The accelerator supports both HWC and CHW input formats to avoid unnecessary data manipulation. Choose the format that results in the least amount of data movement for a given input.
691697

692-
In general, HWC is faster since each memory read can deliver data to up to four processors in parallel. On the other hand, four processors must share one data memory instance, which reduces the maximum allowable dimensions.
698+
Internal layers and the output layer always use the HWC format.
699+
700+
In general, HWC is faster since each memory read can deliver data to up to four processors in parallel. On the other hand, four processors must share one data memory instance, which reduces the maximum allowable dimensions of the input layer.
693701

694702
#### CHW Input Data Format and Consequences for Weight Memory Layout
695703

@@ -1128,6 +1136,8 @@ The `quantize.py` software has the following important command line arguments:
11281136

11291137
*Note: The syntax for the optional YAML file is described below. The same file can be used for both `quantize.py` and `ai8xize.py`.*
11301138

1139+
`quantize.py` does not need access to the dataset.
1140+
11311141
#### Example and Evaluation
11321142

11331143
Copy the working and tested weight files into the `trained/` folder of the `ai8x-synthesis` project.
@@ -1158,14 +1168,26 @@ In all cases, ensure that the quantizer writes out a checkpoint file that the Ne
11581168

11591169
### Adding New Network Models and New Datasets to the Training Process
11601170

1171+
#### Model
1172+
11611173
The following step is needed to add new network models:
11621174

1163-
* Implement a new network model based on the constraints described earlier, see [Custom nn.Modules](#custom-nnmodules) (and `models/ai85net.py` for an example). The file must include the `models` data structure that describes the model (name, minimum number of inputs, and whether it can handle 1D or 2D inputs). `models` can list multiple models in the same file.
1175+
Implement a new network model based on the constraints described earlier, see [Custom nn.Modules](#custom-nnmodules) (and `models/ai85net.py` for an example).
11641176

1165-
The following steps are needed for new data formats and datasets:
1177+
##### `models` Data Structure
1178+
1179+
The file must include the `models` data structure that describes the model. `models` can list multiple models in the same file.
1180+
1181+
For each model, three fields are required in the data structure:
1182+
1183+
* The `name` field assigns a name to the model for discovery by `train.py`, for example “`resnet5`”.
1184+
* The `min_input` field describes the minimum width for 2D models, it is typically `1` *(when the input `W` dimension is smaller than `min_input`, it is padded to `min_input`)*.
1185+
* The `dim` field is either `1` (the model handles 1D inputs) or `2` (the model handles 2D inputs).
11661186

11671187
#### Data Loader
11681188

1189+
The following steps are needed for new data formats and datasets:
1190+
11691191
Develop a data loader in PyTorch, see https://pytorch.org/tutorials/beginner/data_loading_tutorial.html. See `datasets/mnist.py` for an example.
11701192

11711193
The data loader must include a loader function, for example `mnist_get_datasets(data, load_train=True, load_test=True)`. `data` is a tuple of the specified data directory and the program arguments, and the two *bools* specify whether training and/or test data should be loaded.
@@ -1184,15 +1206,15 @@ In many cases, image data is delivered as fewer than 8 bits per channel (for exa
11841206

11851207
On the other hand, a different sensor may produce unsigned data values in the full 8-bit range $[0, 255]$. This range must be mapped to $[–128, +127]$ to match hardware and the trained model. The mapping can be performed during inference by subtracting 128 from each input byte, but this requires extra processing time during inference.
11861208

1187-
#### `datasets` Data Structure
1209+
##### `datasets` Data Structure
11881210

11891211
Add the new data loader to a new file in the `datasets` directory (for example `datasets/mnist.py`). The file must include the `datasets` data structure that describes the dataset and points to the new loader. `datasets` can list multiple datasets in the same file.
11901212

1191-
The `input` key describes the dimensionality of the data, and the first dimension is passed as `num_channels` to the model, whereas the remaining dimensions are passed as `dimension`. For example, `'input': (1, 28, 28)` will be passed to the model as `num_channels=1` and `dimensions=(28,28)`.
1213+
* The `input` field describes the dimensionality of the data, and the first dimension is passed as `num_channels` to the model, whereas the remaining dimensions are passed as `dimension`. For example, `'input': (1, 28, 28)` will be passed to the model as `num_channels=1` and `dimensions=(28,28)`.
11921214

1193-
The optional `regression` key in the structure can be set to `True` to automatically select the `--regression` command line argument. `regression` defaults to `False`.
1215+
* The optional `regression` field in the structure can be set to `True` to automatically select the `--regression` command line argument. `regression` defaults to `False`.
11941216

1195-
The optional `visualize` key can point to a custom visualization function used when creating `--embedding`. The input to the function (format NCHW for 2D data, or NCL for 1D data) is a batch of data (with N ≤ 100). The default handles square RGB or monochrome images. For any other data, a custom function must be supplied.
1217+
* The optional `visualize` field can point to a custom visualization function used when creating `--embedding`. The input to the function (format NCHW for 2D data, or NCL for 1D data) is a batch of data (with N ≤ 100). The default handles square RGB or monochrome images. For any other data, a custom function must be supplied.
11961218

11971219
#### Training and Verification Data
11981220

README.pdf

3.34 KB
Binary file not shown.

0 commit comments

Comments
 (0)