As a follow up on the issue I created on the coremltools repo, I have tried to debug further based on their feedback:
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?