53 const std::vector<TensorShape>& inputShapes)
const
55 if (inputShapes.size() != 1)
57 throw armnn::Exception(
"inputShapes' size is \"" + std::to_string(inputShapes.size()) +
58 "\" - should be \"1\".");
62 std::vector<unsigned int> outputShape;
63 unsigned int amountDimShrunk{0};
67 for(
unsigned int i = 0; i <
m_Param.m_Begin.size(); ++i)
70 if(
m_Param.m_NewAxisMask & (1 << i) && !(
m_Param.m_EllipsisMask & (1 << i)))
78 int realEllipsisMask = 0, realNewAxisMask = 0;
80 unsigned int ellipsisExpandedBy = 0;
81 for(
unsigned int i = 0; i < outputDims; ++i)
83 if(
m_Param.m_EllipsisMask & (1 << i))
87 unsigned int endIdx = std::min(i + 1u + outputDims - inputShape.
GetNumDimensions(), outputDims);
90 ellipsisExpandedBy = endIdx - i - 1;
93 for(; i < endIdx; ++i)
95 realEllipsisMask |= (1 << i);
100 if(
m_Param.m_NewAxisMask & (1 << (i - ellipsisExpandedBy)))
102 realNewAxisMask |= (1 << i);
107 unsigned int inputDimOffset = 0;
109 for (
unsigned int i = 0; i < outputDims; ++i)
112 if(realEllipsisMask & (1 << i))
114 outputShape.push_back(inputShape[i - inputDimOffset]);
118 if(realNewAxisMask & (1 << i))
120 outputShape.push_back(1);
129 if(realEllipsisMask > 0)
131 outputShape.push_back(1);
135 outputShape.push_back(inputShape[i - inputDimOffset]);
140 int stride =
m_Param.m_Stride[i];
141 int start =
m_Param.GetStartForAxis(inputShape, i);
142 int stop =
m_Param.GetStopForAxis(inputShape, i, start);
144 if (
m_Param.m_ShrinkAxisMask & (1 << i))
153 "StridedSlice: Attempting to take a larger slice than can fit in inferred output");
164 int newSize = stride > 0 ? ((stop - start) + stride - 1) / stride :
165 ((start - stop) - stride - 1) / -stride;
168 newSize = std::max(0, newSize);
174 if (outputShape.size() == 0 && (inputShape.
GetNumDimensions() - amountDimShrunk) == 0)
176 outputShape.push_back(1);
179 return std::vector<TensorShape>({
193 if (inferredShapes.size() != 1)
196 + std::to_string(inferredShapes.size()) +
197 " elements - should only have 1.");
Base class for all ArmNN exceptions so that users can filter to just those.
virtual void ExecuteStrategy(const IConnectableLayer *layer, const armnn::BaseDescriptor &descriptor, const std::vector< armnn::ConstTensor > &constants, const char *name, const armnn::LayerBindingId id=0)=0
virtual std::unique_ptr< IWorkload > CreateWorkload(LayerType type, const QueueDescriptor &descriptor, const WorkloadInfo &info) const =0
Backends should implement their own CreateWorkload function with a switch statement.
void VerifyLayerConnections(unsigned int expectedConnections, const CheckLocation &location) const
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
void VerifyShapeInferenceType(const TensorShape &outputShape, ShapeInferenceMethod shapeInferenceMethod)
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
Get the const output slot handle by slot index.
LayerType * CloneBase(Graph &graph, Params &&... params) const
const char * GetName() const override
Returns the name of the layer.
void ValidateAndCopyShape(const TensorShape &outputShape, const TensorShape &inferredShape, const ShapeInferenceMethod shapeInferenceMethod, const std::string &layerName, const unsigned int outputSlotIndex=0)
void SetAdditionalInfo(QueueDescriptor &descriptor) const
ShapeInferenceMethod m_ShapeInferenceMethod
LayerWithParameters(unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, const StridedSliceDescriptor ¶m, const char *name)
WorkloadInfo PrepInfoAndDesc(QueueDescriptor &descriptor) const
const StridedSliceDescriptor & GetParameters() const override
StridedSliceDescriptor m_Param
const TensorInfo & GetTensorInfo() const override
StridedSliceLayer(const StridedSliceDescriptor ¶m, const char *name)
Constructor to create a StridedSliceLayer.
void ExecuteStrategy(IStrategy &strategy) const override
Apply a visitor to this layer.
std::vector< TensorShape > InferOutputShapes(const std::vector< TensorShape > &inputShapes) const override
By default returns inputShapes if the number of inputs are equal to number of outputs,...
void ValidateTensorShapesFromInputs() override
Check if the input tensor shape(s) will lead to a valid configuration of StridedSliceLayer.
StridedSliceLayer * Clone(Graph &graph) const override
Creates a dynamically-allocated copy of this layer.
virtual std::unique_ptr< IWorkload > CreateWorkload(const IWorkloadFactory &factory) const override
Makes a workload for the StridedSlice type.
const TensorShape & GetShape() const
unsigned int GetNumDimensions() const
Function that returns the tensor rank.
Copyright (c) 2021 ARM Limited and Contributors.
LayerType
When adding a new layer, adapt also the LastLayer enum value in the enum class LayerType below.
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
void StridedSlice(const TensorInfo &inputInfo, const StridedSliceDescriptor ¶ms, const void *inputData, void *outputData, unsigned int dataTypeSize)
LayerDescriptor m_Parameters
A StridedSliceDescriptor for the StridedSliceLayer.
std::vector< int > m_Stride
Stride values for the input that will be sliced.
std::vector< int > m_Begin
Begin values for the input that will be sliced.
int32_t m_BeginMask
Begin mask value.
int32_t m_ShrinkAxisMask
Shrink axis mask value. If set, the nth specification shrinks the dimensionality by 1.
int32_t m_NewAxisMask
New axis mask value.
std::vector< int > m_End
End values for the input that will be sliced.
int32_t m_EndMask
End mask value.
int32_t m_EllipsisMask
Ellipsis mask value.