Skip to content

Instantly share code, notes, and snippets.

@shelhamer
Last active August 10, 2017 10:42
Show Gist options
  • Save shelhamer/91eece041c19ff8968ee to your computer and use it in GitHub Desktop.
Save shelhamer/91eece041c19ff8968ee to your computer and use it in GitHub Desktop.
FCN-8s Fully Convolutional Semantic Segmentation on PASCAL-Context
@xjtuljy
Copy link

xjtuljy commented Feb 4, 2016

Hi all, I now try to export the prediction from the FCN using C++ for my project. But I end up with some very strange images.

In my problem I tried to build my own fcn and there are only two classes to segment (0 and 1)

Here is my code to read the output of the forward pass:
////////////////////////////////////////////////////////////////
const vector<Blob>& result = caffe_net.Forward(bottom_vec, &iter_loss); // forward pass
const float
result_vec = result[0]->cpu_data();

// generate prediction from the output vector and store it in Mat
cv::Mat srcC = cv::Mat::zeros(cv::Size(512,384), CV_32FC1);
int nl= srcC.rows;
int nc= srcC.cols;

for (int j=0; j<nl; j++) {
float* data= srcC.ptr(j);
for (int i=0; i<nc; i++) {
if (result_vec[i+j*nc+datum.height()*datum.width()] > result_vec[i+j_nc]);
// compare the value from different classes and generate the prediction
data[i] = 255;
}
}
//////////////////////////////////////////////////////////////////
The output of CNN is in format of const float_, but I don't know whether the data is arranged in c_h_w or w_h_c order for fcn, and due to the wired output Mat I got, I think maybe I did it in the wrong way. Can somebody help with this please?

@arasharchor
Copy link

@shelhamer I want to fine tune fcn8 on a different dataset for predicting flow magnitude map which is gray scale image by doing regression by changing the loss to euclidean and num_outputs of last layer to 1. is that right?
The loss is too high. basically for how many iterations should I set it in this case?
should I first do some changes in solver around your parameters or in this case I should decrease e.g. base_lr because now we are finetuning.

thanks a lot for your help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment