forked from huawei/mindspore2022
modify resizebilinear infer type
This commit is contained in:
parent
c3cf1fb16b
commit
7a2fbdda85
|
|
@ -39,7 +39,7 @@ bool ResizeBilinearCPUKernel::Launch(const std::vector<kernel::AddressPtr> &inpu
|
|||
const std::vector<kernel::AddressPtr> &,
|
||||
const std::vector<kernel::AddressPtr> &outputs) {
|
||||
if (dtype_ == kNumberTypeFloat16) {
|
||||
LaunchKernel<float16, float>(inputs, outputs);
|
||||
LaunchKernel<float16, float16>(inputs, outputs);
|
||||
} else if (dtype_ == kNumberTypeFloat32) {
|
||||
LaunchKernel<float, float>(inputs, outputs);
|
||||
}
|
||||
|
|
@ -64,7 +64,7 @@ void ResizeBilinearCPUKernel::LaunchKernel(const std::vector<AddressPtr> &inputs
|
|||
|
||||
if (out_height == in_height && out_width == in_width) {
|
||||
for (size_t i = 0; i < bhwc_size; ++i) {
|
||||
output_addr[i] = static_cast<float>(input_addr[i]);
|
||||
output_addr[i] = static_cast<T2>(input_addr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ class ResizeBilinearCPUKernel : public CPUKernel {
|
|||
std::vector<size_t> shape_;
|
||||
};
|
||||
|
||||
MS_REG_CPU_KERNEL(ResizeBilinear, KernelAttr().AddInputAttr(kNumberTypeFloat16).AddOutputAttr(kNumberTypeFloat32),
|
||||
MS_REG_CPU_KERNEL(ResizeBilinear, KernelAttr().AddInputAttr(kNumberTypeFloat16).AddOutputAttr(kNumberTypeFloat16),
|
||||
ResizeBilinearCPUKernel);
|
||||
|
||||
MS_REG_CPU_KERNEL(ResizeBilinear, KernelAttr().AddInputAttr(kNumberTypeFloat32).AddOutputAttr(kNumberTypeFloat32),
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
template <typename T>
|
||||
__global__ void ResizeBilinear(const T *input, const int n, const int c, const int input_h, const int input_w,
|
||||
const int output_h, const int output_w, const int nchw, const int chw, const int hw, const float h_scale,
|
||||
const float w_scale, float *output) {
|
||||
const float w_scale, T *output) {
|
||||
for (size_t pos = blockIdx.x * blockDim.x + threadIdx.x; pos < nchw; pos += blockDim.x * gridDim.x) {
|
||||
const int posn = pos / chw;
|
||||
const int posc = pos / hw % c;
|
||||
|
|
@ -38,11 +38,12 @@ __global__ void ResizeBilinear(const T *input, const int n, const int c, const i
|
|||
const float h_alpha = posh_scaled - h_low;
|
||||
const float h_beta = 1.0f - h_alpha;
|
||||
const int input_start = input_h * input_w * (posn * c + posc);
|
||||
const float p1 = static_cast<float>(input[input_start + (h_low * input_w) + w_low]);
|
||||
const float p2 = static_cast<float>(input[input_start + (h_low * input_w) + w_high]);
|
||||
const float p3 = static_cast<float>(input[input_start + (h_high * input_w) + w_low]);
|
||||
const float p4 = static_cast<float>(input[input_start + (h_high * input_w) + w_high]);
|
||||
output[pos] = (p1 * h_beta * w_beta) + (p2 * h_beta * w_alpha) + (p3 * h_alpha * w_beta) + (p4 * h_alpha * w_alpha);
|
||||
const T p1 = input[input_start + (h_low * input_w) + w_low];
|
||||
const T p2 = input[input_start + (h_low * input_w) + w_high];
|
||||
const T p3 = input[input_start + (h_high * input_w) + w_low];
|
||||
const T p4 = input[input_start + (h_high * input_w) + w_high];
|
||||
output[pos] = (p1 * static_cast<T>(h_beta * w_beta)) + (p2 * static_cast<T>(h_beta * w_alpha))
|
||||
+ (p3 * static_cast<T>(h_alpha * w_beta)) + (p4 * static_cast<T>(h_alpha * w_alpha));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
@ -122,7 +123,7 @@ __global__ void ResizeBilinearGradPost(const int nchw, half *output, float *inte
|
|||
|
||||
template <typename T>
|
||||
void CalResizeBilinear(const T *input, const int n, const int c, const int input_h, const int input_w,
|
||||
const int output_h, const int output_w, const float h_scale, const float w_scale, float *output,
|
||||
const int output_h, const int output_w, const float h_scale, const float w_scale, T *output,
|
||||
cudaStream_t cuda_stream) {
|
||||
const int nchw = n * c * output_h * output_w;
|
||||
const int chw = c * output_h * output_w;
|
||||
|
|
@ -160,5 +161,5 @@ template void CalResizeBilinear<float>(const float *input, const int n, const in
|
|||
const int input_w, const int output_h, const int output_w, const float h_scale, const float w_scale, float *output,
|
||||
cudaStream_t cuda_stream);
|
||||
template void CalResizeBilinear<half>(const half *input, const int n, const int c, const int input_h,
|
||||
const int input_w, const int output_h, const int output_w, const float h_scale, const float w_scale, float *output,
|
||||
const int input_w, const int output_h, const int output_w, const float h_scale, const float w_scale, half *output,
|
||||
cudaStream_t cuda_stream);
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
#include "runtime/device/gpu/cuda_common.h"
|
||||
template <typename T>
|
||||
void CalResizeBilinear(const T *input, const int n_, const int c_, const int input_h_, const int input_w_,
|
||||
const int output_h_, const int output_w_, const float h_scale, const float w_scale, float *output,
|
||||
const int output_h_, const int output_w_, const float h_scale, const float w_scale, T *output,
|
||||
cudaStream_t cuda_stream);
|
||||
void CalResizeBilinearGrad(const float *input, const int n_, const int c_, const int input_h_, const int input_w_,
|
||||
const int output_h_, const int output_w_, const float h_scale, const float w_scale, half *output, float *interim,
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ namespace mindspore {
|
|||
namespace kernel {
|
||||
MS_REG_GPU_KERNEL_ONE(ResizeBilinear, KernelAttr().AddInputAttr(kNumberTypeFloat32).AddOutputAttr(kNumberTypeFloat32),
|
||||
ResizeBilinearGpuKernel, float)
|
||||
MS_REG_GPU_KERNEL_ONE(ResizeBilinear, KernelAttr().AddInputAttr(kNumberTypeFloat16).AddOutputAttr(kNumberTypeFloat32),
|
||||
MS_REG_GPU_KERNEL_ONE(ResizeBilinear, KernelAttr().AddInputAttr(kNumberTypeFloat16).AddOutputAttr(kNumberTypeFloat16),
|
||||
ResizeBilinearGpuKernel, half)
|
||||
} // namespace kernel
|
||||
} // namespace mindspore
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class ResizeBilinearGpuKernel : public GpuKernel {
|
|||
bool Launch(const std::vector<AddressPtr> &inputs, const std::vector<AddressPtr> &workspace,
|
||||
const std::vector<AddressPtr> &outputs, void *stream_ptr) override {
|
||||
T *input = GetDeviceAddress<T>(inputs, 0);
|
||||
float *output = GetDeviceAddress<float>(outputs, 0);
|
||||
T *output = GetDeviceAddress<T>(outputs, 0);
|
||||
float h_scale = Scaling(input_h_, output_h_, align_corners_);
|
||||
float w_scale = Scaling(input_w_, output_w_, align_corners_);
|
||||
CalResizeBilinear(input, n_, c_, input_h_, input_w_, output_h_, output_w_, h_scale, w_scale, output,
|
||||
|
|
@ -72,7 +72,7 @@ class ResizeBilinearGpuKernel : public GpuKernel {
|
|||
for (auto x : input_shape) {
|
||||
input_size_ *= x;
|
||||
}
|
||||
output_size_ = sizeof(float);
|
||||
output_size_ = sizeof(T);
|
||||
for (auto x : output_shape) {
|
||||
output_size_ *= x;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ AbstractBasePtr ResizeBilinearInfer(const abstract::AnalysisEnginePtr &, const P
|
|||
// Infer type
|
||||
const std::set<TypePtr> valid_types = {kFloat16, kFloat32};
|
||||
(void)CheckAndConvertUtils::CheckTensorTypeValid("input_type", input_args[0]->BuildType(), valid_types, prim_name);
|
||||
return std::make_shared<abstract::AbstractTensor>(kFloat32, out_shape);
|
||||
return std::make_shared<abstract::AbstractTensor>(input_args[0]->BuildType(), out_shape);
|
||||
}
|
||||
REGISTER_PRIMITIVE_C(kNameResizeBilinear, ResizeBilinear);
|
||||
} // namespace ops
|
||||
|
|
|
|||
|
|
@ -3491,7 +3491,7 @@ class ResizeBilinear(PrimitiveWithInfer):
|
|||
|
||||
Outputs:
|
||||
Tensor, resized image. 4-D with shape :math:`(batch, channels, new\_height, new\_width)`,
|
||||
with data type of float32.
|
||||
with the same data type as input `x`.
|
||||
|
||||
Raises:
|
||||
TypeError: If `size` is neither a tuple nor list.
|
||||
|
|
@ -3539,7 +3539,7 @@ class ResizeBilinear(PrimitiveWithInfer):
|
|||
def infer_dtype(self, input_dtype):
|
||||
validator.check_tensor_dtype_valid('input_dtype', input_dtype, [mstype.float16, mstype.float32],
|
||||
self.name)
|
||||
return mstype.tensor_type(mstype.float32)
|
||||
return input_dtype
|
||||
|
||||
|
||||
class OneHot(Primitive):
|
||||
|
|
|
|||
|
|
@ -41,24 +41,16 @@ def test_resize_nn_grayscale_integer_ratio_half(datatype=np.float16):
|
|||
# larger h and w
|
||||
resize_nn = NetResizeBilinear((9, 9))
|
||||
output = resize_nn(input_tensor)
|
||||
expected_output = Tensor(np.array([[[[0.09997559, 0.13330078, 0.16662598, 0.19995117, 0.23331706,
|
||||
0.26668295, 0.30004883, 0.30004883, 0.30004883],
|
||||
[0.19995117, 0.23328993, 0.26662868, 0.29996747, 0.33333334,
|
||||
0.36669925, 0.40006512, 0.40006512, 0.40006512],
|
||||
[0.29992676, 0.33327907, 0.36663142, 0.39998373, 0.4333496,
|
||||
0.4667155, 0.5000814, 0.5000814, 0.5000814],
|
||||
[0.39990234, 0.43326822, 0.46663412, 0.5, 0.5333659,
|
||||
0.5667318, 0.60009766, 0.60009766, 0.60009766],
|
||||
[0.5, 0.5333116, 0.5666233, 0.59993494, 0.6333008,
|
||||
0.66666675, 0.7000326, 0.7000326, 0.7000326],
|
||||
[0.60009766, 0.633355, 0.66661245, 0.6998698, 0.7332357,
|
||||
0.7666016, 0.79996747, 0.79996747, 0.79996747],
|
||||
[0.7001953, 0.73339844, 0.76660156, 0.7998047, 0.8331706,
|
||||
0.8665365, 0.89990234, 0.89990234, 0.89990234],
|
||||
[0.7001953, 0.73339844, 0.76660156, 0.7998047, 0.8331706,
|
||||
0.8665365, 0.89990234, 0.89990234, 0.89990234],
|
||||
[0.7001953, 0.73339844, 0.76660156, 0.7998047, 0.8331706,
|
||||
0.8665365, 0.89990234, 0.89990234, 0.89990234]]]]).astype(np.float32))
|
||||
expected_output = Tensor(np.array([[[[0.1, 0.1333, 0.1666, 0.2, 0.2333, 0.2666, 0.3, 0.3, 0.3],
|
||||
[0.2, 0.2333, 0.2666, 0.2998, 0.3333, 0.3667, 0.4, 0.4, 0.4],
|
||||
[0.2998, 0.3333, 0.3667, 0.4, 0.433, 0.4666, 0.5, 0.5, 0.5],
|
||||
[0.4, 0.433, 0.4666, 0.5, 0.533, 0.5664, 0.6, 0.6, 0.6],
|
||||
[0.5, 0.533, 0.5664, 0.5996, 0.6333, 0.6665, 0.6997, 0.6997, 0.6997],
|
||||
[0.6, 0.6333, 0.6665, 0.6997, 0.733, 0.766, 0.8, 0.7993, 0.8],
|
||||
[0.7, 0.7334, 0.7666, 0.8, 0.833, 0.866, 0.9, 0.8994, 0.8994],
|
||||
[0.7, 0.7334, 0.7666, 0.8, 0.833, 0.866, 0.8994, 0.8994, 0.8994],
|
||||
[0.7, 0.7334, 0.7666, 0.8, 0.8325, 0.866,
|
||||
0.8994, 0.8994, 0.8994]]]]).astype(np.float16))
|
||||
error = np.ones(shape=[9, 9]) * 1.0e-6
|
||||
diff = output.asnumpy() - expected_output.asnumpy()
|
||||
assert np.all(abs(diff) < error)
|
||||
|
|
@ -66,7 +58,7 @@ def test_resize_nn_grayscale_integer_ratio_half(datatype=np.float16):
|
|||
# smaller h and w
|
||||
resize_nn = NetResizeBilinear((1, 1))
|
||||
output = resize_nn(input_tensor)
|
||||
expected_output = Tensor(np.array([[[[0.09997559]]]]).astype(np.float32))
|
||||
expected_output = Tensor(np.array([[[[0.1]]]]).astype(np.float16))
|
||||
error = np.ones(shape=[1, 1]) * 1.0e-6
|
||||
diff = output.asnumpy() - expected_output.asnumpy()
|
||||
assert np.all(abs(diff) < error)
|
||||
|
|
@ -75,7 +67,7 @@ def test_resize_nn_grayscale_integer_ratio_half(datatype=np.float16):
|
|||
resize_nn = NetResizeBilinear((1, 6))
|
||||
output = resize_nn(input_tensor)
|
||||
expected_output = Tensor(
|
||||
np.array([[[[0.09997559, 0.14996338, 0.19995117, 0.25, 0.30004883, 0.30004883]]]]).astype(np.float32))
|
||||
np.array([[[[0.1, 0.1499, 0.2, 0.25, 0.3, 0.3]]]]).astype(np.float16))
|
||||
error = np.ones(shape=[1, 6]) * 1.0e-6
|
||||
diff = output.asnumpy() - expected_output.asnumpy()
|
||||
assert np.all(abs(diff) < error)
|
||||
|
|
@ -84,8 +76,12 @@ def test_resize_nn_grayscale_integer_ratio_half(datatype=np.float16):
|
|||
resize_nn = NetResizeBilinear((6, 1))
|
||||
output = resize_nn(input_tensor)
|
||||
expected_output = Tensor(
|
||||
np.array([[[[0.09997559], [0.24993896], [0.39990234], [0.5500488], [0.7001953], [0.7001953]]]]).astype(
|
||||
np.float32))
|
||||
np.array([[[[0.1],
|
||||
[0.25],
|
||||
[0.4],
|
||||
[0.55],
|
||||
[0.7],
|
||||
[0.7]]]]).astype(np.float16))
|
||||
error = np.ones(shape=[6, 1]) * 1.0e-6
|
||||
diff = output.asnumpy() - expected_output.asnumpy()
|
||||
assert np.all(abs(diff) < error)
|
||||
|
|
@ -94,7 +90,7 @@ def test_resize_nn_grayscale_integer_ratio_half(datatype=np.float16):
|
|||
resize_nn = NetResizeBilinear((1, 3))
|
||||
output = resize_nn(input_tensor)
|
||||
expected_output = Tensor(
|
||||
np.array([[[[0.09997559, 0.19995117, 0.30004883]]]]).astype(np.float32))
|
||||
np.array([[[[0.1, 0.2, 0.3]]]]).astype(np.float16))
|
||||
error = np.ones(shape=[1, 3]) * 1.0e-6
|
||||
diff = output.asnumpy() - expected_output.asnumpy()
|
||||
assert np.all(abs(diff) < error)
|
||||
|
|
@ -102,12 +98,12 @@ def test_resize_nn_grayscale_integer_ratio_half(datatype=np.float16):
|
|||
# larger h, same w
|
||||
resize_nn = NetResizeBilinear((6, 3))
|
||||
output = resize_nn(input_tensor)
|
||||
expected_output = Tensor(np.array([[[[0.09997559, 0.19995117, 0.30004883],
|
||||
[0.24993896, 0.3499756, 0.45007324],
|
||||
[0.39990234, 0.5, 0.60009766],
|
||||
[0.5500488, 0.64990234, 0.75],
|
||||
[0.7001953, 0.7998047, 0.89990234],
|
||||
[0.7001953, 0.7998047, 0.89990234]]]]).astype(np.float32))
|
||||
expected_output = Tensor(np.array([[[[0.1, 0.2, 0.3],
|
||||
[0.25, 0.35, 0.4502],
|
||||
[0.4, 0.5, 0.6],
|
||||
[0.55, 0.65, 0.75],
|
||||
[0.7, 0.8, 0.9],
|
||||
[0.7, 0.8, 0.9]]]]).astype(np.float16))
|
||||
error = np.ones(shape=[6, 3]) * 1.0e-6
|
||||
diff = output.asnumpy() - expected_output.asnumpy()
|
||||
assert np.all(abs(diff) < error)
|
||||
|
|
@ -116,7 +112,9 @@ def test_resize_nn_grayscale_integer_ratio_half(datatype=np.float16):
|
|||
resize_nn = NetResizeBilinear((3, 1))
|
||||
output = resize_nn(input_tensor)
|
||||
expected_output = Tensor(
|
||||
np.array([[[[0.09997559], [0.39990234], [0.7001953]]]]).astype(np.float32))
|
||||
np.array([[[[0.1],
|
||||
[0.4],
|
||||
[0.7]]]]).astype(np.float16))
|
||||
error = np.ones(shape=[3, 1]) * 1.0e-6
|
||||
diff = output.asnumpy() - expected_output.asnumpy()
|
||||
assert np.all(abs(diff) < error)
|
||||
|
|
@ -124,12 +122,9 @@ def test_resize_nn_grayscale_integer_ratio_half(datatype=np.float16):
|
|||
# same h, larger w
|
||||
resize_nn = NetResizeBilinear((3, 6))
|
||||
output = resize_nn(input_tensor)
|
||||
expected_output = Tensor(np.array([[[[0.09997559, 0.14996338, 0.19995117, 0.25, 0.30004883,
|
||||
0.30004883],
|
||||
[0.39990234, 0.44995117, 0.5, 0.5500488, 0.60009766,
|
||||
0.60009766],
|
||||
[0.7001953, 0.75, 0.7998047, 0.8498535, 0.89990234,
|
||||
0.89990234]]]]).astype(np.float32))
|
||||
expected_output = Tensor(np.array([[[[0.1, 0.1499, 0.2, 0.25, 0.3, 0.3],
|
||||
[0.4, 0.45, 0.5, 0.55, 0.6, 0.6],
|
||||
[0.7, 0.75, 0.8, 0.8496, 0.9, 0.9]]]]).astype(np.float16))
|
||||
error = np.ones(shape=[3, 6]) * 1.0e-6
|
||||
diff = output.asnumpy() - expected_output.asnumpy()
|
||||
assert np.all(abs(diff) < error)
|
||||
|
|
@ -138,9 +133,9 @@ def test_resize_nn_grayscale_integer_ratio_half(datatype=np.float16):
|
|||
resize_nn = NetResizeBilinear((3, 3))
|
||||
output = resize_nn(input_tensor)
|
||||
expected_output = Tensor(np.array(
|
||||
[[[[0.09997559, 0.19995117, 0.30004883],
|
||||
[0.39990234, 0.5, 0.60009766],
|
||||
[0.7001953, 0.7998047, 0.89990234]]]]).astype(np.float32))
|
||||
[[[[0.1, 0.2, 0.3],
|
||||
[0.4, 0.5, 0.6],
|
||||
[0.7, 0.8, 0.9]]]]).astype(np.float16))
|
||||
error = np.ones(shape=[3, 3]) * 1.0e-6
|
||||
diff = output.asnumpy() - expected_output.asnumpy()
|
||||
assert np.all(abs(diff) < error)
|
||||
|
|
@ -261,20 +256,13 @@ def test_resize_nn_grayscale_not_integer_ratio_half(datatype=np.float16):
|
|||
# larger h and w
|
||||
resize_nn = NetResizeBilinear((7, 7))
|
||||
output = resize_nn(input_tensor)
|
||||
expected_output = Tensor(np.array([[[[0.09997559, 0.15710449, 0.21425085, 0.2714495, 0.3285784,
|
||||
0.38563755, 0.39990234],
|
||||
[0.27141464, 0.3285734, 0.3857422, 0.44294086, 0.5000399,
|
||||
0.55703926, 0.57128906],
|
||||
[0.44285366, 0.5000423, 0.5572336, 0.6144322, 0.67150134,
|
||||
0.7284409, 0.7426758],
|
||||
[0.6142578, 0.50819117, 0.44293588, 0.5001146, 0.5571937,
|
||||
0.6141731, 0.62841797],
|
||||
[0.78564453, 0.4346799, 0.18574369, 0.2428925, 0.3000015,
|
||||
0.3570706, 0.3713379],
|
||||
[0.89990234, 0.3856724, 0.01428223, 0.07141115, 0.12854005,
|
||||
0.18566895, 0.19995117],
|
||||
[0.89990234, 0.3856724, 0.01428223, 0.07141115, 0.12854005,
|
||||
0.18566895, 0.19995117]]]]).astype(np.float32))
|
||||
expected_output = Tensor(np.array([[[[0.1, 0.1571, 0.2142, 0.2715, 0.3286, 0.3857, 0.4],
|
||||
[0.2715, 0.3286, 0.386, 0.443, 0.5, 0.557, 0.5713],
|
||||
[0.4429, 0.5, 0.5576, 0.6147, 0.6714, 0.7285, 0.7427],
|
||||
[0.6143, 0.5083, 0.443, 0.5, 0.557, 0.614, 0.6284],
|
||||
[0.7856, 0.4346, 0.1858, 0.2429, 0.2998, 0.357, 0.3713],
|
||||
[0.8994, 0.3857, 0.014275, 0.0714, 0.1285, 0.1858, 0.2],
|
||||
[0.8994, 0.3857, 0.014275, 0.0714, 0.1285, 0.1857, 0.2]]]]).astype(np.float16))
|
||||
error = np.ones(shape=[7, 7]) * 1.0e-6
|
||||
diff = output.asnumpy() - expected_output.asnumpy()
|
||||
assert np.all(abs(diff) < error)
|
||||
|
|
@ -283,8 +271,8 @@ def test_resize_nn_grayscale_not_integer_ratio_half(datatype=np.float16):
|
|||
resize_nn = NetResizeBilinear((2, 3))
|
||||
output = resize_nn(input_tensor)
|
||||
expected_output = Tensor(
|
||||
np.array([[[[0.09997559, 0.23331706, 0.36661786],
|
||||
[0.6999512, 0.33339438, 0.46661377]]]]).astype(np.float32))
|
||||
np.array([[[[0.1, 0.2333, 0.3667],
|
||||
[0.7, 0.3333, 0.4666]]]]).astype(np.float16))
|
||||
error = np.ones(shape=[2, 3]) * 1.0e-6
|
||||
diff = output.asnumpy() - expected_output.asnumpy()
|
||||
assert np.all(abs(diff) < error)
|
||||
|
|
@ -292,10 +280,8 @@ def test_resize_nn_grayscale_not_integer_ratio_half(datatype=np.float16):
|
|||
# smaller h, larger w
|
||||
resize_nn = NetResizeBilinear((2, 7))
|
||||
output = resize_nn(input_tensor)
|
||||
expected_output = Tensor(np.array([[[[0.09997559, 0.15710449, 0.21425085, 0.2714495, 0.3285784,
|
||||
0.38563755, 0.39990234],
|
||||
[0.6999512, 0.47143552, 0.3143398, 0.37150356, 0.4285976,
|
||||
0.48562187, 0.49987793]]]]).astype(np.float32))
|
||||
expected_output = Tensor(np.array([[[[0.1, 0.1571, 0.2142, 0.2715, 0.3286, 0.3857, 0.4],
|
||||
[0.7, 0.4714, 0.3142, 0.3713, 0.4285, 0.4856, 0.4998]]]]).astype(np.float16))
|
||||
error = np.ones(shape=[2, 7]) * 1.0e-6
|
||||
diff = output.asnumpy() - expected_output.asnumpy()
|
||||
assert np.all(abs(diff) < error)
|
||||
|
|
@ -303,11 +289,11 @@ def test_resize_nn_grayscale_not_integer_ratio_half(datatype=np.float16):
|
|||
# larger h, smaller w
|
||||
resize_nn = NetResizeBilinear((5, 3))
|
||||
output = resize_nn(input_tensor)
|
||||
expected_output = Tensor(np.array([[[[0.09997559, 0.23331706, 0.36661786],
|
||||
[0.33999026, 0.47340494, 0.6066081],
|
||||
[0.5799805, 0.51343584, 0.64660645],
|
||||
[0.8199219, 0.15335283, 0.28662106],
|
||||
[0.89990234, 0.0333252, 0.16662598]]]]).astype(np.float32))
|
||||
expected_output = Tensor(np.array([[[[0.1, 0.2333, 0.3667],
|
||||
[0.34, 0.4731, 0.6064],
|
||||
[0.58, 0.5137, 0.647],
|
||||
[0.82, 0.1533, 0.2866],
|
||||
[0.9, 0.03333, 0.1666]]]]).astype(np.float16))
|
||||
error = np.ones(shape=[5, 3]) * 1.0e-6
|
||||
diff = output.asnumpy() - expected_output.asnumpy()
|
||||
assert np.all(abs(diff) < error)
|
||||
|
|
@ -315,8 +301,8 @@ def test_resize_nn_grayscale_not_integer_ratio_half(datatype=np.float16):
|
|||
# smaller h, same w
|
||||
resize_nn = NetResizeBilinear((2, 4))
|
||||
output = resize_nn(input_tensor)
|
||||
expected_output = Tensor(np.array([[[[0.09997559, 0.19995117, 0.30004883, 0.39990234],
|
||||
[0.6999512, 0.30004883, 0.40008545, 0.49987793]]]]).astype(np.float32))
|
||||
expected_output = Tensor(np.array([[[[0.1, 0.2, 0.3, 0.4],
|
||||
[0.7, 0.3, 0.4001, 0.5]]]]).astype(np.float16))
|
||||
error = np.ones(shape=[2, 4]) * 1.0e-6
|
||||
diff = output.asnumpy() - expected_output.asnumpy()
|
||||
assert np.all(abs(diff) < error)
|
||||
|
|
@ -324,14 +310,14 @@ def test_resize_nn_grayscale_not_integer_ratio_half(datatype=np.float16):
|
|||
# larger h, same w
|
||||
resize_nn = NetResizeBilinear((8, 4))
|
||||
output = resize_nn(input_tensor)
|
||||
expected_output = Tensor(np.array([[[[0.09997559, 0.19995117, 0.30004883, 0.39990234],
|
||||
[0.24998474, 0.3500061, 0.45010376, 0.5498657],
|
||||
[0.3999939, 0.50006104, 0.6001587, 0.6998291],
|
||||
[0.5499878, 0.52508545, 0.62516785, 0.724823],
|
||||
[0.6999512, 0.30004883, 0.40008545, 0.49987793],
|
||||
[0.84991455, 0.07501221, 0.17500305, 0.27493286],
|
||||
[0.89990234, 0., 0.09997559, 0.19995117],
|
||||
[0.89990234, 0., 0.09997559, 0.19995117]]]]).astype(np.float32))
|
||||
expected_output = Tensor(np.array([[[[0.1, 0.2, 0.3, 0.4],
|
||||
[0.25, 0.35, 0.4502, 0.55],
|
||||
[0.4, 0.5, 0.6, 0.6997],
|
||||
[0.55, 0.525, 0.6255, 0.7246],
|
||||
[0.7, 0.3, 0.4001, 0.5],
|
||||
[0.85, 0.075, 0.175, 0.275],
|
||||
[0.9, 0., 0.1, 0.2],
|
||||
[0.9, 0., 0.1, 0.2]]]]).astype(np.float16))
|
||||
error = np.ones(shape=[8, 4]) * 1.0e-6
|
||||
diff = output.asnumpy() - expected_output.asnumpy()
|
||||
assert np.all(abs(diff) < error)
|
||||
|
|
@ -339,9 +325,9 @@ def test_resize_nn_grayscale_not_integer_ratio_half(datatype=np.float16):
|
|||
# same h, smaller w
|
||||
resize_nn = NetResizeBilinear((3, 2))
|
||||
output = resize_nn(input_tensor)
|
||||
expected_output = Tensor(np.array([[[[0.09997559, 0.30004883],
|
||||
[0.5, 0.7001953],
|
||||
[0.89990234, 0.09997559]]]]).astype(np.float32))
|
||||
expected_output = Tensor(np.array([[[[0.1, 0.3],
|
||||
[0.5, 0.7],
|
||||
[0.9, 0.1]]]]).astype(np.float16))
|
||||
error = np.ones(shape=[3, 2]) * 1.0e-6
|
||||
diff = output.asnumpy() - expected_output.asnumpy()
|
||||
assert np.all(abs(diff) < error)
|
||||
|
|
@ -349,12 +335,9 @@ def test_resize_nn_grayscale_not_integer_ratio_half(datatype=np.float16):
|
|||
# same h, larger w
|
||||
resize_nn = NetResizeBilinear((3, 6))
|
||||
output = resize_nn(input_tensor)
|
||||
expected_output = Tensor(np.array([[[[0.09997559, 0.16662598, 0.23331706, 0.30004883, 0.36661786,
|
||||
0.39990234],
|
||||
[0.5, 0.56673175, 0.63346356, 0.7001953, 0.76660156,
|
||||
0.7998047],
|
||||
[0.89990234, 0.2999674, 0.0333252, 0.09997559, 0.16662598,
|
||||
0.19995117]]]]).astype(np.float32))
|
||||
expected_output = Tensor(np.array([[[[0.1, 0.1666, 0.2333, 0.3, 0.3667, 0.4],
|
||||
[0.5, 0.5664, 0.6333, 0.7, 0.7666, 0.8],
|
||||
[0.9, 0.2998, 0.03333, 0.1, 0.1666, 0.2]]]]).astype(np.float16))
|
||||
error = np.ones(shape=[3, 6]) * 1.0e-6
|
||||
diff = output.asnumpy() - expected_output.asnumpy()
|
||||
assert np.all(abs(diff) < error)
|
||||
|
|
@ -362,9 +345,9 @@ def test_resize_nn_grayscale_not_integer_ratio_half(datatype=np.float16):
|
|||
# same w, same h (identity)
|
||||
resize_nn = NetResizeBilinear((3, 4))
|
||||
output = resize_nn(input_tensor)
|
||||
expected_output = Tensor(np.array([[[[0.09997559, 0.19995117, 0.30004883, 0.39990234],
|
||||
[0.5, 0.60009766, 0.7001953, 0.7998047],
|
||||
[0.89990234, 0., 0.09997559, 0.19995117]]]]).astype(np.float32))
|
||||
expected_output = Tensor(np.array([[[[0.1, 0.2, 0.3, 0.4],
|
||||
[0.5, 0.6, 0.7, 0.8],
|
||||
[0.9, 0., 0.1, 0.2]]]]).astype(np.float16))
|
||||
error = np.ones(shape=[3, 4]) * 1.0e-6
|
||||
diff = output.asnumpy() - expected_output.asnumpy()
|
||||
assert np.all(abs(diff) < error)
|
||||
|
|
@ -492,13 +475,12 @@ def test_resize_nn_grayscale_multiple_images_half(datatype=np.float16):
|
|||
|
||||
resize_nn = NetResizeBilinear((2, 6))
|
||||
output = resize_nn(input_tensor)
|
||||
expected_output = Tensor(np.array([[[[0.09997559, 0.14996338, 0.19995117, 0.25, 0.30004883, 0.30004883],
|
||||
[0.5500488, 0.5999756, 0.64990234, 0.6999512, 0.75, 0.75]]],
|
||||
[[[0.39990234, 0.44995117, 0.5, 0.5500488, 0.60009766, 0.60009766],
|
||||
[0.40008545, 0.4499817, 0.49987793, 0.54992676, 0.5999756, 0.5999756]]],
|
||||
[[[0.7001953, 0.75, 0.7998047, 0.8498535, 0.89990234, 0.89990234],
|
||||
[0.24993896, 0.29995728, 0.3499756, 0.4000244, 0.45007324,
|
||||
0.45007324]]]]).astype(np.float32))
|
||||
expected_output = Tensor(np.array([[[[0.1, 0.1499, 0.2, 0.25, 0.3, 0.3],
|
||||
[0.55, 0.5996, 0.65, 0.6997, 0.75, 0.75]]],
|
||||
[[[0.4, 0.45, 0.5, 0.55, 0.6, 0.6],
|
||||
[0.4001, 0.45, 0.5, 0.55, 0.6, 0.6]]],
|
||||
[[[0.7, 0.75, 0.8, 0.8496, 0.9, 0.9],
|
||||
[0.25, 0.2998, 0.35, 0.4, 0.4502, 0.4502]]]]).astype(np.float16))
|
||||
|
||||
error = np.ones(shape=[3, 3, 2, 6]) * 1.0e-6
|
||||
diff = output.asnumpy() - expected_output.asnumpy()
|
||||
|
|
@ -542,18 +524,12 @@ def test_resize_nn_grayscale_align_corners_half(datatype=np.float16):
|
|||
resize_nn = NetResizeBilinear((3, 7))
|
||||
output = resize_nn(input_tensor)
|
||||
|
||||
expected_output_align = Tensor(np.array([[[[0.09997559, 0.14996338, 0.19995117, 0.25, 0.30004883,
|
||||
0.3499756, 0.39990234],
|
||||
[0.2999878, 0.3500061, 0.4000244, 0.45007324, 0.5001221,
|
||||
0.5499878, 0.5998535],
|
||||
[0.5, 0.5500488, 0.60009766, 0.6501465, 0.7001953,
|
||||
0.75, 0.7998047]]]]).astype(np.float32))
|
||||
expected_output = Tensor(np.array([[[[0.09997559, 0.15710449, 0.21425085, 0.2714495, 0.3285784,
|
||||
0.38563755, 0.39990234],
|
||||
[0.36665854, 0.42383394, 0.4810152, 0.53821385, 0.59529626,
|
||||
0.6522624, 0.6665039],
|
||||
[0.5, 0.55719864, 0.61439735, 0.671596, 0.72865516,
|
||||
0.7855748, 0.7998047]]]]).astype(np.float32))
|
||||
expected_output_align = Tensor(np.array([[[[0.1, 0.1499, 0.2, 0.25, 0.3, 0.35, 0.4],
|
||||
[0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.5996],
|
||||
[0.5, 0.55, 0.6, 0.6504, 0.7, 0.75, 0.8]]]]).astype(np.float16))
|
||||
expected_output = Tensor(np.array([[[[0.1, 0.1571, 0.2142, 0.2715, 0.3286, 0.3857, 0.4],
|
||||
[0.3667, 0.4238, 0.481, 0.538, 0.595, 0.6523, 0.6665],
|
||||
[0.5, 0.557, 0.6143, 0.6714, 0.7285, 0.7856, 0.8]]]]).astype(np.float16))
|
||||
|
||||
error = np.ones(shape=[3, 7]) * 1.0e-6
|
||||
diff_align = output_corners_aligned.asnumpy() - expected_output_align.asnumpy()
|
||||
|
|
|
|||
|
|
@ -2180,7 +2180,7 @@ test_case_nn_ops = [
|
|||
('ResizeBilinear', {
|
||||
'block': P.ResizeBilinear((5, 5)),
|
||||
'desc_inputs': [Tensor([[[[1, 2, 3, 4, 5], [1, 2, 3, 4, 5]]]], mstype.float16)],
|
||||
'desc_bprop': [Tensor([[[[1, 2, 3, 4, 5], [1, 2, 3, 4, 5]]]], mstype.float32)]}),
|
||||
'desc_bprop': [Tensor([[[[1, 2, 3, 4, 5], [1, 2, 3, 4, 5]]]], mstype.float16)]}),
|
||||
('ResizeBilinearGrad', {
|
||||
'block': G.ResizeBilinearGrad(),
|
||||
'desc_inputs': [Tensor([[[[1, 2, 3, 4, 5]]]], mstype.float32), Tensor([[[[1, 2, 3, 4, 5]]]], mstype.float32)],
|
||||
|
|
|
|||
Loading…
Reference in New Issue