aboutsummaryrefslogtreecommitdiff
path: root/src/armnnDeserializer
diff options
context:
space:
mode:
authorNattapat Chaimanowong <nattapat.chaimanowong@arm.com>2019-03-04 12:35:39 +0000
committerNattapat Chaimanowong <nattapat.chaimanowong@arm.com>2019-03-04 12:35:39 +0000
commitb348521a8308d374e39c5d8da1a94622e89cf8df (patch)
tree9a9fb1fc81591eec09c3b5301bd72d0fc1fa7be3 /src/armnnDeserializer
parentda1f975558a96499ea48cfca54e727a04b175271 (diff)
downloadarmnn-b348521a8308d374e39c5d8da1a94622e89cf8df.tar.gz
IVGCVSW-2710 Add Serializer and Deserializer for StridedSlice
Change-Id: I6e8198a2aa5f8c56f00ccf9b4d98fcd208755654 Signed-off-by: Nattapat Chaimanowong <nattapat.chaimanowong@arm.com>
Diffstat (limited to 'src/armnnDeserializer')
-rw-r--r--src/armnnDeserializer/Deserializer.cpp48
-rw-r--r--src/armnnDeserializer/Deserializer.hpp1
-rw-r--r--src/armnnDeserializer/DeserializerSupport.md1
-rw-r--r--src/armnnDeserializer/test/DeserializeStridedSlice.cpp181
4 files changed, 231 insertions, 0 deletions
diff --git a/src/armnnDeserializer/Deserializer.cpp b/src/armnnDeserializer/Deserializer.cpp
index 73c2042024..e4c9bd67be 100644
--- a/src/armnnDeserializer/Deserializer.cpp
+++ b/src/armnnDeserializer/Deserializer.cpp
@@ -209,6 +209,7 @@ m_ParserFunctions(Layer_MAX+1, &Deserializer::ParseUnsupportedLayer)
m_ParserFunctions[Layer_RsqrtLayer] = &Deserializer::ParseRsqrt;
m_ParserFunctions[Layer_SoftmaxLayer] = &Deserializer::ParseSoftmax;
m_ParserFunctions[Layer_SpaceToBatchNdLayer] = &Deserializer::ParseSpaceToBatchNd;
+ m_ParserFunctions[Layer_StridedSliceLayer] = &Deserializer::ParseStridedSlice;
m_ParserFunctions[Layer_SubtractionLayer] = &Deserializer::ParseSubtraction;
}
@@ -270,6 +271,8 @@ Deserializer::LayerBaseRawPtr Deserializer::GetBaseLayer(const GraphPtr& graphPt
return graphPtr->layers()->Get(layerIndex)->layer_as_SoftmaxLayer()->base();
case Layer::Layer_SpaceToBatchNdLayer:
return graphPtr->layers()->Get(layerIndex)->layer_as_SpaceToBatchNdLayer()->base();
+ case Layer::Layer_StridedSliceLayer:
+ return graphPtr->layers()->Get(layerIndex)->layer_as_StridedSliceLayer()->base();
case Layer::Layer_SubtractionLayer:
return graphPtr->layers()->Get(layerIndex)->layer_as_SubtractionLayer()->base();
case Layer::Layer_NONE:
@@ -1642,6 +1645,51 @@ void Deserializer::ParseRsqrt(GraphPtr graph, unsigned int layerIndex)
RegisterOutputSlots(graph, layerIndex, layer);
}
+void Deserializer::ParseStridedSlice(GraphPtr graph, unsigned int layerIndex)
+{
+ CHECK_LAYERS(graph, 0, layerIndex);
+
+ Deserializer::TensorRawPtrVector inputs = GetInputs(graph, layerIndex);
+ CHECK_VALID_SIZE(inputs.size(), 1);
+
+ Deserializer::TensorRawPtrVector outputs = GetOutputs(graph, layerIndex);
+ CHECK_VALID_SIZE(outputs.size(), 1);
+
+ auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_StridedSliceLayer()->descriptor();
+
+ auto flatBufferBegin = flatBufferDescriptor->begin();
+ auto flatBufferEnd = flatBufferDescriptor->end();
+ auto flatBufferStride = flatBufferDescriptor->stride();
+
+ if (!(flatBufferBegin->Length() == flatBufferEnd->Length() &&
+ flatBufferBegin->Length() == flatBufferStride->Length()))
+ {
+ throw ParseException(boost::str(
+ boost::format("The size of the begin, end, and stride must be equal %1%") % CHECK_LOCATION().AsString()));
+ }
+
+ std::vector<int> begin(flatBufferBegin->begin(), flatBufferBegin->end());
+ std::vector<int> end(flatBufferEnd->begin(), flatBufferEnd->end());
+ std::vector<int> stride(flatBufferStride->begin(), flatBufferStride->end());
+
+ armnn::StridedSliceDescriptor descriptor(begin, end, stride);
+ descriptor.m_BeginMask = flatBufferDescriptor->beginMask();
+ descriptor.m_EndMask = flatBufferDescriptor->endMask();
+ descriptor.m_ShrinkAxisMask = flatBufferDescriptor->shrinkAxisMask();
+ descriptor.m_EllipsisMask = flatBufferDescriptor->ellipsisMask();
+ descriptor.m_NewAxisMask = flatBufferDescriptor->newAxisMask();
+ descriptor.m_DataLayout = ToDataLayout(flatBufferDescriptor->dataLayout());
+
+ auto layerName = GetLayerName(graph, layerIndex);
+ IConnectableLayer* layer = m_Network->AddStridedSliceLayer(descriptor, layerName.c_str());
+
+ armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]);
+ layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo);
+
+ RegisterInputSlots(graph, layerIndex, layer);
+ RegisterOutputSlots(graph, layerIndex, layer);
+}
+
void Deserializer::ParseSubtraction(GraphPtr graph, unsigned int layerIndex)
{
CHECK_LAYERS(graph, 0, layerIndex);
diff --git a/src/armnnDeserializer/Deserializer.hpp b/src/armnnDeserializer/Deserializer.hpp
index 7595818628..b45551feb0 100644
--- a/src/armnnDeserializer/Deserializer.hpp
+++ b/src/armnnDeserializer/Deserializer.hpp
@@ -95,6 +95,7 @@ private:
void ParseRsqrt(GraphPtr graph, unsigned int layerIndex);
void ParseSoftmax(GraphPtr graph, unsigned int layerIndex);
void ParseSpaceToBatchNd(GraphPtr graph, unsigned int layerIndex);
+ void ParseStridedSlice(GraphPtr graph, unsigned int layerIndex);
void ParseSubtraction(GraphPtr graph, unsigned int layerIndex);
void RegisterOutputSlotOfConnection(uint32_t connectionIndex, armnn::IOutputSlot* slot);
diff --git a/src/armnnDeserializer/DeserializerSupport.md b/src/armnnDeserializer/DeserializerSupport.md
index 42da558738..a295676a84 100644
--- a/src/armnnDeserializer/DeserializerSupport.md
+++ b/src/armnnDeserializer/DeserializerSupport.md
@@ -30,6 +30,7 @@ The Arm NN SDK Deserialize parser currently supports the following layers:
* Rsqrt
* Softmax
* SpaceToBatchNd
+* StridedSlice
* Subtraction
More machine learning layers will be supported in future releases.
diff --git a/src/armnnDeserializer/test/DeserializeStridedSlice.cpp b/src/armnnDeserializer/test/DeserializeStridedSlice.cpp
new file mode 100644
index 0000000000..7c273070d9
--- /dev/null
+++ b/src/armnnDeserializer/test/DeserializeStridedSlice.cpp
@@ -0,0 +1,181 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include <boost/test/unit_test.hpp>
+#include "ParserFlatbuffersSerializeFixture.hpp"
+#include "../Deserializer.hpp"
+
+#include <string>
+
+BOOST_AUTO_TEST_SUITE(Deserializer)
+
+struct StridedSliceFixture : public ParserFlatbuffersSerializeFixture
+{
+ explicit StridedSliceFixture(const std::string& inputShape,
+ const std::string& begin,
+ const std::string& end,
+ const std::string& stride,
+ const std::string& beginMask,
+ const std::string& endMask,
+ const std::string& shrinkAxisMask,
+ const std::string& ellipsisMask,
+ const std::string& newAxisMask,
+ const std::string& dataLayout,
+ const std::string& outputShape,
+ const std::string& dataType)
+ {
+ m_JsonString = R"(
+ {
+ inputIds: [0],
+ outputIds: [2],
+ layers: [
+ {
+ layer_type: "InputLayer",
+ layer: {
+ base: {
+ layerBindingId: 0,
+ base: {
+ index: 0,
+ layerName: "InputLayer",
+ layerType: "Input",
+ inputSlots: [{
+ index: 0,
+ connection: {sourceLayerIndex:0, outputSlotIndex:0 },
+ }],
+ outputSlots: [{
+ index: 0,
+ tensorInfo: {
+ dimensions: )" + inputShape + R"(,
+ dataType: )" + dataType + R"(
+ }
+ }]
+ }
+ }
+ }
+ },
+ {
+ layer_type: "StridedSliceLayer",
+ layer: {
+ base: {
+ index: 1,
+ layerName: "StridedSliceLayer",
+ layerType: "StridedSlice",
+ inputSlots: [{
+ index: 0,
+ connection: {sourceLayerIndex:0, outputSlotIndex:0 },
+ }],
+ outputSlots: [{
+ index: 0,
+ tensorInfo: {
+ dimensions: )" + outputShape + R"(,
+ dataType: )" + dataType + R"(
+ }
+ }]
+ },
+ descriptor: {
+ begin: )" + begin + R"(,
+ end: )" + end + R"(,
+ stride: )" + stride + R"(,
+ beginMask: )" + beginMask + R"(,
+ endMask: )" + endMask + R"(,
+ shrinkAxisMask: )" + shrinkAxisMask + R"(,
+ ellipsisMask: )" + ellipsisMask + R"(,
+ newAxisMask: )" + newAxisMask + R"(,
+ dataLayout: )" + dataLayout + R"(,
+ }
+ }
+ },
+ {
+ layer_type: "OutputLayer",
+ layer: {
+ base:{
+ layerBindingId: 2,
+ base: {
+ index: 2,
+ layerName: "OutputLayer",
+ layerType: "Output",
+ inputSlots: [{
+ index: 0,
+ connection: {sourceLayerIndex:1, outputSlotIndex:0 },
+ }],
+ outputSlots: [{
+ index: 0,
+ tensorInfo: {
+ dimensions: )" + outputShape + R"(,
+ dataType: )" + dataType + R"(
+ },
+ }],
+ }
+ }
+ },
+ }
+ ]
+ }
+ )";
+ SetupSingleInputSingleOutput("InputLayer", "OutputLayer");
+ }
+};
+
+struct SimpleStridedSliceFixture : StridedSliceFixture
+{
+ SimpleStridedSliceFixture() : StridedSliceFixture("[ 3, 2, 3, 1 ]",
+ "[ 0, 0, 0, 0 ]",
+ "[ 3, 2, 3, 1 ]",
+ "[ 2, 2, 2, 1 ]",
+ "0",
+ "0",
+ "0",
+ "0",
+ "0",
+ "NCHW",
+ "[ 2, 1, 2, 1 ]",
+ "Float32") {}
+};
+
+BOOST_FIXTURE_TEST_CASE(SimpleStridedSliceFloat32, SimpleStridedSliceFixture)
+{
+ RunTest<4, armnn::DataType::Float32>(0,
+ {
+ 1.0f, 1.0f, 1.0f, 2.0f, 2.0f, 2.0f,
+ 3.0f, 3.0f, 3.0f, 4.0f, 4.0f, 4.0f,
+ 5.0f, 5.0f, 5.0f, 6.0f, 6.0f, 6.0f
+ },
+ {
+ 1.0f, 1.0f, 5.0f, 5.0f
+ });
+}
+
+struct StridedSliceMaskFixture : StridedSliceFixture
+{
+ StridedSliceMaskFixture() : StridedSliceFixture("[ 3, 2, 3, 1 ]",
+ "[ 1, 1, 1, 1 ]",
+ "[ 1, 1, 1, 1 ]",
+ "[ 1, 1, 1, 1 ]",
+ "15",
+ "15",
+ "0",
+ "0",
+ "0",
+ "NCHW",
+ "[ 3, 2, 3, 1 ]",
+ "Float32") {}
+};
+
+BOOST_FIXTURE_TEST_CASE(StridedSliceMaskFloat32, StridedSliceMaskFixture)
+{
+ RunTest<4, armnn::DataType::Float32>(0,
+ {
+ 1.0f, 1.0f, 1.0f, 2.0f, 2.0f, 2.0f,
+ 3.0f, 3.0f, 3.0f, 4.0f, 4.0f, 4.0f,
+ 5.0f, 5.0f, 5.0f, 6.0f, 6.0f, 6.0f
+ },
+ {
+ 1.0f, 1.0f, 1.0f, 2.0f, 2.0f, 2.0f,
+ 3.0f, 3.0f, 3.0f, 4.0f, 4.0f, 4.0f,
+ 5.0f, 5.0f, 5.0f, 6.0f, 6.0f, 6.0f
+ });
+}
+
+BOOST_AUTO_TEST_SUITE_END()