ONNX multi-output model: forward() only returns first output, feature mismatch in FPN upsampling

I'm trying to use a multi-output ONNX model (Feature Pyramid Network for pose estimation) in MATLAB R2024b on macOS ARM (M3). I've encountered two significant issues:
1. **`forward()` only returns first output** despite model having 4 outputs
2. **Feature mismatch** due to how MATLAB interprets Resize operations
### System Information
- MATLAB R2024b
- Deep Learning Toolbox
- macOS ARM (Apple Silicon M3)
- ONNX model: IR version 7, Opset 14
- Model size: ~14 MB, 260-293 layers
### Issue 1: forward() Returns Only First Output
**Model structure:**
```matlab
net = importNetworkFromONNX('model.onnx');
net.OutputNames
% Returns: {'super_fineOutput', 'fineOutput', 'mediumOutput', 'coarseOutput'}
```
**Expected behavior:**
```matlab
net = initialize(net, input);
outputs = forward(net, input, 'Outputs', net.OutputNames);
% Expected: Cell array {1x4} with 4 different tensors
```
**Actual behavior:**
```matlab
outputs = forward(net, input, 'Outputs', net.OutputNames);
% Returns: Single dlarray [640 512 16 1]
% Only the first output is returned, not a cell array with all 4
```
This is the same behavior as calling `predict(net, input)` which only returns the first output. The `'Outputs'` parameter appears to be ignored.
**Verification:** Python onnxruntime correctly returns all 4 outputs from the same ONNX file:
```python
import onnxruntime as ort
session = ort.InferenceSession('model.onnx')
outputs = session.run(None, {'input': input_array})
len(outputs) # Returns: 4 (correct)
```
### Issue 2: Feature Mismatch in FPN Upsampling
When importing ONNX models with Feature Pyramid Networks, I see warnings:
```
Warning: Attribute(s) [antialias,keep_aspect_ratio_policy] in layer 'node_upsample_neares'
with operator type 'Resize' are unknown.
```
**Impact:** MATLAB's interpretation of Resize operations differs from onnxruntime, causing feature values to diverge:
| Level | Upsampling | Max Difference | Status |
|-------|------------|----------------|--------|
| Level 3 (64×80) | None | 0.000027 | ✓ Perfect match |
| Level 2 (128×160) | 1× upsample | 0.537945 | ✗ Significant diff |
| Level 1 (256×320) | 2× upsample | 1.296227 | ✗ Large diff |
| Level 0 (512×640) | 3× upsample | 1.491008 | ✗ Largest diff |
The base level (no upsampling) matches perfectly, but errors compound through the feature pyramid. This breaks downstream pose estimation which requires sub-pixel accuracy.
**Comparison methodology:**
```matlab
% MATLAB features
net = importNetworkFromONNX('model.onnx');
net = initialize(net, input);
matlab_features = predict(net, input);
% Python features (from same checkpoint, onnxruntime)
python_features = load('features_from_onnxruntime.mat');
% Compare
diff = abs(matlab_features(:) - python_features(:));
max_diff = max(diff); % Should be < 0.001 for numerical precision
```
### Questions
1. **Is the forward() multi-output behavior a known limitation or bug?** The documentation suggests `forward(net, input, 'Outputs', net.OutputNames)` should return all requested outputs as a cell array.
2. **Can MATLAB's ONNX importer support the `antialias` and `keep_aspect_ratio_policy` attributes** for Resize operations? Or is there a way to ensure MATLAB interprets Resize the same way as onnxruntime?
3. **Are there recommended workarounds** for deploying multi-output ONNX models in MATLAB?
### Workarounds Attempted
**For Issue 1 (multi-output):**
- ✗ Tried clean re-export with explicit output names - same result
- ✗ Tried different ONNX opset versions (14, 18) - same result
-**Workaround that works:** Export 4 separate single-output ONNX models (one per output)
- Con: 4× inference time, 4× disk space
**For Issue 2 (feature mismatch):**
- ✗ Cannot control PyTorch's ONNX export at operation level
- ✗ Cannot modify MATLAB's Resize interpretation
The multi-output limitation significantly impacts deploying vision models (FPN, U-Net, multi-task networks) that naturally produce multiple outputs.
### Additional Context
- The ONNX file loads and runs successfully (no crashes)
- Model import takes ~7-10 seconds per model
- Single-output models work perfectly with `predict()`
- The same ONNX file works correctly in Python with onnxruntime
- This affects production deployment where pure MATLAB solution is preferred

Réponses (1)

Regarding the number of outputs returned by the forward command, based on the documentation, you may need to explicitly specify a separate output variable for each network output, as forward returns multiple outputs using multiple output arguments rather than a cell array.
For the second query, the attributes you mentioned are currently not supported by the import workflow. If those attributes are essential for your application, it may be worthwhile to contact MathWorks Technical Support to discuss possible options or guidance.
You may also find the following documentations helpful for understanding interoperability considerations and limitations when importing models from other frameworks:

Produits

Version

R2024b

Tags

Réponse apportée :

le 27 Avr 2026 à 7:23

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by