Coremltools: TypeError: Keras layer of type <class 'tensorflow.python.keras.engine.functional.Functional'> is not supported.

Created on 5 Aug 2020  路  14Comments  路  Source: apple/coremltools

## 馃悶Describe the bug

my net:

Model: "functional_1"
Layer (type) Output Shape Param # Connected to
input_1 (InputLayer) [(None, 128, 128, 3) 0


block1_conv1 (Conv2D) (None, 128, 128, 64) 1792 input_1[0][0]


block1_conv2 (Conv2D) (None, 128, 128, 64) 36928 block1_conv1[0][0]


block1_pool (MaxPooling2D) (None, 64, 64, 64) 0 block1_conv2[0][0]


block2_conv1 (Conv2D) (None, 64, 64, 128) 73856 block1_pool[0][0]


block2_conv2 (Conv2D) (None, 64, 64, 128) 147584 block2_conv1[0][0]


block2_pool (MaxPooling2D) (None, 32, 32, 128) 0 block2_conv2[0][0]


block3_conv1 (Conv2D) (None, 32, 32, 256) 295168 block2_pool[0][0]


block3_conv2 (Conv2D) (None, 32, 32, 256) 590080 block3_conv1[0][0]


block3_conv3 (Conv2D) (None, 32, 32, 256) 590080 block3_conv2[0][0]


block3_pool (MaxPooling2D) (None, 16, 16, 256) 0 block3_conv3[0][0]


block4_conv1 (Conv2D) (None, 16, 16, 512) 1180160 block3_pool[0][0]


block4_conv2 (Conv2D) (None, 16, 16, 512) 2359808 block4_conv1[0][0]


block4_conv3 (Conv2D) (None, 16, 16, 512) 2359808 block4_conv2[0][0]


block4_pool (MaxPooling2D) (None, 8, 8, 512) 0 block4_conv3[0][0]


block5_conv1 (Conv2D) (None, 8, 8, 512) 2359808 block4_pool[0][0]


block5_conv2 (Conv2D) (None, 8, 8, 512) 2359808 block5_conv1[0][0]


block5_conv3 (Conv2D) (None, 8, 8, 512) 2359808 block5_conv2[0][0]


block5_pool (MaxPooling2D) (None, 4, 4, 512) 0 block5_conv3[0][0]


flatten (Flatten) (None, 8192) 0 block5_pool[0][0]


dense (Dense) (None, 1024) 8389632 flatten[0][0]


dropout (Dropout) (None, 1024) 0 dense[0][0]


up_sampling2d (UpSampling2D) (None, 12, 12, 512) 0 block5_pool[0][0]


dense_1 (Dense) (None, 1024) 1049600 dropout[0][0]


activation (Activation) (None, 12, 12, 512) 0 up_sampling2d[0][0]


dropout_1 (Dropout) (None, 1024) 0 dense_1[0][0]


conv2d (Conv2D) (None, 10, 10, 1) 4609 activation[0][0]


probabilistic_output (Dense) (None, 5) 5125 dropout_1[0][0]


positional_output (Reshape) (None, 10, 10) 0 conv2d[0][0]

Total params: 24,163,654
Trainable params: 24,163,654
Non-trainable params: 0


Trace

TypeError: Keras layer of type is not supported.

To Reproduce

coreml_model = coremltools.converters.keras.convert('model.h5', input_names=['image'], output_names=['output'],
class_labels=output_labels,
image_input_names='image')

System environment (please complete the following information):

coremltools version 4.0b2
macOS version- 10.15.16
virtualenv
python version 3.8
TensorFlow version 2.3.0
Keras version 2.4.3

bug

Most helpful comment

Since this is using TF 2.x can you try using the Unified Conversion API , ct.convert,
instead of the multi-backend Keras converter , ct.converters.keras.convert.

That is,

tf_keras_model = tf.keras.models.load_model("keras_model.h5")
mlmodel = ct.convert(tf_keras_model)

All 14 comments

I'm also facing this issue. Any updates? You can reproduce this issue by trying to convert https://github.com/notAI-tech/fastPunct

Simply add:
self.model = coremltools.converters.keras.convert(self.model, input_names=['text'], output_names=['output']) self.model.save('punctuation.mlmodel')
at line 173 of fastpunc.py

I鈥檓 also having this issue!

I also have it too.

same issue here

This issue stops me from implementing a great idea.

Can anyone from Apple speak to when this could be investigated in order to support Keras' Functional feature?

Since this is using TF 2.x can you try using the Unified Conversion API , ct.convert,
instead of the multi-backend Keras converter , ct.converters.keras.convert.

That is,

tf_keras_model = tf.keras.models.load_model("keras_model.h5")
mlmodel = ct.convert(tf_keras_model)

Since this is using TF 2.x can you try using the Unified Conversion API , ct.convert,
instead of the multi-backend Keras converter , ct.converters.keras.convert.

That is,

tf_keras_model = tf.keras.models.load_model("keras_model.h5")
mlmodel = ct.convert(tf_keras_model)

Thanks, that's help in my case

Thanks for the tip @aseemw. That fixed this issue but now facing another in as mentioned here 馃槄. We could probably close this one out for now then since this worked for both @dhrebeniuk and me!

Since this is using TF 2.x can you try using the Unified Conversion API , ct.convert,
instead of the multi-backend Keras converter , ct.converters.keras.convert.

That is,

tf_keras_model = tf.keras.models.load_model("keras_model.h5")
mlmodel = ct.convert(tf_keras_model)

which coremodeltools version are you using?
I get the error:

AttributeError: module 'coremltools' has no attribute 'convert'

@pc11000 convert was released in 4.0.2b https://github.com/apple/coremltools/releases/

ok now I get :

TypeError: can't convert expression to float

@pc11000 please search StackOverflow or this GitHub repo for other people facing your new issue. Otherwise, open a new bug report with the required info. This thread is specifically for the issue TypeError: Keras layer of type <class 'tensorflow.python.keras.engine.functional.Functional'> is not supported.

same issue here

Was this page helpful?
0 / 5 - 0 ratings