junxigauss commented on issue #7973: C++ demo memory release problem URL: https://github.com/apache/incubator-mxnet/issues/7973#issuecomment-331055050 I create a std::thread to run the demo, the memory release a big part, but left a small part before exit exe but thread end. I try the release function MXNotifyShutdown(), MXPredFree(pred_hnd) both, absolutely didn't work. I believe it was a bug. code as follow: int f() { std::string test_file = "G:/???-9~17.jpg"; //test_file = std::string(argv[1]); // Models path for your model, you have to modify it std::string json_file = "VGG_VOC0712Plus_SSD_512x_16w.json"; std::string param_file = "VGG_VOC0712Plus_SSD_512x_16w.params"; std::string synset_file = "model/Inception/synset.txt"; std::string nd_file = "model/Inception/mean_224.nd"; BufferFile json_data(json_file); BufferFile param_data(param_file); //system("pause"); // Parameters int dev_type = 2; // 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); int image_size = width * height * channels; // Read Mean Data const mx_float* nd_data = NULL; NDListHandle nd_hnd = 0; BufferFile nd_buf(nd_file); if (nd_buf.GetLength() > 0) { mx_uint nd_index = 0; mx_uint nd_len; const mx_uint* nd_shape = 0; const char* nd_key = 0; mx_uint nd_ndim = 0; MXNDListCreate((const char*)nd_buf.GetBuffer(), nd_buf.GetLength(), &nd_hnd, &nd_len); MXNDListGet(nd_hnd, nd_index, &nd_key, &nd_data, &nd_shape, &nd_ndim); } // Read Image Data std::vector<mx_float> image_data = std::vector<mx_float>(image_size); GetImageFile(test_file, image_data.data(), channels, cv::Size(width, height), nd_data); // Set Input Image MXPredSetInput(pred_hnd, "data", image_data.data(), image_size); // Do Predict Forward MXPredForward(pred_hnd); mx_uint output_index = 0; mx_uint *shape = 0; mx_uint shape_len; // Get Output Result MXPredGetOutputShape(pred_hnd, output_index, &shape, &shape_len); size_t size = 1; for (mx_uint i = 0; i < shape_len; ++i) size *= shape[i]; std::vector<float> data(size); MXPredGetOutput(pred_hnd, output_index, &(data[0]), size); // Release NDList if (nd_hnd) MXNDListFree(nd_hnd); // Release Predictor MXPredFree(pred_hnd); MXNotifyShutdown(); // Synset path for your model, you have to modify it std::vector<std::string> synset = LoadSynset(synset_file); // Print Output Data //PrintOutputResult(data, synset); return 0; } #include <thread> int main(int argc, char* argv[]) { std::thread t1(f); t1.detach(); //f(); } ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org
With regards, Apache Git Services