running deploy for regression

70 views
Skip to first unread message

rahim entezari

unread,
Jul 18, 2016, 8:13:28 AM7/18/16
to Caffe Users
I just want to run deploy.prototxt, but I had found some example of classification like this:
How should I run my deploy.prototxt in my regression problem? there is no regression .bin

Message has been deleted

Hossein Hasanpour

unread,
Jul 18, 2016, 2:50:29 PM7/18/16
to Caffe Users
You need to remove the loss layer, so that the last layer would be the fully connected layer. 
this regression example may help you as well 

rahim entezari

unread,
Jul 19, 2016, 2:43:13 AM7/19/16
to Caffe Users
I have already removed the loss layer for deploy.prototxt.
To be clear I am asking for a command(cpp/python code) to run regression. for exapmle the following command runs a classification:
./build/examples/cpp_classification/classification.bin \ models/bvlc_reference_caffenet/deploy.prototxt \ models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel \ data/ilsvrc12/imagenet_mean.binaryproto \ data/ilsvrc12/synset_words.txt \ 

Hossein Hasanpour

unread,
Jul 19, 2016, 4:39:14 AM7/19/16
to Caffe Users
imo, the process is the same, you only need to exclude the classification part, meaning all you need is the Predict() method and the resulting vector. 
you can then use that vector for what ever scenario you'd like. 
std::vector<float> Classifier::Predict(const cv::Mat& img) {
 
Blob<float>* input_layer = net_->input_blobs()[0];
  input_layer
->Reshape(1, num_channels_,
                       input_geometry_
.height, input_geometry_.width);
 
/* Forward dimension change to all layers. */
  net_
->Reshape();

  std
::vector<cv::Mat> input_channels;
 
WrapInputLayer(&input_channels);

 
Preprocess(img, &input_channels);

  net_
->Forward();

 
/* Copy the output layer to a std::vector */
 
Blob<float>* output_layer = net_->output_blobs()[0];
 
const float* begin = output_layer->cpu_data();
 
const float* end = begin + output_layer->channels();
 
return std::vector<float>(begin, end);
}
see 
/* Return the top N predictions. */
std
::vector<Prediction> Classifier::Classify(const cv::Mat& img, int N) {
  std
::vector<float> output = Predict(img);

  N
= std::min<int>(labels_.size(), N);
  std
::vector<int> maxN = Argmax(output, N);
  std
::vector<Prediction> predictions;
 
for (int i = 0; i < N; ++i) {
   
int idx = maxN[i];
    predictions
.push_back(std::make_pair(labels_[idx], output[idx]));
 
}

 
return predictions;
}

all the classify method is doing is accepting a vector from the predict method, and then retrieving the top n results. 
Reply all
Reply to author
Forward
0 new messages