GithubHelp home page GithubHelp logo

Comments (12)

pplonski avatar pplonski commented on July 22, 2024

Hi, yes I want to support multi-input and merge layer. Do you have an example of Keras network that you want to use, a reference would be great.

from keras2cpp.

blackarrow3542 avatar blackarrow3542 commented on July 22, 2024

Hi, thanks for the fast reply!

For example some model with merge layer like resnet and googlenet?
https://github.com/fchollet/keras/blob/master/keras/applications/resnet50.py
https://github.com/fchollet/keras/blob/master/keras/applications/inception_v3.py

from keras2cpp.

spurihwr avatar spurihwr commented on July 22, 2024

Hi, Thanks for the project. I find it quite useful as I am trying to deploy keras model in cpp.
I came across a small bug in your keras_model.cc file in function:
std::vector< std::vector > keras::conv_single_depth_valid(
std::vector< std::vector > const & im,
std::vector< std::vector > const & k)
{}

In the nested loop, a 2 is missing in front of st_x and st_y . It should be something like:
for(unsigned int i = st_x; i < im.size()-2st_x; ++i) {
for(unsigned int j = st_y; j < im[0].size()-2
st_y; ++j) { ....

Thank you so much. I was able to get the correct prediction by changing this.

from keras2cpp.

pplonski avatar pplonski commented on July 22, 2024

Hi @spurihwr ! In conv_single_depth_valid the st_x and st_y values are borders, so you need to add one border at start and one at end, something like thisfor(unsigned int i = st_x; i < im.size()-st_x; ++i) - this is strange, that if you changed this you started to get correct predictions. I'm going to add better testing for dumping, so I'll look closer on in. Could you share your network for testing? (is it large?)

from keras2cpp.

spurihwr avatar spurihwr commented on July 22, 2024

Hi @pplonski !! Thanks for your reply.
Actually, with your original code, there was a segmentation fault and that is because the loop was accessing outside the size of image in
y[i - st_x][j - st_y] += k[k.size() - k1 - 1][k[0].size() - k2 - 1] * im[i - st_x + k1][j - st_y + k2];
With im.size() = 8 and kernal size k1=k2=4, im[i-st_x+k1] goes out of range at i=6.
My network is something like this:
model = Sequential()
model.add(Convolution2D(4, 3, 3, border_mode='valid', input_shape=(1,8,8)))
model.add(Activation('relu'))
model.add(Convolution2D(4, 3, 3, border_mode='valid'))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2,2)))
model.add(Dropout(0.25))
model.add(Flatten())
model.add(Dense(64))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(num_classes))
model.add(Activation('softmax'))

from keras2cpp.

pplonski avatar pplonski commented on July 22, 2024

for kernel size = 4, indeed there can be a problem but kernels are odd (usually, I haven't seen even kernel size ??). So for kernel size = 3, st_ will be 1, and for i=6, im[i-st_x+k1] will be working, and for kernel size = 5, st_x will be 2, and i=6 will be not considered (because border mode is valid). Does it make sense?

from keras2cpp.

spurihwr avatar spurihwr commented on July 22, 2024

Yes. I was initially using a kernal size of 4 which created this problem. As I am new to CNN, I was not aware of this that kernal should be odd. Thank you so much. The code is running fine. I want to use Conv1D for some task. So i will try to implement that as I see that it is not in the code and will update you here abt that. Thanks :)

from keras2cpp.

xdtl avatar xdtl commented on July 22, 2024

Do you have any suggestions for supporting multi-input and merge layer? Thanks!

from keras2cpp.

blackarrow3542 avatar blackarrow3542 commented on July 22, 2024

@xdtl Hi, since keras2cpp doesn't support some neural network models, an alternative solution is to build Tensorflow with makefile to implement a Tensorflow model in an existing c++ project.
https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/makefile

from keras2cpp.

xdtl avatar xdtl commented on July 22, 2024

Thanks for your reply! Does it support Windows?

from keras2cpp.

blackarrow3542 avatar blackarrow3542 commented on July 22, 2024

@xdtl

Maybe you can try this? https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/cmake
And then use TensorFlow with its c++ API https://www.tensorflow.org/api_docs/cc/.

from keras2cpp.

xdtl avatar xdtl commented on July 22, 2024

Thanks! I will look into this...
It would still be great if there is a light weighted framework that can deploy trained Keras models for prediction.

from keras2cpp.

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.