今天根据网上的文章,训练了一下mnist的数据
效果不是很好
配置的过程参考:
http://www.cnblogs.com/yixuan-xu/p/5858595.html
http://www.cnblogs.com/yixuan-xu/p/5862657.html
我修改了一个下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;
}
}
最后生成的可以执行的文件包如下
直接点击里面的bat就可以查看效果!
原文:http://www.cnblogs.com/baldermurphy/p/6522843.html