|
54 | 54 |
|
55 | 55 | if is_tf2():
|
56 | 56 | conv2d_backprop_input = tf.compat.v1.nn.conv2d_backprop_input
|
| 57 | + conv3d_transpose = tf.compat.v1.nn.conv3d_transpose |
57 | 58 | multinomial = tf.compat.v1.random.multinomial
|
58 | 59 | space_to_batch_nd = tf.compat.v1.space_to_batch_nd
|
59 | 60 | batch_to_space_nd = tf.compat.v1.batch_to_space_nd
|
|
73 | 74 | fake_quant_with_min_max_args = tf.quantization.fake_quant_with_min_max_args
|
74 | 75 | elif LooseVersion(tf.__version__) >= "1.13":
|
75 | 76 | conv2d_backprop_input = tf.compat.v1.nn.conv2d_backprop_input
|
| 77 | + conv3d_transpose = tf.compat.v1.nn.conv3d_transpose |
76 | 78 | multinomial = tf.compat.v1.random.multinomial
|
77 | 79 | space_to_batch_nd = tf.compat.v1.space_to_batch_nd
|
78 | 80 | batch_to_space_nd = tf.compat.v1.batch_to_space_nd
|
|
93 | 95 | fake_quant_with_min_max_args = tf.compat.v1.quantization.fake_quant_with_min_max_args
|
94 | 96 | else:
|
95 | 97 | conv2d_backprop_input = tf.nn.conv2d_backprop_input
|
| 98 | + conv3d_transpose = tf.nn.conv3d_transpose |
96 | 99 | multinomial = tf.multinomial
|
97 | 100 | space_to_batch_nd = tf.space_to_batch_nd
|
98 | 101 | batch_to_space_nd = tf.batch_to_space_nd
|
@@ -395,6 +398,24 @@ def test_conv2d_6(self):
|
395 | 398 | kernel_val = np.arange(1, 1 + np.prod(kernel_shape)).astype("float32").reshape(kernel_shape)
|
396 | 399 | self._conv_test(x_val, kernel_val, strides=strides, padding="VALID", rtol=1e-05)
|
397 | 400 |
|
| 401 | + def test_conv2d_dilation_same(self): |
| 402 | + x_shape = [1, 35, 35, 288] # NHWC |
| 403 | + kernel_shape = [3, 3, 288, 384] # [filter_height, filter_width, in_channels, out_channels] |
| 404 | + strides = [1, 1, 1, 1] # NHWC |
| 405 | + dilations = [1, 3, 1, 1] # NHWC |
| 406 | + x_val = np.arange(1, 1 + np.prod(x_shape)).astype("float32").reshape(x_shape) |
| 407 | + kernel_val = np.arange(1, 1 + np.prod(kernel_shape)).astype("float32").reshape(kernel_shape) |
| 408 | + self._conv_test(x_val, kernel_val, strides=strides, padding="SAME", dilations=dilations, rtol=1e-05) |
| 409 | + |
| 410 | + def test_conv2d_dilation_strides_same(self): |
| 411 | + x_shape = [1, 35, 35, 288] # NHWC |
| 412 | + kernel_shape = [3, 3, 288, 384] # [filter_height, filter_width, in_channels, out_channels] |
| 413 | + strides = [1, 2, 4, 1] # NHWC |
| 414 | + dilations = [1, 3, 1, 1] # NHWC |
| 415 | + x_val = np.arange(1, 1 + np.prod(x_shape)).astype("float32").reshape(x_shape) |
| 416 | + kernel_val = np.arange(1, 1 + np.prod(kernel_shape)).astype("float32").reshape(kernel_shape) |
| 417 | + self._conv_test(x_val, kernel_val, strides=strides, padding="SAME", dilations=dilations, rtol=1e-05) |
| 418 | + |
398 | 419 | def test_conv3d_1(self):
|
399 | 420 | strides = [1, 1, 1, 1, 1]
|
400 | 421 | dilations = [1, 1, 1, 1, 1]
|
@@ -3136,45 +3157,38 @@ def func(x):
|
3136 | 3157 | @check_opset_min_version(10, "Conv2DBackpropInput")
|
3137 | 3158 | def test_Conv2DBackpropInput_const(self):
|
3138 | 3159 | input_sizes_val_ = np.array([1, 10, 10, 3], dtype=np.int32)
|
3139 |
| - filter_val_ = np.random.randint(low=0, high=256, size=[3, 3, 3, 5]) |
3140 |
| - out_backprop_val_ = np.random.randint(low=0, high=256, size=[1, 10, 10, 5]) |
3141 |
| - def func(): |
| 3160 | + def func(filter_val, out_backprop_val): |
3142 | 3161 | input_sizes_val = tf.constant(input_sizes_val_, dtype=tf.int32)
|
3143 |
| - filter_val = tf.constant(filter_val_, dtype=tf.float32) |
3144 |
| - out_backprop_val = tf.constant(out_backprop_val_, dtype=tf.float32) |
3145 | 3162 | return conv2d_backprop_input(input_sizes=input_sizes_val, filter=filter_val,
|
3146 | 3163 | out_backprop=out_backprop_val, strides=[1, 1, 1, 1],
|
3147 | 3164 | padding='SAME', name=_TFOUTPUT)
|
3148 |
| - self._run_test_case(func, [_OUTPUT], {}) |
| 3165 | + filters_val = np.random.randint(low=0, high=256, size=[3, 3, 3, 5]).astype(np.float32) |
| 3166 | + out_backprop_val = np.random.randint(low=0, high=256, size=[1, 10, 10, 5]).astype(np.float32) |
| 3167 | + self._run_test_case(func, [_OUTPUT], {_INPUT: filters_val, _INPUT1: out_backprop_val}) |
3149 | 3168 |
|
3150 | 3169 | @check_opset_min_version(10, "Conv2DBackpropInput")
|
3151 | 3170 | def test_Conv2DBackpropInput_const_strided(self):
|
3152 | 3171 | input_sizes_val_ = np.array([1, 10, 10, 3], dtype=np.int32)
|
3153 |
| - filter_val_ = np.random.randint(low=0, high=256, size=[3, 3, 3, 5]) |
3154 |
| - out_backprop_val_ = np.random.randint(low=0, high=256, size=[1, 5, 5, 5]) |
3155 |
| - |
3156 |
| - def func(): |
| 3172 | + def func(filter_val, out_backprop_val): |
3157 | 3173 | input_sizes_val = tf.constant(input_sizes_val_, dtype=tf.int32)
|
3158 |
| - filter_val = tf.constant(filter_val_, dtype=tf.float32) |
3159 |
| - out_backprop_val = tf.constant(out_backprop_val_, dtype=tf.float32) |
3160 | 3174 | return conv2d_backprop_input(input_sizes=input_sizes_val, filter=filter_val,
|
3161 | 3175 | out_backprop=out_backprop_val, strides=[1, 2, 2, 1],
|
3162 | 3176 | padding='SAME', name=_TFOUTPUT)
|
3163 |
| - self._run_test_case(func, [_OUTPUT], {}) |
| 3177 | + filters_val = np.random.randint(low=0, high=256, size=[3, 3, 3, 5]).astype(np.float32) |
| 3178 | + out_backprop_val = np.random.randint(low=0, high=256, size=[1, 5, 5, 5]).astype(np.float32) |
| 3179 | + self._run_test_case(func, [_OUTPUT], {_INPUT: filters_val, _INPUT1: out_backprop_val}) |
3164 | 3180 |
|
3165 | 3181 | @check_opset_min_version(10, "Conv2DBackpropInput")
|
3166 | 3182 | def test_Conv2DBackpropInput_const_valid(self):
|
3167 | 3183 | input_sizes_val_ = np.array([1, 12, 12, 3], dtype=np.int32)
|
3168 |
| - filter_val_ = np.random.randint(low=0, high=256, size=[3, 3, 3, 5]) |
3169 |
| - out_backprop_val_ = np.random.randint(low=0, high=256, size=[1, 10, 10, 5]) |
3170 |
| - def func(): |
| 3184 | + def func(filter_val, out_backprop_val): |
3171 | 3185 | input_sizes_val = tf.constant(input_sizes_val_, dtype=tf.int32)
|
3172 |
| - filter_val = tf.constant(filter_val_, dtype=tf.float32) |
3173 |
| - out_backprop_val = tf.constant(out_backprop_val_, dtype=tf.float32) |
3174 | 3186 | return conv2d_backprop_input(input_sizes=input_sizes_val, filter=filter_val,
|
3175 | 3187 | out_backprop=out_backprop_val, strides=[1, 1, 1, 1],
|
3176 | 3188 | padding='VALID', name=_TFOUTPUT)
|
3177 |
| - self._run_test_case(func, [_OUTPUT], {}) |
| 3189 | + filters_val = np.random.randint(low=0, high=256, size=[3, 3, 3, 5]).astype(np.float32) |
| 3190 | + out_backprop_val = np.random.randint(low=0, high=256, size=[1, 10, 10, 5]).astype(np.float32) |
| 3191 | + self._run_test_case(func, [_OUTPUT], {_INPUT: filters_val, _INPUT1: out_backprop_val}) |
3178 | 3192 |
|
3179 | 3193 | @check_opset_min_version(10, "Conv2DBackpropInput")
|
3180 | 3194 | def test_Conv2DBackpropInput(self):
|
@@ -3206,6 +3220,72 @@ def func(input_sizes, filters, out_backprop):
|
3206 | 3220 | out_backprop_val = np.random.randint(low=0, high=256, size=[1, 10, 10, 5]).astype(np.float32)
|
3207 | 3221 | self._run_test_case(func, [_OUTPUT], {_INPUT: input_sizes_val, _INPUT1: filters_val, _INPUT2: out_backprop_val})
|
3208 | 3222 |
|
| 3223 | + @check_opset_min_version(10, "Conv3DBackpropInputV2") |
| 3224 | + def test_Conv3DBackpropInputV2_const(self): |
| 3225 | + output_shape_val_ = np.array([1, 10, 10, 10, 3], dtype=np.int32) |
| 3226 | + def func(value, filters): |
| 3227 | + output_shape_val = tf.constant(output_shape_val_, dtype=tf.int32) |
| 3228 | + return conv3d_transpose(value, filters, output_shape_val, strides=[1, 1, 1, 1, 1], |
| 3229 | + padding='SAME', data_format="NDHWC", name=_TFOUTPUT) |
| 3230 | + filters_val = np.random.randint(low=0, high=256, size=[3, 3, 3, 3, 5]).astype(np.float32) |
| 3231 | + value_val = np.random.randint(low=0, high=256, size=[1, 10, 10, 10, 5]).astype(np.float32) |
| 3232 | + self._run_test_case(func, [_OUTPUT], {_INPUT: value_val, _INPUT1: filters_val}, rtol=1e-6) |
| 3233 | + |
| 3234 | + @check_opset_min_version(10, "Conv3DBackpropInputV2") |
| 3235 | + def test_Conv3DBackpropInputV2_const_strided(self): |
| 3236 | + output_shape_val_ = np.array([1, 10, 10, 10, 3], dtype=np.int32) |
| 3237 | + def func(value, filters): |
| 3238 | + output_shape_val = tf.constant(output_shape_val_, dtype=tf.int32) |
| 3239 | + return conv3d_transpose(value, filters, output_shape_val, strides=[1, 2, 2, 2, 1], |
| 3240 | + padding='SAME', data_format="NDHWC", name=_TFOUTPUT) |
| 3241 | + filters_val = np.random.randint(low=0, high=256, size=[3, 3, 3, 3, 5]).astype(np.float32) |
| 3242 | + value_val = np.random.randint(low=0, high=256, size=[1, 5, 5, 5, 5]).astype(np.float32) |
| 3243 | + self._run_test_case(func, [_OUTPUT], {_INPUT: value_val, _INPUT1: filters_val}, rtol=1e-6) |
| 3244 | + |
| 3245 | + @check_opset_min_version(10, "Conv3DBackpropInputV2") |
| 3246 | + def test_Conv3DBackpropInputV2_const_valid(self): |
| 3247 | + output_shape_val_ = np.array([1, 12, 12, 12, 3], dtype=np.int32) |
| 3248 | + def func(value, filters): |
| 3249 | + output_shape_val = tf.constant(output_shape_val_, dtype=tf.int32) |
| 3250 | + return conv3d_transpose(value, filters, output_shape_val, strides=[1, 1, 1, 1, 1], |
| 3251 | + padding='VALID', data_format="NDHWC", name=_TFOUTPUT) |
| 3252 | + filters_val = np.random.randint(low=0, high=256, size=[3, 3, 3, 3, 5]).astype(np.float32) |
| 3253 | + value_val = np.random.randint(low=0, high=256, size=[1, 10, 10, 10, 5]).astype(np.float32) |
| 3254 | + self._run_test_case(func, [_OUTPUT], {_INPUT: value_val, _INPUT1: filters_val}, rtol=1e-6) |
| 3255 | + |
| 3256 | + @check_opset_min_version(10, "Conv3DBackpropInputV2") |
| 3257 | + def test_Conv3DBackpropInputV2(self): |
| 3258 | + def func(value, filters, output_shape): |
| 3259 | + return conv3d_transpose(value, filters, output_shape, strides=[1, 1, 1, 1, 1], |
| 3260 | + padding='SAME', data_format="NDHWC", name=_TFOUTPUT) |
| 3261 | + filters_val = np.random.randint(low=0, high=256, size=[2, 3, 4, 4, 5]).astype(np.float32) |
| 3262 | + value_val = np.random.randint(low=0, high=256, size=[2, 7, 8, 9, 5]).astype(np.float32) |
| 3263 | + output_shape_val = np.array([2, 7, 8, 9, 4], dtype=np.int32) |
| 3264 | + self._run_test_case(func, [_OUTPUT], {_INPUT: value_val, _INPUT1: filters_val, _INPUT2: output_shape_val}, |
| 3265 | + rtol=1e-6) |
| 3266 | + |
| 3267 | + @check_opset_min_version(10, "Conv3DBackpropInputV2") |
| 3268 | + def test_Conv3DBackpropInputV2_strided(self): |
| 3269 | + def func(value, filters, output_shape): |
| 3270 | + return conv3d_transpose(value, filters, output_shape, strides=[1, 2, 2, 2, 1], |
| 3271 | + padding='SAME', data_format="NDHWC", name=_TFOUTPUT) |
| 3272 | + filters_val = np.random.randint(low=0, high=256, size=[3, 3, 3, 3, 5]).astype(np.float32) |
| 3273 | + value_val = np.random.randint(low=0, high=256, size=[1, 5, 5, 5, 5]).astype(np.float32) |
| 3274 | + output_shape_val = np.array([1, 10, 10, 10, 3], dtype=np.int32) |
| 3275 | + self._run_test_case(func, [_OUTPUT], {_INPUT: value_val, _INPUT1: filters_val, _INPUT2: output_shape_val}, |
| 3276 | + rtol=1e-6) |
| 3277 | + |
| 3278 | + @check_opset_min_version(10, "Conv3DBackpropInputV2") |
| 3279 | + def test_Conv3DBackpropInputV2_valid(self): |
| 3280 | + def func(value, filters, output_shape): |
| 3281 | + return conv3d_transpose(value, filters, output_shape, strides=[1, 1, 1, 1, 1], |
| 3282 | + padding='VALID', data_format="NDHWC", name=_TFOUTPUT) |
| 3283 | + filters_val = np.random.randint(low=0, high=256, size=[3, 3, 3, 3, 5]).astype(np.float32) |
| 3284 | + value_val = np.random.randint(low=0, high=256, size=[1, 10, 10, 10, 5]).astype(np.float32) |
| 3285 | + output_shape_val = np.array([1, 12, 12, 12, 3], dtype=np.int32) |
| 3286 | + self._run_test_case(func, [_OUTPUT], {_INPUT: value_val, _INPUT1: filters_val, _INPUT2: output_shape_val}, |
| 3287 | + rtol=1e-6) |
| 3288 | + |
3209 | 3289 | @check_opset_min_version(8, "CategoryMapper")
|
3210 | 3290 | @skip_tf2()
|
3211 | 3291 | def test_hashtable_lookup(self):
|
|
0 commit comments