Assertion `pred_hnd' failed in MXPredCreate step


#1

Note: Providing complete information in the most concise form is the best way to get help. This issue template serves as the checklist for essential information to most of the technical issues and bug reports. For non-technical issues and feature requests, feel free to present the information in what you believe is the best form.

For Q & A and discussion, please start a discussion thread at https://discuss.mxnet.io

Description

Assertion `pred_hnd’ failed in MXPredCreate step

Environment info (Required)

mxnet==1.3.1, mxnet-cu90=1.3.1, gluonCV=0.4.0
using the pretrained coco models with json and params exported from the python script.

Error Message:

…/models/yolo3_darknet53_coco-symbol.json … 218177 bytes
…/models/yolo3_darknet53_coco-0000.params … 248431467 bytes
yolo_detect: /home/inuyasha/Develop/suyongjian/mxnet/yolo_detector/src/test_new.cpp:79: int main(int, char**): Assertion `pred_hnd’ failed.
Aborted (core dumped)

Minimum reproducible example

(If you are using your own code, please provide a short script that reproduces the error. Otherwise, please provide link to the existing example.)
const std::string json_file = “…/models/yolo3_darknet53_coco-symbol.json”;
const std::string param_file = “…/models/yolo3_darknet53_coco-0000.params”;

BufferFile json_data(json_file);
BufferFile param_data(param_file);

// Parameters
int dev_type = 1;  // 1: cpu, 2: gpu
int dev_id = 0;  // arbitrary.
mx_uint num_input_nodes = 1;  // 1 for feedforward
const char* input_key[1] = {"data"};
const char** input_keys = input_key;

// Image size and channels
int width = 512;
int height = 512;
int channels = 3;

const mx_uint input_shape_indptr[2] = { 0, 4 };
const mx_uint input_shape_data[4] = { 1, static_cast<mx_uint>(channels), static_cast<mx_uint>(height), static_cast<mx_uint>(width)};
PredictorHandle pred_hnd = 0;

if (json_data.GetLength() == 0 || param_data.GetLength() == 0) {
    return -1;
}

// Create Predictor
MXPredCreate((const char*)json_data.GetBuffer(),
             (const char*)param_data.GetBuffer(),
             static_cast<size_t>(param_data.GetLength()),
             dev_type, dev_id, num_input_nodes, input_keys, input_shape_indptr, input_shape_data, &pred_hnd);
assert(pred_hnd);

#2

I have found out that the segment fault happens in code:
g = mxnet::exec::InferShape(std::move(g), std::move(in_shapes), "__shape__");
in MXPredCreatePartialOut function in c_predict_api.cc file, but why?


#3

Hi @eugene,

Unfortunately I’m not too familiar with the C++ API but @leleamol suggested that it’s most likely to do with your input shapes. Are you specifying the input shapes for all the inputs to the model? i.e. for both the input images and the true label (if this is an image classification problem). And are they the correct shapes?


#4

I have meet a similar error. It is fail to initialize the pred_hnd by MXPredCreate funcion.