You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+57-8Lines changed: 57 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# MAX78000 Model Training and Synthesis
2
2
3
-
_July 14, 2021_
3
+
_July 16, 2021_
4
4
5
5
The Maxim Integrated AI project is comprised of five repositories:
6
6
@@ -1231,7 +1231,17 @@ For both approaches, the `quantize.py` software quantizes an existing PyTorch ch
1231
1231
1232
1232
#### Quantization-Aware Training (QAT)
1233
1233
1234
-
Quantization-aware training is the better performing approach. It is enabled by default. QAT learns additional parameters during training that help with quantization (see [Weights: Quantization-Aware Training (QAT)](#Weights: Quantization-Aware Training (QAT)). No additional arguments are needed for `quantize.py`.
1234
+
Quantization-aware training is the better performing approach. It is enabled by default. QAT learns additional parameters during training that help with quantization (see [Weights: Quantization-Aware Training (QAT)](#Weights: Quantization-Aware Training (QAT)). No additional arguments (other than input, output, and device) are needed for `quantize.py`.
1235
+
1236
+
The input checkpoint to `quantize.py` is either `qat_best.pth.tar`, the best QAT epoch’s checkpoint, or `qat_checkpoint.pth.tar`, the final QAT epoch’s checkpoint.
@@ -1241,6 +1251,17 @@ While several approaches for clipping are implemented in `quantize.py`, clipping
1241
1251
1242
1252
Note that the “optimum” scale factor for simple clipping is highly dependent on the model and weight data. For the MNIST example, a `--scale 0.85` works well. For the CIFAR-100 example on the other hand, Top-1 performance is 30 points better with `--scale 1.0`.
1243
1253
1254
+
The input checkpoint to `quantize.py`for post-training quantization is typically `best.pth.tar`, the best epoch’s checkpoint, or `checkpoint.pth.tar`, the final epoch’s checkpoint.
The `quantize.py` software has the following important command line arguments:
@@ -1259,7 +1280,7 @@ The `quantize.py` software has the following important command line arguments:
1259
1280
1260
1281
*Note: The syntax for the optional YAML file is described below. The same file can be used for both `quantize.py` and `ai8xize.py`.*
1261
1282
1262
-
`quantize.py` does not need access to the dataset.
1283
+
*Note:*`quantize.py` does <u>not</u> need access to the dataset.
1263
1284
1264
1285
#### Example and Evaluation
1265
1286
@@ -1295,18 +1316,47 @@ In all cases, ensure that the quantizer writes out a checkpoint file that the Ne
1295
1316
1296
1317
The following step is needed to add new network models:
1297
1318
1298
-
Implement a new network model based on the constraints described earlier, see [Custom nn.Modules](#custom-nnmodules) (and `models/ai85net.py` for an example).
1319
+
Implement a new network model based on the constraints described earlier, see [Custom nn.Modules](#custom-nnmodules) (and `models/ai85net.py` for an example).
1320
+
1321
+
***Note:****When re-using existing models, please note that some of the example models are designed to be used with [Neural Architecture Search (NAS)](#Neural Architecture Search (NAS)). These models will typically not perform well, or not fit into hardware without the NAS steps. These models have “nas” as part of their name.*
1322
+
1323
+
##### Model Instantiation and Initialization
1324
+
1325
+
To support *evaluation* of the quantized model using PyTorch, the model must be instantiated and initialized using all parameters supplied by `train.py`, and the parameters must be passed to the individual *nn.Modules*.
Note the `__init(...)__`functionsignature, the extra arguments to `ai8x.FusedConv2dReLU(...)` and the `NewModel(**kwargs)` instantiation.
1299
1345
1300
1346
##### `models` Data Structure
1301
1347
1302
1348
The file must include the `models` data structure that describes the model. `models` can list multiple models in the same file.
1303
1349
1304
1350
For each model, three fields are required in the data structure:
1305
1351
1306
-
* The `name` field assigns a name to the model for discovery by `train.py`, for example “`resnet5`”.
1352
+
* The `name` field assigns a name to the model for discovery by `train.py`, for example “`resnet5`”.*Note: The `name` must be unique.*
1307
1353
* 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`)*.
1308
1354
* The `dim` field is either `1` (the model handles 1D inputs) or `2` (the model handles 2D inputs).
1309
1355
1356
+
##### Model File Location
1357
+
1358
+
Place the new model file (with its unique model name as specified by `name`in the data structure described above) into the `models` folder. `train.py` will now be able to discover and use the new model by specifying `--model modelname`.
1359
+
1310
1360
#### Data Loader
1311
1361
1312
1362
The following steps are needed for new data formats and datasets:
@@ -1333,10 +1383,9 @@ On the other hand, a different sensor may produce unsigned data values in the fu
1333
1383
1334
1384
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.
1335
1385
1336
-
* 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)`.
1337
-
1386
+
* The `name` field assigns a name to the dataset for discovery by `train.py`, for example “`MNIST`”. *Note: The `name` must be unique.*
1387
+
* 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)`. One-dimensional input uses a single “dimension”, for example `'input': (2, 512)` will be passed to the model as `num_channels=2` and `dimensions=(512, )`.
1338
1388
* The optional `regression` field in the structure can be set to `True` to automatically selectthe`--regression`command line argument. `regression` defaults to `False`.
1339
-
1340
1389
* The optional `visualize` field can point to a custom visualization functionused 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 functionmust be supplied.
0 commit comments