@@ -978,10 +978,12 @@ def version_13(cls, ctx, node, **kwargs):
978
978
cls .any_version_after11 (13 , ctx , node , ** kwargs )
979
979
980
980
981
- @tf_op (["ResizeBilinear" , "ResizeNearestNeighbor" ])
981
+ @tf_op (["ResizeBilinear" , "ResizeNearestNeighbor" , "ResizeBicubic" ])
982
982
class Resize :
983
983
@classmethod
984
984
def version_7 (cls , ctx , node , ** kwargs ):
985
+ utils .make_sure (node .type != "ResizeBicubic" , "Opset 11 is required for bicubic interpolation for node %s" ,
986
+ node .name )
985
987
mode = "linear" if node .type == "ResizeBilinear" else "nearest"
986
988
node .type = "Upsample"
987
989
shape = ctx .get_shape (node .input [0 ])
@@ -1009,7 +1011,16 @@ def version_10(cls, ctx, node, **kwargs):
1009
1011
1010
1012
@classmethod
1011
1013
def version_11 (cls , ctx , node , ** kwargs ):
1012
- mode = "linear" if node .type == "ResizeBilinear" else "nearest"
1014
+ cubic_coeff_a = None
1015
+ exclude_outside = False
1016
+ if node .type == "ResizeBilinear" :
1017
+ mode = "linear"
1018
+ elif node .type == "ResizeBicubic" :
1019
+ mode = "cubic"
1020
+ cubic_coeff_a = - 0.5
1021
+ exclude_outside = True
1022
+ else :
1023
+ mode = "nearest"
1013
1024
roi = ctx .make_const (utils .make_name ("roi" ), np .array ([]).astype (np .float32 ))
1014
1025
const_zero = ctx .make_const (utils .make_name ("const_zero" ), np .array ([0 ]).astype (np .int64 ))
1015
1026
const_two = ctx .make_const (utils .make_name ("const_two" ), np .array ([2 ]).astype (np .int64 ))
@@ -1035,9 +1046,11 @@ def version_11(cls, ctx, node, **kwargs):
1035
1046
nearest_mode = "round_prefer_ceil"
1036
1047
else :
1037
1048
transformation_mode = "half_pixel"
1038
- resize = ctx .make_node ("Resize" , resize_inputs ,
1039
- attr = {"mode" : mode , "nearest_mode" : nearest_mode ,
1040
- "coordinate_transformation_mode" : transformation_mode })
1049
+ attr = {"mode" : mode , "nearest_mode" : nearest_mode , "coordinate_transformation_mode" : transformation_mode ,
1050
+ "exclude_outside" : exclude_outside }
1051
+ if cubic_coeff_a is not None :
1052
+ attr ["cubic_coeff_a" ] = cubic_coeff_a
1053
+ resize = ctx .make_node ("Resize" , resize_inputs , attr = attr )
1041
1054
shapes = node .output_shapes
1042
1055
dtypes = node .output_dtypes
1043
1056
ctx .remove_node (node .name )
@@ -1050,6 +1063,8 @@ def _convert_since_9(cls, ctx, node, op_type, use_target_size=False):
1050
1063
# float32 out = ResizeBilinear/ResizeNearestNeighbor(T images, int size)
1051
1064
# https://www.tensorflow.org/api_docs/python/tf/image/resize_nearest_neighbor
1052
1065
# wants the input to be NHWC - adjust target_shape to this.
1066
+ utils .make_sure (node .type != "ResizeBicubic" , "Opset 11 is required for bicubic interpolation for node %s" ,
1067
+ node .name )
1053
1068
mode = "linear" if node .type == "ResizeBilinear" else "nearest"
1054
1069
1055
1070
# because onnxruntime only supports to scale the last two dims so transpose is inserted
0 commit comments