⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testpca.cc

📁 torch tracking code, it is a good code
💻 CC
字号:
const char *help = "\testPCA (c) Sebastien Marcel 2003\n\\n\This program projects data into PCA sub-space\n";#include "FileBinDataSet.h"#include "PCATrainer.h"#include "MyMeanVarNorm.h"#include "HistoEqualSmoothImagePreProcessing.h"#include "FileListCmdOption.h"#include "CmdLine.h"using namespace Torch;			int main(int argc, char **argv){  	int n_inputs;  	char *model_file;	bool verbose;	int verbose_level;	bool normalize;	bool image_normalize;	int width, height;	  	Allocator *allocator = new Allocator;  	DiskXFile::setLittleEndianMode();	  	//=================== The command-line ==========================	FileListCmdOption filelist("file name", "the list files or one data file");        filelist.isArgument(true);  	// Construct the command line  	CmdLine cmd;	cmd.setBOption("write log", false);	  	// Put the help line at the beginning  	cmd.info(help);  	cmd.addText("\nArguments:");  	cmd.addSCmdArg("model_file", &model_file, "model file", true);  	cmd.addCmdOption(&filelist);  	cmd.addICmdArg("n_inputs", &n_inputs, "input dimension of the data", true);  	cmd.addText("\nOptions:");  	cmd.addBCmdOption("-normalize", &normalize, false, "centroid normalization", true);  	cmd.addBCmdOption("-verbose", &verbose, false, "verbose", true);  	cmd.addICmdOption("-verbose_level", &verbose_level, 0, "verbose level", true);	cmd.addBCmdOption("-imagenorm", &image_normalize, false, "considers the input pattern as an image and performs a photometric normalization");	cmd.addICmdOption("-width", &width, -1, "width");	cmd.addICmdOption("-height", &height, -1, "height");  	// Read the command line  	cmd.read(argc, argv);	if(image_normalize)	{		print("Perform photometric normalization ...\n");		print("The input pattern is an %dx%d image.\n", width, height);	}			//	if(verbose)	{		print(" + n_filenames = %d\n", filelist.n_files);		for(int i = 0 ; i < filelist.n_files ; i++)			print("   filename[%d] = %s\n", i, filelist.file_names[i]);	}  	//	// The PCA Machine	PCAMachine *pca_machine = NULL;	pca_machine = new(allocator) PCAMachine(n_inputs);	pca_machine->setIOption("verbose_level", verbose_level);	//	PreProcessing *preprocess = NULL;	if(image_normalize)	{		print("Pre-processing image %dx%d ...\n", width, height);		preprocess = new(allocator) HistoEqualSmoothImagePreProcessing(width, height);	}	//	MyMeanVarNorm *mv_norm = NULL;	if(normalize)	{		print("Loading PCA model and its normalisation: %s ...\n", model_file);		mv_norm = new(allocator) MyMeanVarNorm(n_inputs, 1);	   	pca_machine->load(model_file, mv_norm);	}	else	{		print("Loading PCA model: %s ...\n", model_file);		DiskXFile *file = NULL;		file = new DiskXFile(model_file, "r");		pca_machine->loadXFile(file);		delete file;	}		//	pca_machine->setIOption("verbose_level", verbose_level);	pca_machine->setROption("variance", 0.95);	pca_machine->init();	//	// Load all the data in the same dataset    	FileBinDataSet *bindata = new(allocator) FileBinDataSet(filelist.file_names, filelist.n_files, 0.0, n_inputs);	bindata->info(false);		//	real *realinput = NULL;        Sequence *seq;        realinput = new real [n_inputs];        seq = new Sequence(&realinput, 1, n_inputs);		for(int i=0; i< bindata->n_examples; i++)	{		if(verbose) 	   		print("[%d]:\n", i);		//		bindata->setExample(i);				if(verbose) 			print(" Input =   [%2.3f %2.3f %2.3f ...]\n", bindata->inputs->frames[0][0], bindata->inputs->frames[0][1], bindata->inputs->frames[0][2]);		//		bindata->inputs->copyTo(realinput);		if(verbose) 			print(" Seq =     [%2.3f %2.3f %2.3f ...]\n", realinput[0], realinput[1], realinput[2]);		if(image_normalize)			preprocess->preProcessInputs(seq);		if(normalize)			mv_norm->preProcessInputs(seq);		//		pca_machine->forward(seq);					if(verbose) 			print(" Output =   [%2.3f %2.3f %2.3f ...]\n", pca_machine->outputs->frames[0][0], pca_machine->outputs->frames[0][1], pca_machine->outputs->frames[0][2]);	}	//	// Free memory	delete [] realinput;	delete seq;  	delete allocator;  	return(0);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -