-
Notifications
You must be signed in to change notification settings - Fork 422
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for QONNX
Resize
node ingestion and tested with tiny …
…UNet model (#1122) * Added support for `Resize` node from QONNX model * Added a test on tiny UNet model in order to test `Resize` node * pre-commit restyling * Aesthetic fix * Second aesthetic fix * Added one test on a simpler model extracted from UNet model `branched_model_ch_last.onnx` * Example models commit updated * An empty list is now appended to the shape of all the inputs of the considered node, in case the input is empty * Cleaned some code and added the removal of RoI input from `Resize` node * revert some unneeded changes * Added some minor checks related to sizes parameter * Minor fix * Minor modification of the error msg * Minor fixes --------- Co-authored-by: Jovan Mitrevski <[email protected]>
- Loading branch information
Showing
6 changed files
with
201 additions
and
15 deletions.
There are no files selected for viewing
Submodule example-models
updated
from d40894 to 6a82da
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from warnings import warn | ||
|
||
from hls4ml.model.layers import Constant, Resize | ||
from hls4ml.model.optimizer import OptimizerPass | ||
|
||
|
||
class ResizeRemoveConstants(OptimizerPass): | ||
""" | ||
This optimizer is intended to clean the Resize node from RoI and Scales parameters that if left cause issues in hls4ml. | ||
""" | ||
|
||
def match(self, node): | ||
is_match = isinstance(node, Resize) and len(node.inputs) > 1 | ||
return is_match | ||
|
||
def transform(self, model, node): | ||
""" | ||
Remove RoI and Scale Constant from new shape input. | ||
""" | ||
# see doc here: https://onnx.ai/onnx/operators/onnx__Resize.html | ||
roi_index = 1 | ||
scales_idx = 2 | ||
scales_node = node.get_input_node(node.inputs[scales_idx]) | ||
node.inputs[scales_idx] = '' | ||
if not isinstance(scales_node, Constant): | ||
raise RuntimeError("Non-constant shape inputs are not supported") | ||
model.remove_node(scales_node, rewire=False) | ||
# RoI position is always 1 when present | ||
roi_node = node.get_input_node(node.inputs[roi_index]) | ||
if roi_node.get_attr('value'): | ||
warn('RoI value vector is not empty. Consider that RoI is not supported in hls4ml', stacklevel=2) | ||
node.inputs[roi_index] = '' | ||
if not isinstance(roi_node, Constant): | ||
raise RuntimeError("Non-constant RoI inputs are not supported") | ||
model.remove_node(roi_node, rewire=False) | ||
# Clean all the '' inputs | ||
node.inputs = list(filter(None, node.inputs)) | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters