AttributeError: объект 'module' не имеет атрибута 'SeparableConv1D' при преобразовании Keras в модель Core ML - PullRequest
0 голосов
/ 07 июня 2019

Я следую учебнику по машинному обучению с Keras и CoreML, и когда я дохожу до того, чтобы запустить следующий код и преобразовать модель Keras в CoreML. Я получаю:

AttributeError: у объекта 'module' нет атрибута 'SeparableConv1D'

где я должен измениться, чтобы решить эту проблему?

Это код, который я запускаю:

output_labels = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']

coreml_mnist = coremltools.converters.keras.convert(
    'best_model.09-0.03.h5', input_names=['image'], output_names=['output'], 
    class_labels=output_labels, image_input_names='image')

и вот что я получаю в деталях:

AttributeError                            Traceback (most recent call last)
<ipython-input-73-8fa50f6bbeb9> in <module>()
     10 coreml_mnist = coremltools.converters.keras.convert(
     11     'best_model.08-0.03.h5', input_names=['image'], output_names=['output'],
---> 12     class_labels=output_labels, image_input_names='image')

/usr/local/lib/python2.7/dist-packages/coremltools/converters/keras/_keras_converter.pyc in convert(model, input_names, output_names, image_input_names, input_name_shape_dict, is_bgr, red_bias, green_bias, blue_bias, gray_bias, image_scale, class_labels, predicted_feature_name, model_precision, predicted_probabilities_output, add_custom_layers, custom_conversion_functions)
    758                       predicted_probabilities_output,
    759                       add_custom_layers,
--> 760                       custom_conversion_functions=custom_conversion_functions)
    761 
    762     return _MLModel(spec)

/usr/local/lib/python2.7/dist-packages/coremltools/converters/keras/_keras_converter.pyc in convertToSpec(model, input_names, output_names, image_input_names, input_name_shape_dict, is_bgr, red_bias, green_bias, blue_bias, gray_bias, image_scale, class_labels, predicted_feature_name, model_precision, predicted_probabilities_output, add_custom_layers, custom_conversion_functions, custom_objects)
    554                                            add_custom_layers=add_custom_layers,
    555                                            custom_conversion_functions=custom_conversion_functions,
--> 556                                            custom_objects=custom_objects)
    557     else:
    558         raise RuntimeError(

/usr/local/lib/python2.7/dist-packages/coremltools/converters/keras/_keras2_converter.pyc in _convert(model, input_names, output_names, image_input_names, input_name_shape_dict, is_bgr, red_bias, green_bias, blue_bias, gray_bias, image_scale, class_labels, predicted_feature_name, predicted_probabilities_output, add_custom_layers, custom_conversion_functions, custom_objects)
    207     # Build network graph to represent Keras model
    208     graph = _topology2.NetGraph(model)
--> 209     graph.build()
    210 
    211     # The graph should be finalized before executing this

/usr/local/lib/python2.7/dist-packages/coremltools/converters/keras/_topology2.pyc in build(self, is_top_level)
    748             self.insert_1d_permute_layers()
    749             self.insert_permute_for_spatial_bn()
--> 750             self.defuse_activation()
    751             self.remove_internal_input_layers()
    752 

/usr/local/lib/python2.7/dist-packages/coremltools/converters/keras/_topology2.pyc in defuse_activation(self)
    508                 isinstance(k_layer, _keras.layers.Conv1D) or
    509                 isinstance(k_layer, _keras.layers.SeparableConv2D) or
--> 510                 isinstance(k_layer, _keras.layers.SeparableConv1D) or
    511                 isinstance(k_layer, _keras.layers.Dense)):
    512 

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

Ответы [ 2 ]

0 голосов
/ 21 июня 2019

У меня была такая же проблема с в этом учебном пособии , и, как другие упоминали, версия keras не поддерживает SeparableConv1D.

Однако, просто обновляя версиюkeras без обновления tensorflow вызвало другие ошибки в ноутбуке jupyter.Мне удалось напрямую установить совместимые версии keras и tensorflow в блокнот jupyter с помощью модуля sys.На момент написания статьи последняя версия keras была 2.2.4, а одна совместимая версия tensorflow (по крайней мере протестирована для данного руководства) - 1.7.0.

Вы можете запустить следующий код Python для установки:

import sys
!{sys.executable} -m pip install tensorflow==1.7.0
!{sys.executable} -m pip install keras==2.2.4
0 голосов
/ 08 июня 2019

Кажется, вы используете версию keras, которая не поддерживается coremltools, так как SeparableConv1D был добавлен позже, чем keras 2.0.6, вы должны обновить keras до последней версии, чтобы это работало.

...