Tensorflow 2.0 Testing - coremltools - TFlite

77 views
Skip to first unread message

Jan Van de Poel

unread,
Feb 6, 2019, 4:37:03 AM2/6/19
to tes...@tensorflow.org, webp...@google.com
Hi,

I have been playing around with Tensorflow 2.0 on Google Colab, and have tried to convert a model to CoreML (https://github.com/zerotosingularity/tensorflow-20-experiments) which is not working at the moment.

I'm aware this is not a Tensorflow 2.0 specific issue, and I have opened an issue on the Coremltoosl repository: https://github.com/apple/coremltools/issues/323 to track this and wanted to keep you in the loop.

I will try to add TFLite experiments in the coming days, to see how that is working. Any pointers or documentation would be very much appreciated. 

@Paige, not sure if this already qualifies for TF socks, but just so you know, it's a pretty cold winter here as well. :D

All the best from Belgium!

Jan Van de Poel

unread,
Feb 7, 2019, 11:47:19 AM2/7/19
to tes...@tensorflow.org, Paige Bailey
As a follow up on the issue I created on the coremltools repo, I have tried to debug further based on their feedback:
Screen Shot 2019-02-07 at 17.26.21.png

I have updated the Notebook (https://github.com/zerotosingularity/tensorflow-20-experiments/blob/master/convert_to_coreml.ipynb) to be able to switch between keras and tf.keras.

When using Keras instead of tf.keras, this throws an error when creating the model:

AttributeErrorTraceback (most recent call last)
<ipython-input-19-8a7001b9058c> in <module>()
----> 1 model = keras.applications.MobileNetV2(weights='imagenet')

/usr/local/lib/python2.7/dist-packages/keras/applications/__init__.pyc in wrapper(*args, **kwargs)
     26             kwargs['models'] = models
     27             kwargs['utils'] = utils
---> 28         return base_fun(*args, **kwargs)
     29 
     30     return wrapper

/usr/local/lib/python2.7/dist-packages/keras/applications/mobilenet_v2.pyc in MobileNetV2(*args, **kwargs)
      9 @keras_modules_injection
     10 def MobileNetV2(*args, **kwargs):
---> 11     return mobilenet_v2.MobileNetV2(*args, **kwargs)
     12 
     13 

/usr/local/lib/python2.7/dist-packages/keras_applications/mobilenet_v2.pyc in MobileNetV2(input_shape, alpha, include_top, weights, input_tensor, pooling, classes, **kwargs)
    319 
    320     if input_tensor is None:
--> 321         img_input = layers.Input(shape=input_shape)
    322     else:
    323         if not backend.is_keras_tensor(input_tensor):

/usr/local/lib/python2.7/dist-packages/keras/engine/input_layer.pyc in Input(shape, batch_shape, name, dtype, sparse, tensor)
    176                              name=name, dtype=dtype,
    177                              sparse=sparse,
--> 178                              input_tensor=tensor)
    179     # Return tensor including _keras_shape and _keras_history.
    180     # Note that in this case train_output and test_output are the same pointer.

/usr/local/lib/python2.7/dist-packages/keras/legacy/interfaces.pyc in wrapper(*args, **kwargs)
     89                 warnings.warn('Update your `' + object_name + '` call to the ' +
     90                               'Keras 2 API: ' + signature, stacklevel=2)
---> 91             return func(*args, **kwargs)
     92         wrapper._original_function = func
     93         return wrapper

/usr/local/lib/python2.7/dist-packages/keras/engine/input_layer.pyc in __init__(self, input_shape, batch_size, batch_input_shape, dtype, input_tensor, sparse, name)
     37         if not name:
     38             prefix = 'input'
---> 39             name = prefix + '_' + str(K.get_uid(prefix))
     40         super(InputLayer, self).__init__(dtype=dtype, name=name)
     41 

/usr/local/lib/python2.7/dist-packages/keras/backend/tensorflow_backend.pyc in get_uid(prefix)
     72     """
     73     global _GRAPH_UID_DICTS
---> 74     graph = tf.get_default_graph()
     75     if graph not in _GRAPH_UID_DICTS:
     76         _GRAPH_UID_DICTS[graph] = defaultdict(int)

AttributeError: 'module' object has no attribute 'get_default_graph'


Coremltools does not support tf.keras at the moment (v2.1.0). With TF 2.0 in the making, should they? Or should the model creation bug be fixed on the keras side?

Martin Wicke

unread,
Feb 7, 2019, 11:56:26 AM2/7/19
to Jan Van de Poel, Francois Chollet, TensorFlow Community Testing, Paige Bailey
This particular issue (in Keras backend) should probably be fixed in Keras, to make sure that Keras works with TF 2.0. This may already be the case, pending a release, +Francois Chollet would know.

That said, coremltools should really support tf.keras -- it seems to me the only (visible) problem is that they have a type check that throws an error when it sees tf.keras.

--
You received this message because you are subscribed to the Google Groups "TensorFlow Community Testing" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testing+u...@tensorflow.org.

Francois Chollet

unread,
Feb 7, 2019, 12:19:08 PM2/7/19
to Martin Wicke, Jan Van de Poel, TensorFlow Community Testing, Paige Bailey
> make sure that Keras works with TF 2.0. This may already be the case, pending a release

We are actively working on making external Keras TF 2.0-ready, and it should happen before the end of February.

> That said, coremltools should really support tf.keras -- it seems to me the only (visible) problem is that they have a type check that throws an error when it sees tf.keras.

+1, it seems there is no real technical difficulty, and making CoreMLTools compatible with tf.keras should be very easy.

Jan Van de Poel

unread,
Feb 8, 2019, 4:29:54 AM2/8/19
to Francois Chollet, Martin Wicke, TensorFlow Community Testing, Paige Bailey

Thanks for the follow up, would love to test/provide feedback once Keras is ready(-ish) to support TF 2.0.

I'll have a look at the Coremltools repository, hopefully the rabbit hole is not all that deep...
Reply all
Reply to author
Forward
0 new messages