microsoft / ELL

Embedded Learning Library
https://microsoft.github.io/ELL
Other
2.29k stars 294 forks source link

Documentation seems out-of-date #181

Closed vl-01 closed 5 years ago

vl-01 commented 5 years ago

After compiling a model according the tutorial I have noticed that the line model_Predict(input, predictions); will fail to compile since the signature of model_Predict in my generated model.h is void model_Predict(void* context, double* input0, float* output0); whereas I expected something more like void model_Predict(float*, float*); Have I done something wrong or is the documentation out-of-date?

lovettchris commented 5 years ago

Ah, doc is out of date, sorry. The new "void* context" argument is added to handle the case that you have any "callbacks" from the predict function. The "context" argument is now plumbed through to those callbacks. But for simple predict calls you can simply pass nullptr" for this argument. Now you may also notice the tutorial has been updated to use a new ModelWrapper class that is now generated that makes all this stuff (especially callbacks) even easier.

vl-01 commented 5 years ago

Thanks for the explanation. I think I understand how the callback API is used, but I have a different use case. I'm using one of the pretrained models that I wrapped with wrap.py. I have the image loaded in memory, with the option of RGB or BGR and float* or double* normalized from 0 to 1. What is the minimal way to get a prediction from there? I have tried something like model_Predict(nullptr, (double*)image.data(), (float*)output.data()) but this is giving me nonsense results.

lovettchris commented 5 years ago

Sound like your approach should work. This is what our C++ tutorial is doing, so if this is not working as expected, then we need to check your model, how it was trained, and whether there were any import errors or warnings. Can you share the model, how it was trained, the model architecture, and output from any "import" process you followed? From there we can narrow down what might be the problem here. Typically what we like to do in debugging a new model from here is compare the ELL "Compute" code path on a layer by layer basis with whatever runtime you used to train the model and make sure each layout output matches the expected result. This technique can find a bug in the import process where some node parameter was not copied over correctly to the ELL model. Or if the very first layer doesn't match, perhaps the image preprocessing is wrong (e.g. BGR versus RGB, or scaling the numbers to 0,1 versus some models require that you leave then in byte range 0-255, especially if the model already contains a "scaling" node that does the conversion to 0-1, etc) all depends on how the model was trained and what the set of nodes are that get properly imported to ELL, etc.

vl-01 commented 5 years ago

I'm using the same model as in the tutorial, d_I224x224x3CMCMCMCMCMCMC1AS.ell. I've confirmed that my inputs are normalized and that the image I'm capturing in the pipeline is what I expect. (In this case, I'm testing it with a picture of a coffee mug I found online.) The result is that it is classified as "nematode" always. And sometimes the model reports a very high (1e30+) confidence that it is something called a "Tinca". I see this result no matter what image or video I show. This layer-by-layer debugging sounds promising - how can I get expected layer outputs so that I can compare to what my local model is computing?

lovettchris commented 5 years ago

Does the tutorial.cpp code work for you that is included in the C++ tutorial folder? I just tried the full tutorial steps using this code and the OpenCV 3.4.3 binaries from sourceforge and when I modify the tutorial.cpp to use this static image like this:

cv::Mat photo = GetImageFromFile(argv[1]); 

I see this output: image

vl-01 commented 5 years ago

The tutorial works for me. I'll compare my program to the tutorial more carefully and work out where I'm going wrong. Thanks!