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

Error when converting keras model #2

Closed paullee2018 closed 5 years ago

paullee2018 commented 5 years ago

Hi,

I am trying to convert a keras model but getting the following error message.

AssertionError: Unsupported layer type: Conv2D

My code is below and I print the summary of the model.

Regards Paul

from keras.models import load_model

model = load_model('bayer_1000_BS4_56_56_2.model')

#save model
from keras2cpp import export_model
export_model(model, 'example.model')
Layer (type)                 Output Shape              Param #
=================================================================
conv2d_1 (Conv2D)            (None, 56, 56, 64)        640
_________________________________________________________________
batch_normalization_1 (Batch (None, 56, 56, 64)        256
_________________________________________________________________
activation_1 (Activation)    (None, 56, 56, 64)        0
_________________________________________________________________
max_pooling2d_1 (MaxPooling2 (None, 28, 28, 64)        0
_________________________________________________________________
conv2d_2 (Conv2D)            (None, 28, 28, 32)        18464
_________________________________________________________________
batch_normalization_2 (Batch (None, 28, 28, 32)        128
_________________________________________________________________
activation_2 (Activation)    (None, 28, 28, 32)        0
_________________________________________________________________
conv2d_3 (Conv2D)            (None, 28, 28, 64)        18496
_________________________________________________________________
batch_normalization_3 (Batch (None, 28, 28, 64)        256
_________________________________________________________________
activation_3 (Activation)    (None, 28, 28, 64)        0
_________________________________________________________________
max_pooling2d_2 (MaxPooling2 (None, 14, 14, 64)        0
_________________________________________________________________
conv2d_4 (Conv2D)            (None, 14, 14, 32)        18464
_________________________________________________________________
batch_normalization_4 (Batch (None, 14, 14, 32)        128
_________________________________________________________________
activation_4 (Activation)    (None, 14, 14, 32)        0
_________________________________________________________________
max_pooling2d_3 (MaxPooling2 (None, 7, 7, 32)          0
_________________________________________________________________
conv2d_5 (Conv2D)            (None, 7, 7, 16)          4624
_________________________________________________________________
batch_normalization_5 (Batch (None, 7, 7, 16)          64
_________________________________________________________________
activation_5 (Activation)    (None, 7, 7, 16)          0
_________________________________________________________________
conv2d_6 (Conv2D)            (None, 7, 7, 32)          4640
_________________________________________________________________
batch_normalization_6 (Batch (None, 7, 7, 32)          128
_________________________________________________________________
activation_6 (Activation)    (None, 7, 7, 32)          0
_________________________________________________________________
conv2d_7 (Conv2D)            (None, 7, 7, 16)          4624
_________________________________________________________________
batch_normalization_7 (Batch (None, 7, 7, 16)          64
_________________________________________________________________
activation_7 (Activation)    (None, 7, 7, 16)          0
_________________________________________________________________
max_pooling2d_4 (MaxPooling2 (None, 3, 3, 16)          0
_________________________________________________________________
flatten_1 (Flatten)          (None, 144)               0
_________________________________________________________________
dense_1 (Dense)              (None, 3)                 435
_________________________________________________________________
activation_8 (Activation)    (None, 3)                 0
=================================================================
gosha20777 commented 5 years ago

Thank you! I have fixed it in #ef3ab21. I forgot that Conv2D and Convolution2D are equals.

But in fact, not all layer types are supported yet. Here is a list of all supported layers and activation types. Supported layers:

Supported activation:

Unfortunately keras2cpp is not support BatchNormalization layer and you will get the same error with BatchNormalization...

Create new issue (e.g. Add BatchNormalization support) i'll try to implement this layer into keras2cpp.

You can try to convert this model to tensorfliw, build tf with bezel and try to use it. Or wait for changes :-)