我已经使用以下结构在keras中训练了一个模型。
model = Sequential()
model.add(TimeDistributed(Convolution2D(16, 3, 3, border_mode="same", activation='relu'), input_shape=(None, image_height, image_width, 3)))
model.add(TimeDistributed(MaxPooling2D(pool_size=(2, 2))))
model.add(TimeDistributed(Convolution2D(32, 3, 3, activation='relu')))
model.add(TimeDistributed(MaxPooling2D(pool_size=(2, 2))))
model.add(TimeDistributed(Convolution2D(64, 3, 3, activation='relu')))
model.add(TimeDistributed(MaxPooling2D(pool_size=(2, 2))))
model.add(TimeDistributed(Convolution2D(128, 3, 3, activation='relu')))
model.add(TimeDistributed(MaxPooling2D(pool_size=(2, 2))))
model.add(TimeDistributed(Flatten(), name='out1'))
model.add(LSTM(256, name='lstm'))
model.add(Dense(1, activation='sigmoid', name='out'))
该模型很好用,但是我需要将其转换为CoreML。当我尝试以下错误时。
0 : time_distributed_1_input, <keras.engine.topology.InputLayer object at 0x7f05c8711390>
1 : time_distributed_1, <keras.layers.wrappers.TimeDistributed object at 0x7f05c8711450>
Traceback (most recent call last):
File "converter.py", line 92, in <module>
coreml_model = coremltools.converters.keras.convert(loaded_model, input_names=["image"], output_names=["out1"])
File "/usr/local/lib/python2.7/dist-packages/coremltools/converters/keras/_keras_converter.py", line 752, in convert
custom_conversion_functions=custom_conversion_functions)
File "/usr/local/lib/python2.7/dist-packages/coremltools/converters/keras/_keras_converter.py", line 550, in convertToSpec
custom_objects=custom_objects)
File "/usr/local/lib/python2.7/dist-packages/coremltools/converters/keras/_keras2_converter.py", line 311, in _convert
converter_func(builder, layer, input_names, output_names, keras_layer)
File "/usr/local/lib/python2.7/dist-packages/coremltools/converters/keras/_layers2.py", line 284, in convert_convolution
output_blob_shape = list(filter(None, keras_layer.output_shape))
File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 1062, in output_shape
raise AttributeError('The layer has never been called '
AttributeError: The layer has never been called and thus has no defined output shape.
关于如何在iOS中运行此功能的任何想法。我可以用coremltools解决这个问题吗?