DESCRIPTION
NNCASE model compiler and inference tool.
SYNOPSIS
ncc compile <input file> <output file> -i <input format> [-o <output
format>] [-t <target>] [--dataset <dataset path>] [--dataset-format
<dataset format>] [--inference-type <inference type>] [--input-mean
<input mean>] [--input-std <input std>] [--dump-ir] [--input-type <input
type>] [--max-allocator-solve-secs <max allocator solve secs>]
[--calibrate-method <calibrate method>] [-v]
ncc infer <input file> <output path> --dataset <dataset path>
[--dataset-format <dataset format>] [--input-mean <input mean>]
[--input-std <input std>] [-v]
OPTIONS
ncc compile <input file> <output file> -i <input format> [-o <output
format>] [-t <target>] [--dataset <dataset path>] [--dataset-format
<dataset format>] [--inference-type <inference type>] [--input-mean
<input mean>] [--input-std <input std>] [--dump-ir]
[--dump-weights-range] [--input-type <input type>]
[--max-allocator-solve-secs <max allocator solve secs>]
[--calibrate-method <calibrate method>] [--weights-quantize-threshold
<weights quantize threshold>] [--no-quantized-binary] [-v]
ncc infer <input file> <output path> --dataset <dataset path>
[--dataset-format <dataset format>] [--input-mean <input mean>]
[--input-std <input std>] [-v]
ncc -h [-v]
OPTIONS
compile
<input file> input file
<output file> output file
-i, --input-format input file format: e.g. tflite, caffe, onnx
-o, --output-format output file format: e.g. kmodel, default is kmodel
-t, --target target arch: e.g. cpu, k210, default is k210
--dataset calibration dataset, used in post quantization
--dataset-format datset format: e.g. image, raw default is image
--inference-type inference type: e.g. float, uint8 default is uint8
--input-mean input mean, default is 0.000000
--input-std input std, default is 1.000000
--dump-ir dump nncase ir to .dot files
--dump-weights-range
dump weights range
--input-type input type: e.g. default, float, uint8, default
means equal to inference type
--max-allocator-solve-secs
max optimal layout solve time in secs used by
allocators, 0 means don't use solver, default is 60
--calibrate-method calibrate method: e.g. no_clip, l2, default is
no_clip
--weights-quantize-threshold
the threshold to control quantizing op or not
according to it's weigths range, default is
32.000000
--output-quantize-threshold
the threshold to control quantizing op or not
according to it's output size, default is 1024
--no-quantized-binary
don't quantize binary ops
infer
<input file> input kmodel
<output path> inference result output directory
--dataset input dataset to inference
--dataset-format datset format: e.g. image, raw default is image
--input-mean input mean, default is 0.000000
--input-std input std, default is 1.000000
-h, --help show help
-v, --version show version
ncc is the nncase command line tool. It has two commands: compile and infer.
compile command compile your trained models (.tflite, .caffemodel, .onnx) to .kmodel.
<input file>is your input model path.<output file>is the output model path.-i, --input-formatoption is used to specify the input model format. nncase supportstflite,caffeandonnxinput model currently.-o, --output-formatoption is used to sepecify the output model format. You have only one choice:kmodelcurrently.-t, --targetoption is used to set your desired target device to run the model.cpuis the most general target that almost every platform should support.k210is the Kendryte K210 SoC platform. If you set this option tok210, this model can only run on K210 or be emulated on your PC.--inference-typeSet tofloatif you want precision, but you need more memory and lost K210 KPU acceleration. Set touint8if you want KPU acceleration and fast speed and you need to provide a quantization calibration dataset to quantize your models later.--datasetis to provide your quantization calibration dataset to quantize your models. You should put hundreds or thousands of data in training set to this directory. You only need this option when you set--inference-typetouint8.--dataset-formatis to set the format of the calibration dataset. Default isimage, nncase will useopencvto read your images and autoscale to the desired input size of your model. If the input has 3 channels, ncc will convert images to RGB float tensors [0,1] inNCHWlayout. If the input has only 1 channel, ncc will grayscale your images. Set torawif your dataset is not image dataset for example, audio or matrices. In this scenario you should convert your dataset to raw binaries which contains float tensors. You only need this option when you set--inference-typetouint8.--input-stdand--input-meanis to set the preprocess method on your calibration dataset. As said above, ncc will firstly convert images to RGB float tensors [0,1] inNCHWlayout, then ncc will normalize your images usingy = (x - mean) / stdformula. There is an arguments table for reference.
| Input range | --input-std | --input-mean |
|---|---|---|
| [0,1] (default) | 1 | 0 |
| [-1,1] | 0.5 | 0.5 |
| [0,255] | 0.0039216 | 0 |
--calibrate-methodis to set your desired calibration method, which is used to select the optimal activation ranges. The default isno_clipin that ncc will use the full range of activations. If you want a better quantization result, you can usel2but it will take a longer time to find the optimal ranges.--input-typeis to set your desired input data type when do inference. Default is equal to inference type. If--input-typeisuint8, for example you should provide RGB888 uint8 tensors when you do inference. If--input-typeisfloat, you shold provide RGB float tensors instead.--max-allocator-solve-secsis to limit the maximum solving time when do the best fit allocation search. If the search time exceeded, ncc will fallback to use the first fit method. Default is 60 secs, set to 0 to disable search.--weights-quantize-thresholdcontrols the threshold whether or not to quantize conv2d and matmul's weights. If the range of weights is larger than the threshold, nncase will not quantize it.--output-quantize-thresholdcontrols the threshold whether or not to quantize conv2d and matmul's weights. If the elements count of output is smaller than the threshold, nncase will not quantize it.--no-quantized-binarydisable quantized binary ops, nncase will always use float binary ops.--dump-iris a debug option. When it's on, ncc will produce some.dotgraph files to the working directory. You can useGraphvizor Graphviz Online to view these files.--dump-weights-rangeis a debug option. When it's on, ncc will print ranges of conv2d' weights.
infer command can run your kmodel, and it's often used as debug purpose. ncc will save the model's output tensors to .bin files in NCHW layout.
<input file>is your kmodel path.<output path>is the output directory ncc will produce to.--datasetis the test set directory.--dataset-format,--input-stdand--input-meanhas the same meaning as incompilecommand.