Skip to content

Commit

Permalink
Add Arm NN support
Browse files Browse the repository at this point in the history
  • Loading branch information
iwatake2222 committed Jul 23, 2021
1 parent e55bb21 commit c556e73
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 63 deletions.
114 changes: 69 additions & 45 deletions 00_doc/class_diagram.drawio

Large diffs are not rendered by default.

Binary file modified 00_doc/class_diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions NOTICE.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ This project utilizes the following OSS (Open Source Software):
- https://developer.qualcomm.com/software/qualcomm-neural-processing-sdk
- Copyright (c) 2017-2020 Qualcomm Technologies, Inc.

- Arm NN
- https://github.com/Arm-software/armnn
- Copyright (c) 2017 ARM Limited.

--------------------------------------------------------------------
Terms of the Apache License, Version 2.0:

Expand Down Expand Up @@ -270,3 +274,28 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


--------------------------------------------------------------------
MIT License

Copyright (c) 2017 ARM Limited.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

27 changes: 16 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- ncnn
- MNN
- SNPE (Snapdragon Neural Processing Engine SDK (Qualcomm Neural Processing SDK for AI v1.51.0))
- Arm NN

## Supported targets
- Windows 10 (Visual Studio 2017 x64, Visual Studio 2019 x64)
Expand All @@ -31,6 +32,7 @@
| ncnn | OK | OK | OK | OK | OK |
| MNN | OK | OK | OK | OK | OK |
| SNPE | not supported | not supported | not tested | OK | OK |
| Arm NN | not supported | OK | not supported | OK | not supported |
| Note | Visual Studio 2017, 2019 | Xubuntu 18.04 | Raspberry Pi | Jetson Xavier NX | Pixel 4a |


Expand All @@ -42,7 +44,6 @@ https://github.com/iwatake2222/InferenceHelper_Sample
- https://github.com/iwatake2222/play_with_tensorrt
- https://github.com/iwatake2222/play_with_ncnn
- https://github.com/iwatake2222/play_with_mnn
- https://github.com/iwatake2222/play_with_snpe

# Usage
## Installation
Expand Down Expand Up @@ -103,6 +104,8 @@ https://github.com/iwatake2222/InferenceHelper_Sample
cmake .. -DINFERENCE_HELPER_ENABLE_MNN=on
# SNPE
cmake .. -DINFERENCE_HELPER_ENABLE_SNPE=on
# Arm NN
cmake .. -DINFERENCE_HELPER_ENABLE_ARMNN=on
```
- Enable/Disable preprocess using OpenCV:
Expand All @@ -127,6 +130,7 @@ typedef enum {
kNcnn,
kMnn,
kSnpe,
kArmnn,
} HelperType;
```

Expand Down Expand Up @@ -175,15 +179,15 @@ InputTensorInfo input_tensor_info("input", TensorInfo::TENSOR_TYPE_FP32);
input_tensor_info.tensor_dims = { 1, 224, 224, 3 };
input_tensor_info.data_type = InputTensorInfo::kDataTypeImage;
input_tensor_info.data = img_src.data;
input_tensor_info.imageInfo.width = img_src.cols;
input_tensor_info.imageInfo.height = img_src.rows;
input_tensor_info.imageInfo.channel = img_src.channels();
input_tensor_info.imageInfo.cropX = 0;
input_tensor_info.imageInfo.cropY = 0;
input_tensor_info.imageInfo.cropWidth = img_src.cols;
input_tensor_info.imageInfo.cropHeight = img_src.rows;
input_tensor_info.imageInfo.isBGR = false;
input_tensor_info.imageInfo.swapColor = false;
input_tensor_info.image_info.width = img_src.cols;
input_tensor_info.image_info.height = img_src.rows;
input_tensor_info.image_info.channel = img_src.channels();
input_tensor_info.image_info.crop_x = 0;
input_tensor_info.image_info.crop_y = 0;
input_tensor_info.image_info.crop_width = img_src.cols;
input_tensor_info.image_info.crop_height = img_src.rows;
input_tensor_info.image_info.is_bgr = false;
input_tensor_info.image_info.swap_color = false;
input_tensor_info.normalize.mean[0] = 0.485f; /* https://github.com/onnx/models/tree/master/vision/classification/mobilenet#preprocessing */
input_tensor_info.normalize.mean[1] = 0.456f;
input_tensor_info.normalize.mean[2] = 0.406f;
Expand Down Expand Up @@ -228,6 +232,7 @@ inference_helper->Process(output_tensor_info_list)
enum {
kTensorTypeNone,
kTensorTypeUint8,
kTensorTypeInt8,
kTensorTypeFp32,
kTensorTypeInt32,
kTensorTypeInt64,
Expand Down Expand Up @@ -288,7 +293,7 @@ struct {
void* data; // [Out] Pointer to the output data_
struct {
float scale;
uint8_t zeroPoint;
uint8_t zero_point;
} quant; // [Out] Parameters for dequantization (convert uint8 to float)
```

Expand Down
4 changes: 2 additions & 2 deletions inference_helper/inference_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class OutputTensorInfo : public TensorInfo {
#pragma omp parallel
for (int32_t i = 0; i < data_num; i++) {
const uint8_t* val_uint8 = static_cast<const uint8_t*>(data);
float val_float = (val_uint8[i] - quant.zeroPoint) * quant.scale;
float val_float = (val_uint8[i] - quant.zero_point) * quant.scale;
data_fp32_[i] = val_float;
}
return data_fp32_;
Expand All @@ -150,7 +150,7 @@ class OutputTensorInfo : public TensorInfo {
void* data; // [Out] Pointer to the output data_
struct {
float scale;
uint8_t zeroPoint;
uint8_t zero_point;
} quant; // [Out] Parameters for dequantization (convert uint8 to float)

private:
Expand Down
2 changes: 1 addition & 1 deletion inference_helper/inference_helper_armnn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class ArmnnWrapper {
list_armnntensor_out_.push_back(std::make_pair(armnn_info.first, armnn::Tensor(armnn_info.second, list_buffer_out_.back())));

tensor_info.data = list_buffer_out_.back();
tensor_info.quant.zeroPoint = armnn_tensor_info.GetQuantizationOffset();
tensor_info.quant.zero_point = armnn_tensor_info.GetQuantizationOffset();
tensor_info.quant.scale = armnn_tensor_info.GetQuantizationScale();
}

Expand Down
6 changes: 3 additions & 3 deletions inference_helper/inference_helper_tensorflow_lite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ void InferenceHelperTensorflowLite::DisplayModelInfo(const tflite::Interpreter&
}
if (tensor->type == kTfLiteUInt8) {
PRINT(" tensor[%d]->type: quantized\n", i);
PRINT(" tensor[%d]->params.outputZeroPoint, scale: %d, %f\n", i, tensor->params.zero_point, tensor->params.scale);
PRINT(" tensor[%d]->params.zero_point, scale: %d, %f\n", i, tensor->params.zero_point, tensor->params.scale);
} else {
PRINT(" tensor[%d]->type: not quantized\n", i);
}
Expand All @@ -380,7 +380,7 @@ void InferenceHelperTensorflowLite::DisplayModelInfo(const tflite::Interpreter&
}
if (tensor->type == kTfLiteUInt8) {
PRINT(" tensor[%d]->type: quantized\n", i);
PRINT(" tensor[%d]->params.outputZeroPoint, scale: %d, %f\n", i, tensor->params.zero_point, tensor->params.scale);
PRINT(" tensor[%d]->params.zero_point, scale: %d, %f\n", i, tensor->params.zero_point, tensor->params.scale);
} else {
PRINT(" tensor[%d]->type: not quantized\n", i);
}
Expand Down Expand Up @@ -468,7 +468,7 @@ int32_t InferenceHelperTensorflowLite::GetOutputTensorInfo(OutputTensorInfo& ten
tensor_info.tensor_type = TensorInfo::kTensorTypeUint8;
tensor_info.data = interpreter_->typed_tensor<uint8_t>(i);
tensor_info.quant.scale = tensor->params.scale;
tensor_info.quant.zeroPoint = tensor->params.zero_point;
tensor_info.quant.zero_point = tensor->params.zero_point;
break;
case kTfLiteFloat32:
tensor_info.tensor_type = TensorInfo::kTensorTypeFp32;
Expand Down
2 changes: 1 addition & 1 deletion inference_helper/inference_helper_tensorrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ int32_t InferenceHelperTensorRt::AllocateBuffers(std::vector<InputTensorInfo>& i
}
if (data_type == nvinfer1::DataType::kINT8) {
output_tensor_info.quant.scale = 1.0; // todo
output_tensor_info.quant.zeroPoint = 0.0;
output_tensor_info.quant.zero_point = 0.0;
}
output_tensor_info.data = buffer_cpu;
}
Expand Down

0 comments on commit c556e73

Please sign in to comment.