Skip to content
Snippets Groups Projects

fix failed onnx tests

Merged Houssem ROUIS requested to merge fix_operators into dev
1 unresolved thread
Files
15
@@ -33,12 +33,21 @@ enum class AvgPoolingAttr {
* Specifies the step size of the sliding window along each spatial dimension.
*/
StrideDims,
/**
* @brief Dilation along each spatial axis. Default value is 1.
*/
Dilations,
/**
* @brief Kernel dimensions for the pooling operation.
* Specifies the size of the pooling window along each spatial dimension.
*/
KernelDims
KernelDims,
/**
* @brief Flag indicating whether to use ceil or floor when calculating output size.
* - `true`: Use `ceil` for output size calculation.
* - `false`: Use `floor` for output size calculation.
*/
CeilMode
};
/**
@@ -46,11 +55,30 @@ enum class AvgPoolingAttr {
*
* The AvgPooling operation computes the average value within sliding windows of specified size
* (kernel dimensions) over the input tensor. The stride dimensions determine how the window
* moves across the input. This operation is commonly used in neural networks to reduce the spatial
* dimensions while preserving features.
* moves across the input. The dilation parameter allows spacing between kernel elements, and
* `ceil_mode` determines whether to use ceiling instead of floor when computing the output shape.
* This operation is commonly used in neural networks to reduce spatial dimensions while preserving features.
*
* @tparam DIM Number of dimensions for the pooling operation.
*
* ### Output Shape Calculation
* - If `ceil_mode` is false:
* `output_size = floor((input_size - dilation * (kernel_size - 1) - 1) / stride + 1)`
* - If `ceil_mode` is true:
* `output_size = ceil((input_size - dilation * (kernel_size - 1) - 1) / stride + 1)`
*
* @example Example usage:
* - Input shape: (1, 3, 32, 32) // Batch size 1, 3 channels, 32x32 spatial dimensions
* - KernelDims: (2, 2)
* - StrideDims: (2, 2)
* - Dilation: (1, 1)
* - CeilMode: false
* - Output shape: (1, 3, 16, 16)
*
* @see OperatorTensor
* @see Registrable
*/
template <DimIdx_t DIM>
class AvgPooling_Op : public OperatorTensor,
public Registrable<AvgPooling_Op<DIM>, std::string, std::function<std::shared_ptr<OperatorImpl>(const AvgPooling_Op<DIM> &)>> {
@@ -67,7 +95,9 @@ private:
*/
using Attributes_ = StaticAttributes<AvgPoolingAttr,
std::array<DimSize_t, DIM>,
std::array<DimSize_t, DIM>>;
std::array<DimSize_t, DIM>,
std::array<DimSize_t, DIM>,
bool>;
template <AvgPoolingAttr e>
using attr = typename Attributes_::template attr<e>;
@@ -84,21 +114,27 @@ public:
/**
* @brief Constructs an AvgPooling operation with specified kernel and stride dimensions.
* @param kernel_dims Size of the pooling window for each spatial dimension.
* @param stride_dims Step size (stride) for sliding the pooling window across the input dimensions.
* @param[in] kernel_dims Size of the pooling window for each spatial dimension.
* @param[in] stride_dims Step size (stride) for sliding the pooling window across the input dimensions.
* Defaults to 1 for each dimension.
* @param[in] dilations Spatial dilations for the pooling operation.
* @param[in] ceil_mode Indicates whether to use ceil mode for output size calculation.
*/
constexpr AvgPooling_Op(const std::array<DimSize_t, DIM> &kernel_dims,
const std::array<DimSize_t, DIM> &stride_dims = create_array<DimSize_t, DIM>(1))
const std::array<DimSize_t, DIM> &stride_dims = create_array<DimSize_t, DIM>(1),
const std::array<DimSize_t, DIM> &dilations = create_array<DimSize_t, DIM>(1),
bool ceil_mode = false)
: OperatorTensor(Type, {InputCategory::Data}, 1),
mAttributes(std::make_shared<Attributes_>(
attr<AvgPoolingAttr::StrideDims>(stride_dims),
attr<AvgPoolingAttr::KernelDims>(kernel_dims)))
attr<AvgPoolingAttr::KernelDims>(kernel_dims),
attr<AvgPoolingAttr::Dilations>(dilations),
attr<AvgPoolingAttr::CeilMode>(ceil_mode)))
{}
/**
* @brief Copy-constructor.
* @param op AvgPooling_Op to copy.
* @param[in] op AvgPooling_Op to copy.
* @details Copies the operator attributes and its output tensor(s), but not
* its input tensors. The new operator has no associated input.
*/
@@ -112,16 +148,16 @@ public:
/**
* @brief Calculates the output dimensions based on the input dimensions and operator attributes.
* @param allowDataDependency If true, considers data-dependent operations. Defaults to false.
* @param[in] allowDataDependency If true, considers data-dependent operations. Defaults to false.
* @return True if the dimensions are successfully calculated.
*/
bool forwardDims(bool /*allowDataDependency*/ = false) override final;
/**
* @brief Computes the receptive field of the operator.
* @param firstEltDims Dimensions of the first element.
* @param outputDims Dimensions of the output tensor.
* @param outputIdx Index of the output tensor. Defaults to 0.
* @param[in] firstEltDims Dimensions of the first element.
* @param[in] outputDims Dimensions of the output tensor.
* @param[in] outputIdx Index of the output tensor. Defaults to 0.
* @return A vector of pairs representing the receptive fields.
*/
std::vector<std::pair<std::vector<DimSize_t>, std::vector<DimSize_t>>>
@@ -131,8 +167,8 @@ public:
/**
* @brief Sets the backend for the operation.
* @param name Name of the backend.
* @param device Device index. Defaults to 0.
* @param[in] name Name of the backend.
* @param[in] device Device index. Defaults to 0.
*/
void setBackend(const std::string &name, DeviceIdx_t device = 0) override final;
@@ -155,11 +191,23 @@ public:
inline std::array<DimSize_t, DIM>& strideDims() const { return mAttributes->template getAttr<AvgPoolingAttr::StrideDims>(); }
/**
* @brief Accessor for the kernel dimensions.
* @return An array representing the kernel dimensions.
* @brief Accessor for dilations.
* @return An array representing spatial dilations.
*/
inline std::array<DimSize_t, DIM>& dilations() const { return mAttributes->template getAttr<AvgPoolingAttr::Dilations>(); }
/**
* @brief Accessor for kernel dimensions.
* @return An array representing kernel dimensions.
*/
inline std::array<DimSize_t, DIM>& kernelDims() const { return mAttributes->template getAttr<AvgPoolingAttr::KernelDims>(); }
/**
* @brief Accessor for ceil mode flag.
* @return Boolean value indicating whether ceil mode is enabled.
*/
inline bool& ceilMode() const { return mAttributes->template getAttr<AvgPoolingAttr::CeilMode>(); }
/**
* @brief Retrieves the names of the input tensors.
* @return A vector of strings representing the input tensors names.
@@ -180,31 +228,39 @@ public:
/**
* @brief Creates an AvgPooling operator node.
* @tparam DIM Number of dimensions for the pooling operation.
* @param kernel_dims Size of the pooling window for each spatial dimension.
* @param name Name of the operator node. Defaults to an empty string.
* @param stride_dims Step size (stride) for sliding the pooling window across the input dimensions. Defaults to 1 for each dimension.
* @param[in] kernel_dims Size of the pooling window for each spatial dimension.
* @param[in] name Name of the operator node. Defaults to an empty string.
* @param[in] stride_dims Step size (stride) for sliding the pooling window across the input dimensions. Defaults to 1 for each dimension.
* @param[in] dilations Spatial dilations for the pooling operation.
* @param[in] ceil_mode Indicates whether to use ceil mode for output size calculation.
* @return A shared pointer to the created operator node.
*/
template <std::array<DimSize_t, 1>::size_type DIM>
std::shared_ptr<Node> AvgPooling(const std::array<DimSize_t, DIM> &kernel_dims,
const std::string& name = "",
const std::array<DimSize_t, DIM> &stride_dims = create_array<DimSize_t,DIM>(1));
const std::array<DimSize_t, DIM> &stride_dims = create_array<DimSize_t,DIM>(1),
const std::array<DimSize_t, DIM> &dilations = create_array<DimSize_t,DIM>(1),
bool ceil_mode=false);
/**
* @brief Overload of AvgPooling for C-style arrays.
* @tparam DIM Number of dimensions for the pooling operation.
* @param kernel_dims C-style array specifying the kernel dimensions.
* @param name Name of the operator node. Defaults to an empty string.
* @param stride_dims Step size (stride) for sliding the pooling window across the input dimensions. Defaults to 1 for each dimension.
* @param[in] kernel_dims C-style array specifying the kernel dimensions.
* @param[in] name Name of the operator node. Defaults to an empty string.
* @param[in] stride_dims Step size (stride) for sliding the pooling window across the input dimensions. Defaults to 1 for each dimension.
* @param[in] dilations Spatial dilations for the pooling operation.
* @param[in] ceil_mode Indicates whether to use ceil mode for output size calculation.
* @return A shared pointer to the created operator node.
*/
template <DimSize_t DIM>
inline std::shared_ptr<Node> AvgPooling(
DimSize_t const (&kernel_dims)[DIM],
const std::string& name = "",
const std::array<DimSize_t, DIM> &stride_dims = create_array<DimSize_t,DIM>(1)) {
const std::array<DimSize_t, DIM> &stride_dims = create_array<DimSize_t,DIM>(1),
const std::array<DimSize_t, DIM> &dilations = create_array<DimSize_t,DIM>(1),
bool ceil_mode=false) {
static_assert(DIM<=MaxDim,"Too many kernel dimensions required by AvgPooling, not supported");
return AvgPooling(to_array(kernel_dims), name, stride_dims);
return AvgPooling(to_array(kernel_dims), name, stride_dims, dilations, ceil_mode);
}
} // namespace Aidge
@@ -221,10 +277,7 @@ namespace {
* @brief String representation of the AvgPooling attributes.
*/
template <>
const char *const EnumStrings<Aidge::AvgPoolingAttr>::data[] = {
"stride_dims",
"kernel_dims"
};
const char *const EnumStrings<Aidge::AvgPoolingAttr>::data[] = { "stride_dims", "kernel_dims", "dilations", "ceil_mode" };
}
#endif /* AIDGE_CORE_OPERATOR_AVGPOOLING_H_ */
Loading