This repository was archived by the owner on Oct 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 107
Add unit tests for upsample and pool #99
Merged
Merged
Changes from 3 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
46ca059
Add unit tests for upsample and pool
jiafatom 8753c74
Add unit tests for upsample and pool
jiafatom 44b4b36
Merge branch 'test_upsample' of https://github.com/jiafatom/keras-onn…
jiafatom afb71ac
Merge branch 'test_upsample' of https://github.com/jiafatom/keras-onn…
jiafatom dba0a29
Merge branch 'test_upsample' of https://github.com/jiafatom/keras-onn…
jiafatom c39c2b4
Merge branch 'test_upsample' of https://github.com/jiafatom/keras-onn…
jiafatom 4409b08
Merge branch 'test_upsample' of https://github.com/jiafatom/keras-onn…
jiafatom 0d49b6a
Merge branch 'test_upsample' of https://github.com/jiafatom/keras-onn…
jiafatom 2cd17db
Merge branch 'test_upsample' of https://github.com/jiafatom/keras-onn…
jiafatom 5ba260f
Merge branch 'test_upsample' of https://github.com/jiafatom/keras-onn…
jiafatom 4113043
Merge branch 'test_upsample' of https://github.com/jiafatom/keras-onn…
jiafatom c8506a5
Merge branch 'test_upsample' of https://github.com/jiafatom/keras-onn…
jiafatom e262de5
Merge branch 'test_upsample' of https://github.com/jiafatom/keras-onn…
jiafatom 8390953
Merge branch 'test_upsample' of https://github.com/jiafatom/keras-onn…
jiafatom d10b2f5
Merge branch 'test_upsample' of https://github.com/jiafatom/keras-onn…
jiafatom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -10,43 +10,35 @@ | |
|
||
def convert_keras_upsample(scope, operator, container, n_dims): | ||
op = operator.raw_operator | ||
# op.size type is tuple, even if we set a int in keras.layers API | ||
if n_dims == 1: | ||
scales = [1, int(op.size), 1] | ||
elif n_dims == 2: | ||
scales = [1] + list(d for d in op.size) | ||
elif n_dims == 2 or n_dims == 3: | ||
# Always create the list of sampling factors in channels_first format because the input will be converted into | ||
# channels_first if it's in channels_last | ||
if isinstance(op.size, collections.Iterable): | ||
scales = [1, 1] + list(d for d in op.size) | ||
else: | ||
scales = [1, 1, int(op.size), int(op.size)] | ||
elif n_dims == 3: | ||
# Always create the list of sampling factors in channels_first format because the input will be converted into | ||
# channels_first if it's in channels_last | ||
if isinstance(op.size, collections.Iterable): | ||
scales = [1, 1] + list(int(d) for d in op.size) | ||
else: | ||
scales = [1, 1] + [int(op.size)] * 3 | ||
scales = [1, 1] + list(d for d in op.size) | ||
else: | ||
raise ValueError('Unsupported dimension %s when converting Keras Upsampling layer' % n_dims) | ||
|
||
# Derive permutation configuration. If the Keras input format is not channels_first, this configuration may be used | ||
# to manipulate the input and output of ONNX Upsample. | ||
input_perm_axes, output_perm_axes = get_permutation_config(n_dims) | ||
channels_first = n_dims > 1 and op.data_format == 'channels_first' | ||
no_permutation_required = channels_first or n_dims < 2 | ||
|
||
# Before creating the main Upsample operator, we need to permute the input tensor if the original operator is | ||
# working under channels_last mode. | ||
if channels_first: | ||
if no_permutation_required: | ||
# No permutation is required. Use input as it is. | ||
input_tensor_name = operator.inputs[0].full_name | ||
else: | ||
# Permute the original input and then use the permuted result as the input of ONNX Upsample | ||
input_tensor_name = scope.get_unique_variable_name(operator.inputs[0].full_name + '_permuted') | ||
apply_transpose(scope, operator.inputs[0].full_name, input_tensor_name, container, perm=input_perm_axes) | ||
|
||
# If channels_first is True, we don't need to permute the output of ONNX Upsample. Otherwise, similar to Crop's | ||
# If no_permutation_required is True, we don't need to permute the output of ONNX Upsample. Otherwise, similar to Crop's | ||
# conversion, a Transpose would be added. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. update channels_first comments to indicate change to no_permutation_required |
||
if channels_first: | ||
if no_permutation_required: | ||
apply_upsample(scope, input_tensor_name, operator.outputs[0].full_name, container, scales=scales) | ||
else: | ||
upsampled_tensor_name = scope.get_unique_variable_name(input_tensor_name + '_upsampled') | ||
|
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding the ceil_mode opset10 changes! I can close my PR #96.