Add MobileNetV3 operators to aidge_core
This MR is linked to aidge#299 (closed).
This MR aims to add operators declaration to support MobileNet-v3 Small. The current ONNX model (https://huggingface.co/qualcomm/MobileNet-v3-Small/resolve/main/MobileNet-v3-Small.onnx) uses two operators not yet implemented in Aidge:
- HardSigmoid
- HardSwish
HardSwish - Core Framework Implementation
HardSwish is implemented as a meta-operator defined as Mul(x,HardSigmoid(x)).
Core Framework Files
-
HardSwish.cpp(53 lines) - Meta-operator implementation with micro-graph construction -
MetaOperatorDefs.hpp(lines 420-445) - Function declarations for HardSwish_Op and HardSwish -
Test_MetaOperator.cpp(lines 246-273) - Unit tests for HardSwish meta-operator functionality
Meta-Operator Architecture
Implementation (HardSwish.cpp)
-
Micro-Graph Construction: Creates
Identity -> HardSigmoid -> Mulgraph structure -
Graph Connections:
input -> hardSigmoid,input -> mul,hardSigmoid -> mul - Parameter Handling: Supports alpha/beta parameters for HardSigmoid component
-
Node Management: Proper input/output ordering with
setOrderedInputsandsetOrderedOutputs
Function Declarations (MetaOperatorDefs.hpp)
- HardSwish_Op: Meta-operator creation with default parameters (alpha=1/6, beta=0.5)
- HardSwish: Node factory function with parameter customization
- Documentation: Comprehensive API documentation with mathematical definition
Unit Testing (Test_MetaOperator.cpp)
- Graph Structure Validation: Verifies 3-node micro-graph (Identity, HardSigmoid, Mul)
- Input/Output Testing: Validates 1 input, 1 output with proper tensor dimensions
- Functional Testing: Tests with actual tensor data and dimension forwarding
HardSigmoid - Core Framework Implementation
Core Framework Files
-
HardSigmoid.hpp(142 lines) - Main operator header with attribute definitions and class interface -
HardSigmoid.cpp(49 lines) - Operator implementation with constructor and factory functions -
pybind_HardSigmoid.cpp(86 lines) - Python bindings with comprehensive documentation -
Test_HardSigmoid_Op.cpp(62 lines) - Unit tests for operator attributes and functionality
Core Operator Architecture
Header Implementation (HardSigmoid.hpp)
-
Attribute System: Uses
StaticAttributes<HardSigmoidAttr>with Alpha/Beta parameters -
Class Definition:
HardSigmoid_Opinherits fromOperatorTensorWithImpl<HardSigmoid_Op> - Type Safety: Template-based implementation with proper constexpr definitions
- API Design: Clean interface with alpha/beta getters and factory function
Source Implementation (HardSigmoid.cpp)
- Constructor: Parameterized constructor with alpha/beta attribute initialization
- Copy Constructor: Proper deep copying of attributes and operator state
-
Factory Function:
HardSigmoid()creates nodes with default or custom parameters - Attribute Access: Direct access to alpha/beta parameters via reference
Python Bindings (pybind_HardSigmoid.cpp)
- Class Binding: Complete Python class with attribute access and documentation
- Function Binding: Factory function with parameter defaults and type safety
- Documentation: Comprehensive docstrings with mathematical definitions
- Registration: Automatic operator registration for Python interface
Unit Testing (Test_HardSigmoid_Op.cpp)
- Attribute Testing: Validates default and custom alpha/beta parameter handling
- Functionality Testing: Tests constructor and factory function behavior
- Type Safety: Verifies proper operator creation and type casting
External References
Edited by matthieu marchal