oramasearch / onnx-go

onnx-go gives the ability to import a pre-trained neural network within Go without being linked to a framework or library.
https://blog.owulveryck.info/2019/04/03/from-a-project-to-a-product-the-state-of-onnx-go.html
MIT License
704 stars 72 forks source link

Failed to infer shape. Op: A × Bᵀ: Inner dimensions do not match up #180

Open Gabrielllopes opened 4 years ago

Gabrielllopes commented 4 years ago

Hello, I'm using my own model and I faced the follow issue while running -> Failed to infer shape. Op: A × Bᵀ: Inner dimensions do not match up

This is the model shape -> (1, 3, 50, 50)

and the error appear when PopulateExprgraph is called

Down bellow is the code


    if _, err := os.Stat(modelfalepath); err != nil && os.IsNotExist(err) {
        //log.Fatalf("%v does not exist", *model)
        //trhow an decent error
    }
    // Create a backend receiver
    backend := gorgonnx.NewGraph()
    // Create a model and set the execution backend
    m := onnx.NewModel(backend)

    // read the onnx model
    b, err := ioutil.ReadFile(modelfalepath)
    if err != nil {
        log.Fatal(err)
    }
    // Decode it into the model
    err = m.UnmarshalBinary(b)
    if err != nil {
        log.Fatal(err)
    }

    m.SetInput(0, toTensor(img))
    // here is the error
    // if I take this if off the error will be displyed on backend.run
    fmt.Print("\n PopulateExprgraph:", backend.PopulateExprgraph())
    err = backend.Run()
    if err != nil {
        log.Fatal(err)
    }
    //m.GetOutputTensors()
    fmt.Print(m.GetOutputTensors())```

There is an way to check in backend the expected shape(or dimension) ?

Cheers for the project is amazing!

Edit:

I found and corrected this error, I had my ONNX in the following format NHWC and this codes expect NCHW (it could be nice if someone implement a flag for that).

But now I face the following probrem -> onnx: operator ReduceMean not implemented ()
owulveryck commented 4 years ago

Cool, that you found the error.

About reduceMean operator, I don’t know if it is easy to implement, I have to look at it.

It is the main problem with this implementation, as there are few contribution, I can hardly follow the development of the main stream.

I am on holiday and i’ll try to have a look. I can also help you if you want to try to implement it by yourself.

Olivier

Gabrielllopes commented 4 years ago

Cheers buddy,

I am trying to implement reduceMean and i did not understand how to take the parameters from the network.

I saw the following code into the resharp implementation:


    n := ns[0]
    children := getOrderedChildren(g.g, n)
    err := checkCondition(children, 2)
    if err != nil {
        return err
    }

    err = a.inferShape(children[1].gorgoniaNode.Value().Data(), children[0].gorgoniaNode.Shape())
    if err != nil {
        return err
    }

my question is how do I know witch parameters the calling for reduce will pass? Like how do I know what is on

children[1].gorgoniaNode.Value().Data()

or

children[0].gorgoniaNode.Shape()