src/armnn/layers/ConvertFp16ToFp32Layer.cpp \
src/armnn/layers/ConvertFp32ToFp16Layer.cpp \
src/armnn/layers/DebugLayer.cpp \
+ src/armnn/layers/DepthToSpaceLayer.cpp \
src/armnn/layers/DepthwiseConvolution2dLayer.cpp \
src/armnn/layers/DequantizeLayer.cpp \
src/armnn/layers/DetectionPostProcessLayer.cpp \
src/armnn/layers/ConvertFp32ToFp16Layer.cpp
src/armnn/layers/DebugLayer.hpp
src/armnn/layers/DebugLayer.cpp
+ src/armnn/layers/DepthToSpaceLayer.hpp
+ src/armnn/layers/DepthToSpaceLayer.cpp
src/armnn/layers/DepthwiseConvolution2dLayer.hpp
src/armnn/layers/DepthwiseConvolution2dLayer.cpp
src/armnn/layers/DequantizeLayer.hpp
struct SpaceToDepthDescriptor
{
SpaceToDepthDescriptor()
- : m_BlockSize(1u)
- , m_DataLayout(DataLayout::NHWC)
+ : SpaceToDepthDescriptor(1u, DataLayout::NHWC)
+ {}
+
+ SpaceToDepthDescriptor(unsigned int blockSize, DataLayout dataLayout)
+ : m_BlockSize(blockSize)
+ , m_DataLayout(dataLayout)
{}
/// Scalar specifying the input block size. It must be >= 1
unsigned int m_BlockSize;
+
/// The data layout to be used (NCHW, NHWC).
DataLayout m_DataLayout;
};
+/// A DepthToSpaceDescriptor for the DepthToSpaceLayer
+using DepthToSpaceDescriptor = SpaceToDepthDescriptor;
+
/// An LstmDescriptor for the LstmLayer.
struct LstmDescriptor
{
struct TransposeConvolution2dDescriptor;
struct ViewsDescriptor;
+using DepthToSpaceDescriptor = SpaceToDepthDescriptor;
+
// MergerDescriptor is deprecated use ConcatDescriptor instead
using MergerDescriptor = OriginsDescriptor;
using ConcatDescriptor = OriginsDescriptor;
const TensorInfo& output,
Optional<std::string&> reasonIfUnsupported = EmptyOptional()) const = 0;
+ virtual bool IsDepthToSpaceSupported(const TensorInfo& input,
+ const TensorInfo& output,
+ const DepthToSpaceDescriptor& descriptor,
+ Optional<std::string&> reasonIfUnsupported = EmptyOptional()) const = 0;
+
virtual bool IsDepthwiseConvolutionSupported(
const TensorInfo& input,
const TensorInfo& output,
const Optional<ConstTensor>& biases,
const char* name = nullptr) = 0;
+ /// Function a depth to space layer should call back to when its Accept(ILayerVisitor&) function is invoked.
+ /// @param layer - pointer to the layer which is calling back to this visit function.
+ /// @param depthToSpaceDescriptor - Parameters for the depth to space operation.
+ /// @param name - Optional name for the layer.
+ virtual void VisitDepthToSpaceLayer(const IConnectableLayer* layer,
+ const DepthToSpaceDescriptor& depthToSpaceDescriptor,
+ const char* name = nullptr) = 0;
+
/// Function that a 2D depthwise convolution layer with biases should call back to when its
/// Accept(ILayerVisitor&) function is invoked.
/// @param layer - pointer to the layer which is calling back to this visit function.
const ConstTensor& biases,
const char* name = nullptr) = 0;
+ /// Adds a depth to space layer to the network.
+ /// @param depthToSpaceDescriptor - Parameters for the depth to space operation.
+ /// @param name - Optional name for the layer.
+ /// @return - Interface for configuring the layer.
+ virtual IConnectableLayer* AddDepthToSpaceLayer(const DepthToSpaceDescriptor& depthToSpaceDescriptor,
+ const char* name = nullptr) = 0;
+
/// Adds a 2D depthwise convolution layer to the network.
/// @param convolution2dDescriptor - Description of the 2D depthwise convolution layer.
/// @param weights - Tensor for the weights. Expected format: [channelMultiplier, inputChannels, height, width].
const Optional<ConstTensor>&,
const char*) override { DefaultPolicy::Apply(__func__); }
+ void VisitDepthToSpaceLayer(const IConnectableLayer*,
+ const DepthToSpaceDescriptor&,
+ const char*) override { DefaultPolicy::Apply(__func__); }
+
void VisitDepthwiseConvolution2dLayer(const IConnectableLayer*,
const DepthwiseConvolution2dDescriptor&,
const ConstTensor&,
case LayerType::ConvertFp32ToFp16: return "ConvertFp32ToFp16";
case LayerType::Convolution2d: return "Convolution2d";
case LayerType::Debug: return "Debug";
+ case LayerType::DepthToSpace: return "DepthToSpace";
case LayerType::DepthwiseConvolution2d: return "DepthwiseConvolution2d";
case LayerType::Dequantize: return "Dequantize";
case LayerType::DetectionPostProcess: return "DetectionPostProcess";
ConvertFp32ToFp16,
Convolution2d,
Debug,
+ DepthToSpace,
DepthwiseConvolution2d,
Dequantize,
DetectionPostProcess,
#include "layers/ConvertFp32ToFp16Layer.hpp"
#include "layers/Convolution2dLayer.hpp"
#include "layers/DebugLayer.hpp"
+#include "layers/DepthToSpaceLayer.hpp"
#include "layers/DepthwiseConvolution2dLayer.hpp"
#include "layers/DequantizeLayer.hpp"
#include "layers/DetectionPostProcessLayer.hpp"
DECLARE_LAYER(ConvertFp32ToFp16)
DECLARE_LAYER(Convolution2d)
DECLARE_LAYER(Debug)
+DECLARE_LAYER(DepthToSpace)
DECLARE_LAYER(DepthwiseConvolution2d)
DECLARE_LAYER(Dequantize)
DECLARE_LAYER(DetectionPostProcess)
return layer;
}
+IConnectableLayer* Network::AddDepthToSpaceLayer(const DepthToSpaceDescriptor& depthToSpaceDescriptor,
+ const char* name)
+{
+ return m_Graph->AddLayer<DepthToSpaceLayer>(depthToSpaceDescriptor, name);
+}
+
IConnectableLayer* Network::AddDepthwiseConvolution2dLayer(
const DepthwiseConvolution2dDescriptor& convolution2dDescriptor,
const ConstTensor& weights,
const ConstTensor& biases,
const char* name = nullptr) override;
+ IConnectableLayer* AddDepthToSpaceLayer(const DepthToSpaceDescriptor& depthToSpaceDescriptor,
+ const char* name = nullptr) override;
+
IConnectableLayer* AddDepthwiseConvolution2dLayer(
const DepthwiseConvolution2dDescriptor& convolution2dDescriptor,
const ConstTensor& weights,
--- /dev/null
+//
+// Copyright © 2019 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include "DepthToSpaceLayer.hpp"
+
+#include "LayerCloneBase.hpp"
+
+#include <armnn/TypesUtils.hpp>
+
+#include <backendsCommon/WorkloadData.hpp>
+#include <backendsCommon/WorkloadFactory.hpp>
+
+#include <DataLayoutIndexed.hpp>
+
+#include <numeric>
+
+namespace armnn
+{
+
+DepthToSpaceLayer::DepthToSpaceLayer(const DepthToSpaceDescriptor& param, const char* name)
+ : LayerWithParameters(1, 1, LayerType::DepthToSpace, param, name)
+{}
+
+std::unique_ptr<IWorkload> DepthToSpaceLayer::CreateWorkload(const Graph& graph,
+ const IWorkloadFactory& factory) const
+{
+ DepthToSpaceQueueDescriptor descriptor;
+ descriptor.m_Parameters.m_BlockSize = m_Param.m_BlockSize;
+ descriptor.m_Parameters.m_DataLayout = m_Param.m_DataLayout;
+
+ return factory.CreateDepthToSpace(descriptor, PrepInfoAndDesc(descriptor, graph));
+}
+
+DepthToSpaceLayer* DepthToSpaceLayer::Clone(Graph& graph) const
+{
+ return CloneBase<DepthToSpaceLayer>(graph, m_Param, GetName());
+}
+
+std::vector<TensorShape> DepthToSpaceLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const
+{
+ throw UnimplementedException("DepthToSpaceLayer::InferOutputShapes is not implemented");
+
+ BOOST_ASSERT(inputShapes.size() == 1);
+
+ TensorShape inputShape = inputShapes[0];
+ TensorShape outputShape(inputShape);
+
+ armnnUtils::DataLayoutIndexed dimensionIndices(m_Param.m_DataLayout);
+
+ unsigned int hIndex = dimensionIndices.GetHeightIndex();
+ unsigned int wIndex = dimensionIndices.GetWidthIndex();
+ unsigned int cIndex = dimensionIndices.GetChannelsIndex();
+
+ outputShape[hIndex] = inputShape[hIndex] * m_Param.m_BlockSize;
+ outputShape[wIndex] = inputShape[wIndex] * m_Param.m_BlockSize;
+
+ outputShape[cIndex] = inputShape[cIndex] / (m_Param.m_BlockSize * m_Param.m_BlockSize);
+
+ return std::vector<TensorShape>({ outputShape });
+}
+
+void DepthToSpaceLayer::ValidateTensorShapesFromInputs()
+{
+ VerifyLayerConnections(1, CHECK_LOCATION());
+
+ std::vector<TensorShape> inferredShapes = InferOutputShapes({
+ GetInputSlot(0).GetConnection()->GetTensorInfo().GetShape() });
+
+ BOOST_ASSERT(inferredShapes.size() == 1);
+
+ ConditionalThrowIfNotEqual<LayerValidationException>(
+ "DepthToSpaceLayer: TensorShape set on OutputSlot[0] does not match the inferred shape.",
+ GetOutputSlot(0).GetTensorInfo().GetShape(),
+ inferredShapes[0]);
+}
+
+void DepthToSpaceLayer::Accept(ILayerVisitor& visitor) const
+{
+ visitor.VisitDepthToSpaceLayer(this, GetParameters(), GetName());
+}
+
+} // namespace armnn
--- /dev/null
+//
+// Copyright © 2019 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#pragma once
+
+#include "LayerWithParameters.hpp"
+
+namespace armnn
+{
+
+/// This layer represents a DepthToSpace operation.
+class DepthToSpaceLayer : public LayerWithParameters<DepthToSpaceDescriptor>
+{
+public:
+ /// Makes a workload for the DepthToSpace type.
+ /// @param [in] graph The graph where this layer can be found.
+ /// @param [in] factory The workload factory which will create the workload.
+ /// @return A pointer to the created workload, or nullptr if not created.
+ virtual std::unique_ptr<IWorkload> CreateWorkload(const Graph& graph,
+ const IWorkloadFactory& factory) const override;
+
+ /// Creates a dynamically-allocated copy of this layer.
+ /// @param [in] graph The graph into which this layer is being cloned.
+ DepthToSpaceLayer* Clone(Graph& graph) const override;
+
+ /// By default returns inputShapes if the number of inputs are equal to number of outputs,
+ /// otherwise infers the output shapes from given input shapes and layer properties.
+ /// @param [in] inputShapes The input shapes layer has.
+ /// @return A vector to the inferred output shape.
+ std::vector<TensorShape> InferOutputShapes(const std::vector<TensorShape>& inputShapes) const override;
+
+ /// Check if the input tensor shape(s)
+ /// will lead to a valid configuration of @ref DepthToSpaceLayer.
+ void ValidateTensorShapesFromInputs() override;
+
+ void Accept(ILayerVisitor& visitor) const override;
+
+protected:
+ /// Constructor to create a DepthToSpaceLayer.
+ /// @param [in] param DepthToSpaceDescriptor to configure the DepthToSpaceLayer operation.
+ /// @param [in] name Optional name for the layer.
+ DepthToSpaceLayer(const DepthToSpaceDescriptor& param, const char* name);
+
+ /// Default destructor
+ ~DepthToSpaceLayer() = default;
+};
+
+} // namespace armnn
BOOST_AUTO_TEST_SUITE(TestNameOnlyLayerVisitor)
TEST_SUITE_NAME_ONLY_LAYER_VISITOR_1_PARAM(Addition)
+TEST_SUITE_NAME_ONLY_LAYER_VISITOR_2_PARAM(DepthToSpace)
TEST_SUITE_NAME_ONLY_LAYER_VISITOR_1_PARAM(Division)
TEST_SUITE_NAME_ONLY_LAYER_VISITOR_1_PARAM(Equal)
TEST_SUITE_NAME_ONLY_LAYER_VISITOR_1_PARAM(Floor)
} // anonymous namespace
TEST_LAYER_VISITOR_1_PARAM(Addition)
+TEST_LAYER_VISITOR_2_PARAM(DepthToSpace)
TEST_LAYER_VISITOR_1_PARAM(Division)
TEST_LAYER_VISITOR_1_PARAM(Equal)
TEST_LAYER_VISITOR_1_PARAM(Floor)
CreateAnyLayer(flatBufferLayer.o, serializer::Layer::Layer_Convolution2dLayer);
}
+void SerializerVisitor::VisitDepthToSpaceLayer(const armnn::IConnectableLayer* layer,
+ const armnn::DepthToSpaceDescriptor& descriptor,
+ const char* name)
+{
+ throw UnimplementedException("SerializerVisitor::VisitDepthToSpaceLayer is not implemented");
+}
+
void SerializerVisitor::VisitDepthwiseConvolution2dLayer(const armnn::IConnectableLayer* layer,
const armnn::DepthwiseConvolution2dDescriptor& descriptor,
const armnn::ConstTensor& weights,
const armnn::Optional<armnn::ConstTensor>& biases,
const char* = nullptr) override;
+ void VisitDepthToSpaceLayer(const armnn::IConnectableLayer* layer,
+ const armnn::DepthToSpaceDescriptor& descriptor,
+ const char* name = nullptr) override;
+
void VisitDepthwiseConvolution2dLayer(const armnn::IConnectableLayer* layer,
const armnn::DepthwiseConvolution2dDescriptor& descriptor,
const armnn::ConstTensor& weights,
return DefaultLayerSupport(__func__, __FILE__, __LINE__, reasonIfUnsupported);
}
+bool LayerSupportBase::IsDepthToSpaceSupported(const TensorInfo& input,
+ const TensorInfo& output,
+ const DepthToSpaceDescriptor& descriptor,
+ Optional<std::string&> reasonIfUnsupported) const
+{
+ return DefaultLayerSupport(__func__, __FILE__, __LINE__, reasonIfUnsupported);
+}
+
bool LayerSupportBase::IsDepthwiseConvolutionSupported(const TensorInfo& input,
const TensorInfo& output,
const DepthwiseConvolution2dDescriptor& descriptor,
const TensorInfo& output,
Optional<std::string&> reasonIfUnsupported = EmptyOptional()) const override;
+ bool IsDepthToSpaceSupported(const TensorInfo& input,
+ const TensorInfo& output,
+ const DepthToSpaceDescriptor& descriptor,
+ Optional<std::string&> reasonIfUnsupported = EmptyOptional()) const override;
+
bool IsDepthwiseConvolutionSupported(const TensorInfo& input,
const TensorInfo& output,
const DepthwiseConvolution2dDescriptor& descriptor,
}
}
+void DepthToSpaceQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const
+{
+ const std::string descriptorName{"DepthToSpaceQueueDescriptor"};
+
+ ValidateNumInputs(workloadInfo, descriptorName, 1);
+ ValidateNumOutputs(workloadInfo, descriptorName, 1);
+
+ const TensorInfo& inputInfo = workloadInfo.m_InputTensorInfos[0];
+ const TensorInfo& outputInfo = workloadInfo.m_OutputTensorInfos[0];
+
+ ValidateTensorNumDimensions(inputInfo, descriptorName, 4, "input");
+ ValidateTensorNumDimensions(outputInfo, descriptorName, 4, "output");
+
+ std::vector<DataType> supportedTypes =
+ {
+ DataType::Float32,
+ DataType::Float16,
+ DataType::QuantisedAsymm8,
+ DataType::QuantisedSymm16
+ };
+
+ ValidateDataTypes(inputInfo, supportedTypes, descriptorName);
+ ValidateDataTypes(outputInfo, supportedTypes, descriptorName);
+
+ ValidateTensorNumElementsMatch(inputInfo, outputInfo, descriptorName, "input", "output");
+
+ if (m_Parameters.m_BlockSize == 0)
+ {
+ throw InvalidArgumentException(descriptorName + ": Block size cannot be 0.");
+ }
+
+ DataLayoutIndexed dimensionIndices(m_Parameters.m_DataLayout);
+ const unsigned int wIndex = dimensionIndices.GetWidthIndex();
+ const unsigned int hIndex = dimensionIndices.GetHeightIndex();
+ const unsigned int cIndex = dimensionIndices.GetChannelsIndex();
+
+ const TensorShape& outputShape = outputInfo.GetShape();
+ if (outputShape[hIndex] % m_Parameters.m_BlockSize != 0 || outputShape[wIndex] % m_Parameters.m_BlockSize != 0)
+ {
+ throw InvalidArgumentException(descriptorName + ": Output width and height shape"
+ "must be divisible by block size.");
+ }
+
+ const TensorShape& inputShape = inputInfo.GetShape();
+ if (inputShape[cIndex] % (m_Parameters.m_BlockSize * m_Parameters.m_BlockSize) != 0)
+ {
+ throw InvalidArgumentException(descriptorName + ": The depth of the input tensor"
+ "must be divisible by the square of block size." );
+ }
+}
+
} // namespace armnn
void Validate(const WorkloadInfo& workloadInfo) const;
};
+struct DepthToSpaceQueueDescriptor : QueueDescriptorWithParameters<DepthToSpaceDescriptor>
+{
+ void Validate(const WorkloadInfo& workloadInfo) const;
+};
+
} // namespace armnn
reason);
break;
}
+ case LayerType::DepthToSpace:
+ {
+ auto cLayer = boost::polymorphic_downcast<const DepthToSpaceLayer*>(&layer);
+
+ const TensorInfo& input = layer.GetInputSlot(0).GetConnection()->GetTensorInfo();
+ const TensorInfo& output = layer.GetOutputSlot(0).GetTensorInfo();
+
+ result = layerSupportObject->IsDepthToSpaceSupported(OverrideDataType(input, dataType),
+ OverrideDataType(output, dataType),
+ cLayer->GetParameters(),
+ reason);
+ break;
+ }
case LayerType::DepthwiseConvolution2d:
{
auto cLayer = boost::polymorphic_downcast<const DepthwiseConvolution2dLayer*>(&layer);
return std::unique_ptr<IWorkload>();
}
+std::unique_ptr<IWorkload> IWorkloadFactory::CreateDepthToSpace(const DepthToSpaceQueueDescriptor& descriptor,
+ const WorkloadInfo& info) const
+{
+ return std::unique_ptr<IWorkload>();
+}
+
std::unique_ptr<IWorkload> IWorkloadFactory::CreateDepthwiseConvolution2d(
const DepthwiseConvolution2dQueueDescriptor& descriptor, const WorkloadInfo& info) const
{
virtual std::unique_ptr<IWorkload> CreateDebug(const DebugQueueDescriptor& descriptor,
const WorkloadInfo& info) const;
+ virtual std::unique_ptr<IWorkload> CreateDepthToSpace(const DepthToSpaceQueueDescriptor& descriptor,
+ const WorkloadInfo& info) const;
+
virtual std::unique_ptr<IWorkload> CreateDepthwiseConvolution2d(
const DepthwiseConvolution2dQueueDescriptor& descriptor, const WorkloadInfo& info) const;
DECLARE_LAYER_POLICY_1_PARAM(Debug)
+DECLARE_LAYER_POLICY_2_PARAM(DepthToSpace)
+
DECLARE_LAYER_POLICY_2_PARAM(DepthwiseConvolution2d)
DECLARE_LAYER_POLICY_1_PARAM(Dequantize)