reshape problem while training

asked 2018-12-24 15:22:15 -0500

manef gravatar image

I want to train my classifier LDA. I followed this link. but my code is crushing with memory exception and send me to this part of the code of reshape image description can't someone help me ?!

cv::Mat image1, flat_image;
    cv::Mat initial_image = cv::imread("D:\mémoire\DB\to use in training\images_sorted\\image1.jpg", 0);
    cv::Mat trainData = initial_image.reshape(1, 1);
    ////// trainData
    for (int i = 2; i < 30; i++)
        std::string filename = "D:\mémoire\DB\to use in training\images_sorted\\image";
        filename = filename + std::to_string(i);
        filename = filename + ".jpg";
        image1 = cv::imread(filename, 0);
        flat_image = image1.reshape(1, 1);
edit retag flag offensive close merge delete


typical noob error. your image did not load (because the single backslashes in the filename) and you never checked the outcome.

DB\to use do you vaguely remember, that \t inserts a TAB ? lol.

berak gravatar imageberak ( 2018-12-24 18:46:54 -0500 )edit

then, no it'll NEVER work like this. the diaretdb images are 5k * 5k , you cannot use those "as is".

paper mentions SLIC clustering in LAB space, and extracting 20 features from each region ..

berak gravatar imageberak ( 2018-12-24 18:58:19 -0500 )edit

it's also no use, loading images as grayscale, when you're looking for yellow dots (exudates)

berak gravatar imageberak ( 2018-12-24 19:07:00 -0500 )edit

thanks for your replays. after applying the SLIC I extract the features so I have to give the classifier the images after applying the SLIC clustering or the original ? her an example of image they are not in the grayscale , the ground truth is color image with 2 value 0 or 255 and i'll use it for TrainLabels example . and sorry i couldn't understoood your seconde replay sorry. and you'r right i don't know how I missed the \ instead of \ -__-

manef gravatar imagemanef ( 2018-12-25 02:41:14 -0500 )edit

I found this answer it's your i think i'll try to correct my code using it answer

manef gravatar imagemanef ( 2018-12-25 02:52:12 -0500 )edit

have a look at the paper, again, please.

you apply ~100 SLIC clusters per image, then you gather ~20 features per cluster, stack them into a single row, and that's what you use for the classification, not the original images.

(i also wonder, how you gather the ground truth data, the supplied xml files are a total mess :\ )

berak gravatar imageberak ( 2018-12-25 02:57:11 -0500 )edit

you have to check:

if (image.empty())
     return; // not loaded

for every imread() call you do.

berak gravatar imageberak ( 2018-12-25 02:59:38 -0500 )edit

just curious, you seem to be at this for quite a while now ;)

any chance, you can actually upload something to your github repos about this, so we can take a look ?

berak gravatar imageberak ( 2018-12-25 07:58:46 -0500 )edit

i had some issue i fixed them and I'm back + i have a professor that want to develop all the paper function in a mobile app and for the training i had to rewrite all my java code to c++ for training and the LDA classifier don't exist in opnecv java he said idk. and after wasting a lot of time he want me now to change to SVM classifier instead of LDA -__-

manef gravatar imagemanef ( 2018-12-25 08:21:24 -0500 )edit

@break sorry for wasting your time but in the training of the SVM. the training Data i have to give to the SVM the image after preprocessing or the train Data is my features extracted from each image ? I'm confused

manef gravatar imagemanef ( 2018-12-27 09:00:29 -0500 )edit