MNN icon indicating copy to clipboard operation
MNN copied to clipboard

fastOnnxTest 成功 但使用时输出不一致

Open anliyuan opened this issue 1 year ago • 0 comments

image

` MNN::ScheduleConfig config; int forward = MNN_FORWARD_CPU; config.type = static_cast<MNNForwardType>(forward);

config.numThread = 1;
MNN::BackendConfig backendConfig;
backendConfig.precision = MNN::BackendConfig::Precision_High;
backendConfig.power = MNN::BackendConfig::Power_High;
backendConfig.memory=MNN::BackendConfig::Memory_High;
    config.backendConfig = &backendConfig;
  std::string sr_mnn_path = "face_landmarks_detector.mnn";

  std::shared_ptr<MNN::Interpreter> sr_interpreter_ =
      std::shared_ptr<MNN::Interpreter>(MNN::Interpreter::createFromFile(sr_mnn_path.c_str()));
  MNN::Session* sr_session_ = sr_interpreter_->createSession(config);
  MNN::Tensor* input_tensor_ = sr_interpreter_->getSessionInput(sr_session_, "input_12");
    cv::Mat img = cv::imread("/Users/admin/Desktop/ppseg/ppseg/test111.jpg");
cv::Mat rect_img;
img.convertTo(rect_img, CV_32FC3);
cv::resize(rect_img, rect_img, cv::Size(256,256));
    rect_img = rect_img/ 255.0f;
    for (int i = 0; i < 256; ++i) {
        cv::Vec3f* ptr = rect_img.ptr<cv::Vec3f>(i);
        for (int j=0;j<256;j++){
            input_tensor_->host<float>()[i*j] = ptr[j][0];
            input_tensor_->host<float>()[i*j+1] = ptr[j][1];
            input_tensor_->host<float>()[i*j+2] = ptr[j][2];
        }
    }

    // 6. 运行会话
input_tensor_->print();
    sr_interpreter_->runSession(sr_session_);
    std::string output_tensor_name0 = "Identity";
MNN::Tensor *tensor_scores = sr_interpreter_->getSessionOutput(sr_session_, output_tensor_name0.c_str());  // output_tensor_name0.c_str()

       MNN::Tensor tensor_scores_host(tensor_scores,
                                      tensor_scores->getDimensionType());
tensor_scores->copyToHostTensor(&tensor_scores_host);
const float *ldmk = tensor_scores_host.host<float>();`

anliyuan avatar May 24 '24 09:05 anliyuan