Ask Your Question
0

How to use BING Objectness with self trained model?

asked 2018-05-25 07:12:29 -0600

Mary-Ann gravatar image

updated 2018-05-28 03:09:54 -0600

Hi, I would like to use the BING Objectness feature with a custom trained model. I am aware, that it is not possible inside of OpenCV, that is why I downloaded the Linux BING Objectness code (https://github.com/torrvision/Objectness) and trained the algorithm by myself. If the training is done, the code creates the following files:

  • Filter.png
  • ObjNessB2W8MAXBGR.idx
  • ObjNessB2W8MAXBGR.wS1
  • ObjNessB2W8MAXBGR.wS2
  • ObjNessB2W8MAXBGR.xN
  • ObjNessB2W8MAXBGR.xP
  • PerImgAll.m
  • PosNeg.m
  • PosNeg.png

and the proposed windows for the test data are also generated in an additional folder "BBoxesB2W8MAXBGR" . I thought I only need to set the training path to the newly generated model files but I get an error:

Can't load model: /ObjNessB2W8MAXBGR.wS1 or /ObjNessB2W8MAXBGR.idx
Can't load model: /ObjNessB2W8HSV.wS1 or /ObjNessB2W8HSV.idx
Can't load model: /ObjNessB2W8I.wS1 or /ObjNessB2W8I.idx

Since the original code managed to create the object proposals I assume, that the model files were generated correctly. But why is OpenCV not able to read them?

Thanks a lot for any help! Mary C:\fakepath\ObjNessB2W8MAXBGR.wS1.png

edit retag flag offensive close merge delete

Comments

hmmm, you mean the code from opencv_contrib/saliency ?

code here expects to read .yml.gz files , like it is here

code here differs, somewhat

berak gravatar imageberak ( 2018-05-25 07:33:27 -0600 )edit
1

Yes, I want to use ObjectnessBing from Saliency

Mary-Ann gravatar imageMary-Ann ( 2018-05-25 07:36:53 -0600 )edit

can you add a .png extension (else you can't upload it) to one of those files, and attach it to your question, please ?

berak gravatar imageberak ( 2018-05-25 08:27:19 -0600 )edit

it expects files like ObjNessB2W8I.wS1.yml.gz or /ObjNessB2W8I.idx.yml.gz , which you don't have.

it seems, you trained a slightly different model, than expected.

berak gravatar imageberak ( 2018-05-28 01:53:01 -0600 )edit
1

Please post your answer again, it was correct and solved my problem!

Mary-Ann gravatar imageMary-Ann ( 2018-05-28 02:55:13 -0600 )edit

apologies, i'm somehow unable to retrieve it again ;(

berak gravatar imageberak ( 2018-05-28 02:58:33 -0600 )edit
1

I will post it then, it can be helpful for someone else too.

Mary-Ann gravatar imageMary-Ann ( 2018-05-28 03:01:25 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-05-28 03:07:56 -0600

Mary-Ann gravatar image

This is actually the answer of @berak, but their post disappeared...

One should only convert the .wS1 (etc) model files into .wS1.yml.gz. It is possible with the following code:

bool matRead(const string& filename, Mat& _M){
    FILE* f = fopen(filename, "rb");
    if (f == NULL)
        return false;
    char buf[8];
    int pre = fread(buf,sizeof(char), 5, f);
    if (strncmp(buf, "CmMat", 5) != 0)  {
        printf("Invalidate CvMat data file %s\n", filename);
        return false;
    }
    int headData[3]; // Width, height, type
    fread(headData, sizeof(int), 3, f);
    Mat M(headData[1], headData[0], headData[2]);
    fread(M.data, sizeof(char), M.step * M.rows, f);
    fclose(f);
    M.copyTo(_M);
    return true;
}

int main(int argc, char**argv) {
    cv::String node = argv[1];
    cv::String ext = argv[2];
    Mat m;
    if (matRead(node + ext, m)) {
        FileStorage fs(node + ext + ".yml.gz", 1);
        fs << node << m;
        fs.release();
        return 0;
    }
    return 1; // fail
}
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-05-25 07:12:29 -0600

Seen: 1,266 times

Last updated: May 28 '18