gosha20777 / keras2cpp

it's a small library for running trained Keras 2 models from a native C++ code.
MIT License
183 stars 54 forks source link

Assert error conv2d in dims != weight dims #14

Open eupston opened 4 years ago

eupston commented 4 years ago

hi there,

I'm trying to run your code with my own model. The input shape for my prediction in python's keras is (1, 96, 114, 1), which works fine.

However when I create the same shaped Tensor in c++ and try to run the prediction I get:

ASSERT [src/layers/conv2d.cc:8] 'in.dims_[2] == weights_.dims_[3]' failed

my c++ code is:

int main() {
    auto model = Model::load("example.model");
    Tensor in{1, 96, 114, 1};
    Tensor out = model(in);
    out.print();
    return 0;
}

Any ideas?

SangaRavi commented 4 years ago

Hello,

Were you able to fix this issue? if so can you share the sample code?

Thanks.

abdinf commented 4 years ago

i am facing the same problem , in my python code i use this shape : data=data.reshape((1,28,28,1)) prediction = model.predict(data) and it workds in C++ i write: auto model = Model::load("example.model"); Tensor in{1, 28, 28, 1}; Tensor out = model(in); and i get the same error ? pliz any suggestions

eupston commented 4 years ago

Na I didn't end up solving it sorry. Decided to use: https://github.com/Dobiasd/frugally-deep which did the job for me.

haxsender commented 3 years ago

Hello! Got the same problem when trying to use Conv2D with padding='same'. Solved by seting padding='valid' before training.