首页 > 代码库 > caffe使用mnist训练的效果测试
caffe使用mnist训练的效果测试
今天根据网上的文章,训练了一下mnist的数据
效果不是很好
配置的过程参考:
http://www.cnblogs.com/yixuan-xu/p/5858595.html
http://www.cnblogs.com/yixuan-xu/p/5862657.html
其实最后他是用的是classification.exe进行分类
我修改了一个下classification.cpp里面的代码,代码如下:
int main(int argc, char** argv) { /*** if (argc != 6) { std::cerr << "Usage: " << argv[0] << " deploy.prototxt network.caffemodel" << " mean.binaryproto labels.txt img.jpg" << std::endl; return 1; } ::google::InitGoogleLogging(argv[0]); string model_file = argv[1]; string trained_file = argv[2]; string mean_file = argv[3]; string label_file = argv[4]; Classifier classifier(model_file, trained_file, mean_file, label_file); string file = argv[5]; **/ if (argc != 2) { std::cerr << "Usage: " << argv[0] << " deploy.prototxt network.caffemodel" << " mean.binaryproto labels.txt img.jpg" << std::endl; return 1; } ::google::InitGoogleLogging(argv[0]); string model_file = "lenet.prototxt"; string trained_file = "lenet_iter_10000.caffemodel"; string mean_file = "mean.binaryproto"; string label_file = "synset_words.txt"; Classifier classifier(model_file, trained_file, mean_file, label_file); string file = argv[1]; IplImage *image = cvLoadImage(file.c_str()); IplImage *desc; if (!image){ printf(" No image data \n "); return -1; } CvSize sz; sz.width = 28; sz.height = 28; desc = cvCreateImage(sz, image->depth, image->nChannels); cvResize(image, desc, CV_INTER_AREA); cv::Mat imge; imge=cv::cvarrToMat(desc); cv::Mat gray_image; cvtColor(imge, gray_image, CV_BGR2GRAY); imwrite("gray_image.bmp", gray_image); file = "gray_image.bmp"; std::cout << "---------- Prediction for " << file << " ----------" << std::endl; cv::Mat img = cv::imread(file, -1); CHECK(!img.empty()) << "Unable to decode image " << file; std::vector<Prediction> predictions = classifier.Classify(img); /* Print the top N predictions. */ for (size_t i = 0; i < predictions.size(); ++i) { Prediction p = predictions[i]; std::cout << std::fixed << std::setprecision(4) << p.second << " - \"" << p.first << "\"" << std::endl; }}
最后生成的可以执行的文件包如下
博客园这货上传文件容量那么少,只能找度娘了
http://pan.baidu.com/s/1gfcHkhP
直接点击里面的bat就可以查看效果!
caffe使用mnist训练的效果测试
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。