[Solved] MindSpore Error: `half_pixel_centers`=True only support in Ascend

1 Error description

1.1 System Environment

Hardware Environment(Ascend/GPU/CPU): CPU
Software Environment:
– MindSpore version (source or binary): 1.8.0
– Python version (e.g., Python 3.7.5): 3.7.6
– OS platform and distribution (e.g., Linux Ubuntu 16.04): Ubuntu 4.15.0-74-generic
– GCC/Compiler version (if compiled from source):

1.2 Basic information

1.2.1 Script

Call the ResizeBilinear operator to adjust the input Tensor to the specified size using bilinear interpolation. The script is as follows:

 01 context.set_context(device_target='CPU')
 02 x = Tensor([[[[1, 2, 3, 4, 5], [1, 2, 3, 4, 5]]]], mindspore.float32)
 03 resize_bilinear = ops.ResizeBilinear((5, 5), half_pixel_centers=True)
 04 output = resize_bilinear(x)
 05 print(output)

1.2.2 Error reporting

The error message here is as follows:

Traceback (most recent call last):
  File "C:/Users/l30026544/PycharmProjects/q2_map/new/ResizeBilinear.py", line 7, in <module>
    resize_bilinear = ops.ResizeBilinear((5, 5), half_pixel_centers=True)
  File "C:\Users\l30026544\PycharmProjects\q2_map\lib\site-packages\mindspore\ops\primitive.py", line 687, in deco
    fn(self, *args, **kwargs)
  File "C:\Users\l30026544\PycharmProjects\q2_map\lib\site-packages\mindspore\ops\operations\nn_ops.py", line 3263, in __init__
    raise ValueError(f"Currently `half_pixel_centers`=True only support in Ascend device_target, "
ValueError: Currently `half_pixel_centers`=True only support in Ascend device_target, but got CPU

Cause Analysis

Let’s look at the error message. In ValueError, write Current  half_pixel_centers=True only support in Ascend device_target, but got CPU, which means that only the half_pixel_centers property can be set to True in the Ascend environment. The official website API explains this:
image.png

2 Solutions

For the reasons known above, it is easy to make the following modifications:

 01 context.set_context(device_target='Ascend')
 02 x = Tensor([[[[1, 2, 3, 4, 5], [1, 2, 3, 4, 5]]]], mindspore.float32)
 03 resize_bilinear = ops.ResizeBilinear((5, 5), half_pixel_centers=True)
 04 output = resize_bilinear(x)
 05 print(output)

At this point, the execution is successful, and the output is as follows:

[[[[1. 2. 3. 4. 5.]
[1. 2. 3. 4. 5.]
[1. 2. 3. 4. 5.]
[1. 2. 3. 4. 5.]
[1. 2. 3. 4. 5.]]]]

3 Summary

Steps to locate the error report:

1. Find the line of user code that reports the error: * resize_bilinear = ops.ResizeBilinear((5, 5), half_pixel_centers=True)*;

2. According to the keywords in the log error message, narrow down the scope of the analysis problem. Currently  half_pixel_centers=True only support in Ascend device_target, but got CPU  ;

Read More:

Leave a Reply

Your email address will not be published. Required fields are marked *