Coder Social home page Coder Social logo

Comments (8)

MatthewARM avatar MatthewARM commented on August 21, 2024

I'm afraid I'm no expert on OpenCV but I think CV_32FC is NHWC, i.e. in memory the data for an RGB image is RGB,RGB,RGB,etc..,

Caffe convolution needs NCHW, in the Caffe documentation this is described as "n * c_i * h_i * w_i" here: http://caffe.berkeleyvision.org/tutorial/layers/convolution.html. I.e. it's a plane of all the R, followed by all the G, then all the B.

So before passing the image data to your model, as well as converting the pixels to 32-bit floating point, you also have to rearrange it into NCHW layout.

For ExecuteNetwork this is done in InferenceTestImage.cpp.

Hope that helps,

Matthew

from armnn.

liviolima80 avatar liviolima80 commented on August 21, 2024

Hi @MatthewARM ,
actually you are right. I changed the organization of input data, but the issue still remains. With further investigation I found that the problem is related to the caffe model. Let you consider the following caffe models, that represent a convolutional net with 3 output classes.

  • model 1: caffe model generated by default Python training
  • model 2: following the suggestion of @TelmoARM in my old thread (#7) is generated in Python as
    import caffe
    net = caffe.Net('model1.prototxt', 'model1.caffemodel', caffe.TEST)
    net.save('model2.caffemodel')

The following are the results for using both the models with a) standard Caffe c++ library and b) armnnCaffeParser with the same input image

a) standard Caffe c++

  • model 1: output probabilities : [1 4.49625e-12 2.43979e-18] -> correct
  • model 2: Armnn Error: Unsupported layer type 'Data' (as reported in old issue 7)

b) armnnCaffeParser

  • model 1: output probabilities : [0.471663 0.248880 0.279457] -> wrong
  • model 2: Armnn Error: [0.471663 0.248880 0.279457] -> wrong

So actually it seems that caffe library and armnn work in the same way but there is still something related to the model. If needed I can provide both the models

from armnn.

MatthewARM avatar MatthewARM commented on August 21, 2024

I'm pretty sure the problem must still be in the processing of the input data. Are you able to run your model through ExecuteNetwork?

from armnn.

liviolima80 avatar liviolima80 commented on August 21, 2024

Hi @MatthewARM ,
I don't think the problem is in the input data since I'm running in the same program the code for Caffe library C++ and for ArmnnCaffeParser. This is what I do:

  • First I build the model for Caffe c++, load the data and run it. I definetly sure that in the Caffe c++ model input data are correctly loaded since I'm succesfully working with it from a while
  • Than I take the vector of input data from Caffe model and I put it as input to Armnn model, I just need to convert from float* to vector

Sorry I've just see that my last msg was wrong. This is the right situation for the results:

a) standard Caffe c++

  • model 1: output probabilities : [1 4.49625e-12 2.43979e-18] -> correct
  • model 2: output probabilities : [0.471663 0.248880 0.279457] -> wrong

b) armnnCaffeParser

  • model 1: Armnn Error: Unsupported layer type 'Data' (as reported in old issue 7)
  • model 2: output probabilities: [0.471663 0.248880 0.279457] -> wrong

As you can see for model2 Caffe c++ and Armnn give the same wrong results

from armnn.

MatthewARM avatar MatthewARM commented on August 21, 2024

If you are getting the same results from Caffe and Armnn, then the problem must be in the input data. Presumably the old 'data' layer was doing some stuff automatically that is not done by the new 'input' layer.

from armnn.

liviolima80 avatar liviolima80 commented on August 21, 2024

Ok @MatthewARM ,
I tried to open an issue on Caffe official repository since I don't have an idea on what has to be modified.

Nevertheless I think that more documentation and example data have to be provided on Armnn repository, since at the moment it is not easy to understand how to correctly use the library

from armnn.

MatthewARM avatar MatthewARM commented on August 21, 2024

Hi @liviolima80,

I agree and we're working on new documentation just as much as we're working on new functionality and performance.

On the subject of examples, in this case the ArmNN runtime is performing as intended as a drop-in replacement for the Caffe runtime, so you should be able to follow a Caffe example. There is also code at https://github.com/ARM-software/ML-examples which has an example use of ArmNN in an MNIST application.

from armnn.

MatthewARM avatar MatthewARM commented on August 21, 2024

HI @liviolima80 I'm closing this issue as it seems the original problem (data layout) has been resolved. if you figure out what the remaining problem is then please do let us know.

from armnn.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.