libtorch 分类C++推断

本文介绍如何利用libtorch库在C++环境中进行深度学习模型的分类推断,详细探讨C++代码实现过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

分类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> //GUI
#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;   //首先设置为CPU版本
static void Stringsplit(string str, const char split, vector<string>&res)
{
   
	istringstream iss(str);	// 输入流 	
	string token;			// 接收缓冲区 	
	while (getline(iss, token, split))	// 以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.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

沐雨清风 จุ๊บ

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值