the gender classification of caffemodel
*Development Environment ︰ Ubuntu 14.04 *
The neural network I use is Lenet , and now I have already trained my caffemodel from my image database.
Next I want to test new data with using caffemodel like this website(http://www.cnblogs.com/denny402/p/5111018.html) , and I read other website's code about testing,but I don't know how to use it , Could anyone help me? below the message is the code and my reference website.
reference website : https://groups.google.com/forum/#!topic/caffe-users/tMwpaf3s8GQ
code
include <cuda_runtime.h>
include <stdio.h>
include <stdlib.h>
include
include
include
include
include
include
include
include
include
include
include <time.h>
include "/home/dkkim930122/caffe-cudnn/include/caffe/caffe.hpp"
include "/home/dkkim930122/caffe-cudnn/include/caffe/util/io.hpp"
include "/home/dkkim930122/caffe-cudnn/include/caffe/blob.hpp"
include "/usr/include/opencv2/core/core.hpp"
include "/usr/include/opencv2/highgui/highgui.hpp"
include "/usr/include/python2.7/Python.h"
using namespace caffe; using namespace std;
int main(int argc, char** argv) { // Set GPU Caffe::set_mode(Caffe::GPU); int device_id = 0; Caffe::SetDevice(device_id); LOG(INFO) << "Using GPU";
// Load net
Net
// Load pre-trained net net.CopyTrainedLayersFrom("/home/dkkim930122/caffe-cudnn/examples/imagenet/caffe_reference_imagenet_model");
// Load image cv::Mat image = cv::imread("/home/dkkim930122/caffe-dev/examples/images/1.jpg"); // or cat.jpg
// Set vector for image vectorcv::Mat imageVector; imageVector.push_back(image); // image is a cv::Mat, as I'm using #1416 //push_back()
// Set vector for label
vector
// Net initialization float loss = 0.0;
shared_ptr<MemoryDataLayer
memory_data_layer = boost::static_pointer_cast<MemoryDataLayer
memory_data_layer->AddMatVector(imageVector,labelVector);
// Run ForwardPrefilled
vector<Blob
// Display result
const shared_ptr<Blob
for (int i = 0 ; i < 3 ; i++) { LOG(INFO) << "Prob" << i << ": " << probs_out[i]; }
LOG(INFO) << "Max element is: " << *max_element(probs_out,probs_out+3);
// Display result2 const float* argmaxs = results[1]->cpu_data();
for (int i = 0; i < results[1]->num(); i++) { for (int j = 0; j < results[1]->height(); j++) { LOG(INFO) << "Image: "<< i << " class:" << argmaxs[i*results[1]->height() + j]; } }
//printf("%d\n",(int)*argmaxs);
return 0; }
sorry my English is not good. if the statement expression is not clear, I will express more clearly.
From https://github.com/BVLC/caffe/blob/master/CONTRIBUTING.md:
Please do not post usage, installation, or modeling questions, or other requests for help to Issues. Use the caffe-users list instead. This helps developers maintain a clear, uncluttered, and efficient view of the state of Caffe.
To @seanbell
Thank you for your suggestion.
I used to ask question in caffe user but no one answered me, so I'm here to ask questions.
Perhaps the way I asked the question, I will try again , thank you.