Coremltools: tf.unstack causes AttributeError: 'list' object has no attribute 'sym_type'

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

馃悶Describe the bug

  • if tf.unstack is used, coremltools will show AttributeError: 'list' object has no attribute 'sym_type'
  • converter: tensorflow

Trace

鎴湒 2020-08-01 涓嬪崍6 21 57

To Reproduce

  • If a python script can reproduce the error, please paste the code snippet
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")

System environment (please complete the following information):

  • coremltools version (e.g., 3.0b5): 4.0b2
  • OS (e.g., MacOS, Linux): MacOS
  • macOS version (if applicable): Big Sur beta 3
  • XCode version (if applicable): Xcode 11
  • How you install python (anaconda, virtualenv, system): anaconda
  • python version (e.g. 3.7): 3.7
  • any other relevant information:

    • TensorFlow 2.2

bug tf2.x / tf.keras

All 5 comments

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!

Was this page helpful?
0 / 5 - 0 ratings