在CMamke生成的VS项目中插入程序

  1. 在主文件夹的CMakeLists.tex中加入SET(COMPILE_WITH_LSVM OFF CACHE BOOL "Compile with LSVM")

    再添加IF(COMPILE_WITH_LSVM) MESSAGE("Compiling with: LSVM") ADD_DEFINITIONS(-DCOMPILE_WITH_LSVM) ADD_SUBDIRECTORY(LSVM) LIST(APPEND SRC LSVM_wrapper.h LSVM_wrapper.cpp) ENDIF()

之后再按CMake添加程序

把该加的都加进主文件夹和子文件夹中的CMakeLists.tex里

都加好之后再用Cmake congfigure就会出现我们新加的程序,在value列上打上对号,再congfigure

  1. 在VS中添加
    一个头文件:LSVM_wrapper.h
cpp 复制代码
#pragma once

#include "svm_template.h"

class LSVMData : public SvmData
{
public:
    int Load(char *filename, SVM_FILE_TYPE file_type, SVM_DATA_TYPE data_type);
};

class LSVMModel : public SvmModel
{
public:
    int Train(SvmData *data, struct svm_params * params, struct svm_trainingInfo *trainingInfo);
	int StoreModel(char *model_file_name, SVM_MODEL_FILE_TYPE type);
};

和一个源文件:LSVM_wrapper.cpp

cpp 复制代码
#include "ohdSVM_wrapper.h"
#include "OHD-SVM/ohdSVM.h"
#include "utils.h"
#include <string>

extern int g_ws_size;
extern std::string g_imp_spec_arg;

int ohdSVMData::Load(char *filename, SVM_FILE_TYPE file_type, SVM_DATA_TYPE data_type)
{
    svm_memory_dataformat req_data_format;
	req_data_format.allocate_pinned = false;
	req_data_format.allocate_write_combined = false;
	req_data_format.dimAlignment = 32;
	req_data_format.vectAlignment = 32;
	req_data_format.transposed = false;
	req_data_format.labelsInFloat = true;
    req_data_format.supported_types = SUPPORTED_FORMAT_DENSE | SUPPORTED_FORMAT_CSR;  //no sparse yet

	SAFE_CALL(SvmData::Load(filename, file_type, data_type, &req_data_format));//filename=argv[1]=a9a.txt,file_type = LASVM_BINARY

    return SUCCESS;
}

int ohdSVMModel::Train(SvmData *data, struct svm_params * params, struct svm_trainingInfo *trainingInfo)
{
    this->data = data;
    this->params = params;

    alphas = (float *)malloc(data->GetNumVects() * sizeof(float));
	float rho = 0;

    try
    {
		size_t pos = g_imp_spec_arg.find(',');
		if (pos != std::string::npos)
		{
			int sliceSize = atoi(g_imp_spec_arg.c_str());
			int threadsPerRow = atoi(g_imp_spec_arg.c_str() + pos + 1);
			ohdSVM::useEllRT(true, sliceSize, threadsPerRow);
		}

        bool is_sparse = data->GetDataType() == SVM_DATA_TYPE::SPARSE;
		ohdSVM::Data x;
        if (is_sparse)
            x.sparse = (ohdSVM::csr *)data->GetDataSparsePointer();
        else
            x.dense = data->GetDataDensePointer();
		ohdSVM::Train(alphas, &rho, is_sparse, x, (const float *)data->GetVectorLabelsPointer(),
            data->GetNumVects(), data->GetNumVectsAligned(),
            data->GetDimVects(), data->GetDimVectsAligned(),
            params->C, params->gamma, params->eps, g_ws_size);
    }
    catch (std::exception & e)
    {
        std::cerr << "Exception in OHD-SVM: " << e.what() << std::endl;
    }
    params->rho = rho;
    SAFE_CALL(CalculateSupperVectorCounts());

    return SUCCESS;
}

int ohdSVMModel::StoreModel(char *model_file_name, SVM_MODEL_FILE_TYPE type)
{
    return StoreModelGeneric(model_file_name, type);
}
  1. 在svm-train.cpp中加入
cpp 复制代码
#ifdef COMPILE_WITH_LSVM
#include "LSVM_wrapper.h"
#endif

添加

cpp 复制代码
	#ifdef COMPILE_WITH_LSVM
	case 17:
		printf("Using LSVM...\n\n");
		data = new LSVMData;
		model = new LSVMModel;
		return SUCCESS;
#endif
相关推荐
天选之女wow13 分钟前
【Hard——Day4】25.K 个一组翻转链表
数据结构·算法·leetcode·链表
java1234_小锋1 小时前
[免费]基于python的Flask+Vue医疗疾病数据分析大屏可视化系统(机器学习随机森林算法+requests)【论文+源码+SQL脚本】
python·机器学习·数据分析·flask·疾病数据分析
余俊晖1 小时前
英伟达开源多模态视觉语言模型-Nemotron Nano V2 VL模型架构、训练方法、训练数据
人工智能·算法·语言模型·自然语言处理·多模态
2501_941111461 小时前
C++中的原型模式
开发语言·c++·算法
高洁011 小时前
国内外具身智能VLA模型深度解析(2)国外典型具身智能VLA架构
深度学习·算法·aigc·transformer·知识图谱
一只会写代码的猫1 小时前
C# 性能优化:从垃圾回收到多线程并发
jvm·算法
学生小羊2 小时前
A. C05.L08.贪心算法入门
算法·贪心算法
AndrewHZ2 小时前
【图像处理基石】图像连通域计算:原理、算法实现与应用全解析
图像处理·算法·计算机视觉·cv·算法原理·视觉算法·连通域计算
权泽谦2 小时前
Java 在机器学习中的应用:基于 DL4J 与 Weka 的完整实战案例
java·机器学习·数据挖掘
Dev7z3 小时前
基于Matlab遗传算法与蚁群算法的风光储并网微电网容量优化研究
算法·matlab·蚁群算法·多能源微电网