Skip to content

Commit

Permalink
not create new symbol with immutable shape convolution. (#1867)
Browse files Browse the repository at this point in the history
  • Loading branch information
fukatani authored May 31, 2023
1 parent 7c71c53 commit ef18cc0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion coremltools/converters/mil/mil/ops/defs/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,10 @@ def spatial_dimensions_out_shape(
# * `effective_ks` (effective kernel size, determined from kernel size + dilations) cannot be symbolic
# * strides cannot be symbolic
if is_symbolic(input_shape[r]):
out_shape.append(get_new_symbol())
if not is_symbolic(pad[r]) and pad[r] - effective_ks[r] == -1 and strides[r] == 1:
out_shape.append(input_shape[r])
else:
out_shape.append(get_new_symbol())
else:
out_dim = 0
if not ceil_mode:
Expand Down
13 changes: 13 additions & 0 deletions coremltools/converters/mil/mil/ops/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# found in the LICENSE.txt file or at https://opensource.org/licenses/BSD-3-Clause

import numpy as np
from coremltools.converters.mil import get_new_symbol

from coremltools.converters.mil.mil.ops.defs._utils import (
aggregated_pad, effective_kernel, spatial_dimensions_out_shape)
Expand Down Expand Up @@ -260,3 +261,15 @@ def test_same_padding_shape_dilation_2(self):

expected = [5, 5]
np.testing.assert_equal(actual, expected)

def test_symbolic_custom_pad(self):
input_shape = (get_new_symbol(), get_new_symbol())
actual = spatial_dimensions_out_shape(
pad_type="custom",
input_shape=input_shape,
kernel_shape=(1, 1),
strides=(1, 1),
dilations=(1, 1),
custom_pad=(0, 0, 0, 0),
)
np.testing.assert_equal(actual, input_shape)

0 comments on commit ef18cc0

Please sign in to comment.