caffe图像分类教程_机器视觉-图像分类-深度学习-CAFFE

//当前程序的根目录

string pathRoot =AppDomain.CurrentDomain.BaseDirectory;//demo项目的根目录

string projectPath = Path.Combine(pathRoot, "DemoProject");//图像分类的训练器

Trainer trainer = newTrainer(projectPath);//创建训练数据(首次必须创建,后续可以不再重新创建)

bool bRebuildData = true;if(bRebuildData)

{//分类信息

List listLabel = new List();

listLabel.Add(new LabelInfo() { LabelValue = 0, LabelName = "b黑色"});

listLabel.Add(new LabelInfo() { LabelValue = 1, LabelName = "w白色"});

listLabel.Add(new LabelInfo() { LabelValue = 2, LabelName = "n无螺丝"});//...//存储样本图像的根目录

string imagePath = Path.Combine(pathRoot, "DemoProject", "Images");//将用于训练的图像信息加入到列表中

List listTrain = new List();

listTrain.Add(new ImageSampleInfo() { LabelValue = 0, FileName = "4e1b2156a4d548b690b9630f6ca2f8aa.bmp"});//...//将用于测试的图像信息加入到列表中

List listTest = new List();

listTest.Add(new ImageSampleInfo() { LabelValue = 0, FileName = "0e48c295e2ab4eac85429ba94efa12c7.bmp"});//...//调用创建方法

trainer.CreateImageDataFile(

listLabel,

imagePath,

listTrain,

listTest,false);

}//设置基本参数

trainer.ProjectSettings.resize_width = 71;

trainer.ProjectSettings.resize_height= 71;

trainer.ProjectSettings.gray= true;//...

trainer.SaveProjectSettings();//设置训练参数

trainer.solver_args.max_iter = 10;

trainer.solver_args.snapshot= 10;

trainer.solver_args.type=type.SGD;

trainer.solver_args.solver_mode=solver_mode.CPU;//...

trainer.SaveSolver();//调用训练方法

trainer.Train();//等待训练进程

Thread.Sleep(1000 * 3);string trainProcessName = "caffe";while (true)

{var array =Process.GetProcessesByName(trainProcessName);if (array.Length > 0)

{

Debug.WriteLine($"进程还存在 {trainProcessName}");//Application.DoEvents();

Thread.Sleep(500);

}else{

Debug.WriteLine($"进程已杀死 {trainProcessName}");break;

}

}//end while

MessageBox.Show("训练完成!");

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值