You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
4.2 KiB

/*
* @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
* @Date: 2024-03-29 11:44:17
* @LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
* @LastEditTime: 2024-03-29 14:35:20
* @FilePath: \dev_uniform_merge_55kg\mpp\sample\Custom_Sample\main_app_hi3559a\mpp\ai_track\ai\use_mnn.hpp
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
#ifndef NNIE_LITE_USE_MNN_HPP
#define NNIE_LITE_USE_MNN_HPP
#include <unistd.h>
#include <vector>
#include <chrono>
#include <memory>
#include <iostream>
#include <string>
#include <sys/time.h>
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include "gd_alg_type.h"
#include "MNN/Interpreter.hpp"
#include "MNN/MNNDefine.h"
#include "MNN/Tensor.hpp"
#include "MNN/ImageProcess.hpp"
#define DEBUG_TMP (0)
#define D_CPU_BIGCORE (1)
using namespace std::chrono;
namespace GUD {
namespace ALG{
class ForwardNet {
public:
explicit ForwardNet();
explicit ForwardNet(const gud_siamrpn_config_t conf);
~ForwardNet();
int net_init(int model_idx, const char* model_path);
int net_deinit(int model_idx);
int clsMnnForward(const float *cmap_data, float* coutput_data, bool dataReady);
int regMnnForward(const float *rmap_data, float* routput_data, bool dataReady);
int updateTwoKernels(const float *ckernel_data, const float *rkernel_data);
int updateTwoMaps(const float *cm_data, const float *rm_data);
void showTensor(MNN::Tensor *TensorIn, int len, int diff);
public:
int Thread2done_;
int InputDataDone_;
int clsForwardDone_;
int regForwardDone_;
int updataCKDone_;
int updataRKDone_;
int updataCMDone_;
int updataRMDone_;
private:
int deviceType_;
bool initialized_;
int numThread_;
int prec_type_;
int clsMpSize_;
int regMpSize_;
int clsOutSize_;
int regOutSize_;
std::string clsKernelName = "clskernel";
std::string clsMapName = "x";
std::string clsOutputName = "55";
std::string regKernelNane = "regkernel";
std::string regMapName = "y";
std::string regOutputName = "53";
std::shared_ptr<MNN::Interpreter> net_interpreter_;
MNN::Session* net_sess_ = nullptr;
MNN::Tensor* input_tensor = nullptr;
std::map<std::string, MNN::Tensor*> inputClsTensor;
std::map<std::string, MNN::Tensor*> inputRegTensor;
std::map<std::string, MNN::Tensor*> input4Tensors;
std::vector<int> InputDim;
//// Edit By YANGXI on 240426 to solve tracker init slow problem
std::vector<int> clsMap_dims_;
std::vector<int> regMap_dims_;
std::vector<int> ck_dims_;
std::vector<int> rk_dims_;
std::vector<int> clsOut_dims_;
std::vector<int> regOut_dims_;
std::shared_ptr<MNN::Interpreter> net_cls_;
MNN::ScheduleConfig MNNconfig_cls_;
char *MnnModel_cls_;
MNN::Session *session_cls_;
std::shared_ptr<MNN::Interpreter> net_reg_;
MNN::ScheduleConfig MNNconfig_reg_;
char *MnnModel_reg_;
MNN::Session *session_reg_;
MNN::Tensor *clsKernelTensor_;
MNN::Tensor *regKernelTensor_;
MNN::Tensor *clsMapTensor_;
MNN::Tensor *regMapTensor_;
MNN::Tensor *clsOutTensor_;
MNN::Tensor *regOutTensor_;
steady_clock::time_point t1_;
steady_clock::time_point t2_;
duration<double> time_span_;
double time_all_ = 0;
};
};
}
#endif //NNIE_LITE_USE_MNN_HPP