CNTK icon indicating copy to clipboard operation
CNTK copied to clipboard

Question about image transformation for CPPEvalClient.cpp

Open sofeikov opened this issue 10 years ago • 8 comments

Hi there,

I'm curently playing with C++ wrapper provided along with sources. What I want to do is to use trained networks within my Matlab scripts so I've created a small mex interface which takes an image as input and return a vector of scores for the image. I'm currently trying this approach on CIFAR-10.

From what I understood from CPPEvalClient.cpp, I have to take care about transforming image given from Matlab to a vector. What I did for MNIST was something like what can be found in attached file in std::vector<float> imageToVector(double *, mwSize, mwSize, mwSize); function. It worked perfectly for grayscale images with 1 channel - I got the same outputs as were given by WRITE command. However, I was unable to workout the way how to properly transform 3-channel image to a vector. The way I tried to do it is described in the same function.

Am I doing something fundamentally wrong?

Thanks in advance

Source: CPPEvalClient.cpp.txt

Config: 01_Conv.cntk.txt 01_Convolution.ndl.txt

Model(remove txt extension): 01_Convolution.txt

sofeikov avatar May 21 '16 17:05 sofeikov

Hi guys,

I was able to resolve the issue. Please, see attached file that allows to run any trained network on both 1-and 3 channel images.

CPPEvalClient.cpp.txt

Basically, the main trick was that image has to be given in BGR format, which I didn't know

Thanks

sofeikov avatar May 23 '16 13:05 sofeikov

Hi Konstantin, Sorry about that - BGR format is an OpenCV legacy which our users (and, frankly, ourselves) often stumble on. While this fact is documented in the source code of ImageReader, there is no mention of it in our Wiki. I'm going to fix it.

Alexey-Kamenev avatar May 23 '16 16:05 Alexey-Kamenev

Hi Alexey,

thanks for the confirmation. Also, if I see that some essential aspects are not covered in the wiki, do I create an issue for that? Or how do I notify you about this kind of problems? I know it is an offtopic, but still...

Thanks, Konstantin

sofeikov avatar May 23 '16 16:05 sofeikov

Hello Konstantin!

Also, if I see that some essential aspects are not covered in the wiki, do I create an issue for that?

Great idea! Please, go ahead and create an issue - your help is very much appreciated by the whole team.

Thank you, Alexey

alexeyo26 avatar May 23 '16 17:05 alexeyo26

@sofeikov : For images that still need to be transformed into the right size, you may also want to have a look at this StackOverflow question

ant0nsc avatar May 24 '16 14:05 ant0nsc

@ant0nsc to be honest that was the thread that sent me to the right direction :) I've put an upvote there :) Thanks again!

sofeikov avatar May 24 '16 15:05 sofeikov

@sofeikov : Great to hear :-) Is the issue closed now?

ant0nsc avatar May 24 '16 15:05 ant0nsc

@ant0nsc yes, the issue is closed. Thanks

sofeikov avatar May 24 '16 15:05 sofeikov