Keras 到 CoreML 值错误:list.remove(x):x 不在列表中
Keras to CoreML value arror: list.remove(x): x not in list
我正在尝试转换我的 Keras 模型(mobilenet + dence 层)。问题是,当我想使用 coremltools 进行转换时,我遇到了以下问题:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-
packages/IPython/core/interactiveshell.py", line 3265, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-4-7905693382e5>", line 1, in <module>
coreml_model = coremltools.converters.keras.convert(loaded_model)
File "/usr/local/lib/python3.6/dist-packages/coremltools/converters/keras/_keras_converter.py", line 752, in convert
custom_conversion_functions=custom_conversion_functions)
File "/usr/local/lib/python3.6/dist-packages/coremltools/converters/keras/_keras_converter.py", line 550, in convertToSpec
custom_objects=custom_objects)
File "/usr/local/lib/python3.6/dist-packages/coremltools/converters/keras/_keras2_converter.py", line 206, in _convert
graph.build()
File "/usr/local/lib/python3.6/dist-packages/coremltools/converters/keras/_topology2.py", line 687, in build
self._remove_old_edges(layer)
File "/usr/local/lib/python3.6/dist-packages/coremltools/converters/keras/_topology2.py", line 429, in _remove_old_edges
self._remove_edge(layer, succ)
File "/usr/local/lib/python3.6/dist-packages/coremltools/converters/keras/_topology2.py", line 365, in _remove_edge
self.edge_map[src].remove(snk)
ValueError: list.remove(x): x not in list
我正在尝试通过以下代码进行此转换:
js_file = open(args.ddir + args.mdl +'.json','r')
loaded_json_model = js_file.read()
js_file.close()
from keras.applications import mobilenet
from keras.utils.generic_utils import CustomObjectScope
from keras.models import model_from_json
with CustomObjectScope({'relu6': mobilenet.mobilenet.relu6}):
loaded_model = model_from_json(loaded_json_model)
loaded_model.load_weights(args.ddir + args.mdl + '.h5')
coreml_model = coremltools.converters.keras.convert(loaded_model,
input_names="image",
image_input_names="image"
)
我通过使用正确版本的 Keras 解决了这个问题,该版本同时包含 Mobilenet(特征提取器)和 "relu6"。唯一对我有用的版本(到目前为止)是版本“2.1.6”。通过这个版本,我成功地进行了转换。
coremltools 目前不支持某些层(包括 relu6)。此问题可以由 "CustomObjectScope" 处理,并在提供的代码中显示。
请注意,应在此版本 (2.1.6) 上再次训练网络。
我正在尝试转换我的 Keras 模型(mobilenet + dence 层)。问题是,当我想使用 coremltools 进行转换时,我遇到了以下问题:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-
packages/IPython/core/interactiveshell.py", line 3265, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-4-7905693382e5>", line 1, in <module>
coreml_model = coremltools.converters.keras.convert(loaded_model)
File "/usr/local/lib/python3.6/dist-packages/coremltools/converters/keras/_keras_converter.py", line 752, in convert
custom_conversion_functions=custom_conversion_functions)
File "/usr/local/lib/python3.6/dist-packages/coremltools/converters/keras/_keras_converter.py", line 550, in convertToSpec
custom_objects=custom_objects)
File "/usr/local/lib/python3.6/dist-packages/coremltools/converters/keras/_keras2_converter.py", line 206, in _convert
graph.build()
File "/usr/local/lib/python3.6/dist-packages/coremltools/converters/keras/_topology2.py", line 687, in build
self._remove_old_edges(layer)
File "/usr/local/lib/python3.6/dist-packages/coremltools/converters/keras/_topology2.py", line 429, in _remove_old_edges
self._remove_edge(layer, succ)
File "/usr/local/lib/python3.6/dist-packages/coremltools/converters/keras/_topology2.py", line 365, in _remove_edge
self.edge_map[src].remove(snk)
ValueError: list.remove(x): x not in list
我正在尝试通过以下代码进行此转换:
js_file = open(args.ddir + args.mdl +'.json','r')
loaded_json_model = js_file.read()
js_file.close()
from keras.applications import mobilenet
from keras.utils.generic_utils import CustomObjectScope
from keras.models import model_from_json
with CustomObjectScope({'relu6': mobilenet.mobilenet.relu6}):
loaded_model = model_from_json(loaded_json_model)
loaded_model.load_weights(args.ddir + args.mdl + '.h5')
coreml_model = coremltools.converters.keras.convert(loaded_model,
input_names="image",
image_input_names="image"
)
我通过使用正确版本的 Keras 解决了这个问题,该版本同时包含 Mobilenet(特征提取器)和 "relu6"。唯一对我有用的版本(到目前为止)是版本“2.1.6”。通过这个版本,我成功地进行了转换。 coremltools 目前不支持某些层(包括 relu6)。此问题可以由 "CustomObjectScope" 处理,并在提供的代码中显示。 请注意,应在此版本 (2.1.6) 上再次训练网络。