Inference

View Source On Gitee

Q: When MindSpore 1.3 is installed on the Ascend 310 hardware platform, why an error message is displayed when I run the add_model.py sample in mindspore_serving?

A: Ascend 310 supports model export and Serving inference, but does not support direct inference by using the MindSpore frontend Python script. In the add sample, the code for direct inference by using the MindSpore frontend Python script is added in the export model. You only need to comment out the code in the Ascend 310 scenario.

def export_net():
    """Export add net of 2x2 + 2x2, and copy output model `tensor_add.mindir` to directory ../add/1"""
    x = np.ones([2, 2]).astype(np.float32)
    y = np.ones([2, 2]).astype(np.float32)
    add = Net()
    # Comment out the MindSpore frontend Python script used for direct inference in the Ascend 310 scenario.
    # output = add(ms.Tensor(x), ms.Tensor(y))
    ms.export(add, ms.Tensor(x), ms.Tensor(y), file_name='tensor_add', file_format='MINDIR')
    dst_dir = '../add/1'
    try:
        os.mkdir(dst_dir)
    except OSError:
        pass

    dst_file = os.path.join(dst_dir, 'tensor_add.mindir')
    copyfile('tensor_add.mindir', dst_file)
    print("copy tensor_add.mindir to " + dst_dir + " success")

    print(x)
    print(y)
    # print(output.asnumpy()).

Q: What should I do when an error /usr/bin/ld: warning: libxxx.so, needed by libmindspore.so, not found prompts during application compiling?

A: Find the directory where the missing dynamic library file is located.


Q: After updating MindSpore version, the application compilation reports errors WARNING: Package(s) not found: mindspore-ascend, CMake Error: The following variables are use in this project, but they are set to NOTFOUND. Please set them or make sure they are set and tested correctly in the CMake files: MS_LIB. What should I do?

A: MindSpore 2.0 has unified the installation packages of various platforms and no longer distinguishes different installation packages with suffixes such as -ascend, -gpu, etc. Therefore, the old compilation command or the old build.sh with MINDSPORE_PATH="`pip show mindspore-ascend | grep Location | awk '{print $2"/mindspore"}' | xargs realpath`" needs to be modified to MINDSPORE_PATH="`pip show mindspore | grep Location | awk '{print $2"/mindspore"}' | xargs realpath`".


Q: What should I do when error error while loading shared libraries: libge_compiler.so: cannot open shared object file: No such file or directory prompts during application running?

A: While Ascend 310 AI Processor software packages relied by MindSpore is installed, the CANN package should install the full-featured toolkit version instead of the nnrt version.

Q: How to set high-precision or high-performance mode when performing inference on Ascend 310 AI Processor?

A: Set in the inference code through the SetPrecisionMode interface of AscendDeviceInfo. Optional: force_fp16, allow_fp32_to_fp16, must_keep_origin_dtype, and allow_mix_precision. The default value is force_fp16, which refers to the high-performance mode. High precision mode can be set to allow_fp32_to_fp16 or must_keep_origin_dtype.

Q: How to configure AIPP files?

A: AIPP (artistic intelligence pre-processing) AI preprocessing is used to complete image preprocessing on AI core, including changing image size, color gamut conversion (converting image format), subtracting mean / multiplication coefficient (changing image pixels). Real-time inference is performed after data processing. The related configuration introduction is complex. Please refer to AIPP enable chapter of ATC tool.

Q: How to set the log level in the inferenct process of Ascend 310 AI Processor?

A: Use ASCEND_GLOBAL_LOG_LEVEL to set log level, 0: Debug level; 1: Info level; 2: Warning level; 3: Error level; 4: Null level, no log output; Other values are illegal. Configuration example: export ASCEND_GLOBAL_LOG_LEVEL=1. If there are errors in the inference process, you can modify the log level to obtain more detailed log information.