分类C++推断
#pragma once
#define _CRT_SECURE_NO_WARNINGS
#include<torch/torch.h>
#include<torch/script.h>
#include<iostream>
#include <windows.h>
#include <tuple>
#include <string>
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <torch/torch.h>
#include <ATen/Parallel.h>
#include<map>
using namespace std;
using namespace cv;
using namespace torch;
class __declspec(dllexport)Runtime_Classification_new
{
public:
Runtime_Classification_new(const string model_path, int num_threads_, int image_size, int image_channle);
int change_parameters();
int Runing_infer(vector<Mat> &orc_image,vector<float> if_score_limit, vector<vector<float>>&result);
~Runtime_Classification_new();
private:
string model_path;
int image_size;
int image_channle;
int num_threads_;
};
#include "Runtime_Classification_new.h"
static torch::jit::script::Module model_Classification;
static torch::Device device_all_Classification = torch::kCPU;
static void Stringsplit(string str, const char split, vector<string>&res)
{
istringstream iss(str);
string token;
while (getline(iss, token, split))
{
res.push_back(token);
}
}
static vector<string>get_Filepath_many_information(string path)
{
std::vector<std::string> information;
const char* file;
file = path.c_str();
char szDrive[_MAX_DRIVE];
char szDir[_MAX_DIR];
char szFname[_MAX_FNAME];
char szExt[_MAX_EXT];
_splitpath(file, szDrive, szDir, szFname, szExt);
std::string File_name1 = szDrive;
std::string File_name2 = szDir;
std::string File_name3 = szFname;
std::string File_name4 = szExt;
information.push_back(File_name1);
information.