tf.unstack is used, coremltools will show AttributeError: 'list' object has no attribute 'sym_type'
import tensorflow as tf
import tensorflow.keras.layers as layers
import tensorflow.keras as keras
class stackTest(layers.Layer):
def __init__(self, initializer="he_normal", **kwargs):
super(stackTest, self).__init__(**kwargs)
self.initializer = keras.initializers.get(initializer)
def call(self, inputs):
x1, x2, x3, x4 = tf.unstack(inputs, axis=1)
return tf.stack([x1, x2, x3, x4])
inputT = tf.keras.layers.Input(shape=(1, ))
dense = tf.keras.layers.Dense(4)(inputT)
stack = stackTest()(dense)
model = tf.keras.models.Model(inputs=[inputT], outputs=[stack])
model.summary()
import coremltools as ct
coreml_model = ct.convert(model, source="tensorflow")
From the code, it looks like you created the structure of the Keras model, then didn't compile it or train it and then proceeded to convert the untrained / uncompiled model to a coreml model.
@ryendu It doesn't matter if I compile it or not
The following model isn't compiled but it converts to CoreML model successfully.
import coremltools as ct
import tensorflow as tf
import tensorflow.keras.layers as layers
import tensorflow.keras as keras
inputT = tf.keras.layers.Input(shape=(1, ))
dense = tf.keras.layers.Dense(4)(inputT)
model = tf.keras.models.Model(inputs=[inputT], outputs=[dense])
model.summary()
coreml_model = ct.convert(model, source="tensorflow")
The following model failed even though it has been compiled
import coremltools as ct
import tensorflow as tf
import tensorflow.keras.layers as layers
import tensorflow.keras as keras
class stackTest(layers.Layer):
def __init__(self, initializer="he_normal", **kwargs):
super(stackTest, self).__init__(**kwargs)
self.initializer = keras.initializers.get(initializer)
def call(self, inputs):
x1, x2, x3, x4 = tf.unstack(inputs, axis=1)
return tf.stack([x1, x2, x3, x4])
inputT = tf.keras.layers.Input(shape=(1, ))
dense = tf.keras.layers.Dense(4)(inputT)
stack = stackTest()(dense)
model = tf.keras.models.Model(inputs=[inputT], outputs=[stack])
model.compile(optimizer=tf.keras.optimizers.Adam(0.01))
model.summary()
coreml_model = ct.convert(model, source="tensorflow")
@haifengkao thanks for reporting this bug,
we are looking into it :).
@haifengkao we have fixed this issue and the issue will be addressed in the future release. Thanks :)
Thanks for reporting this issue, this has been fixed in the coremltools==4.0b4 release. Feel free to re-open or create another issue if you're still experiencing issues. Thanks!