我正在尝试使用具有以下版本详细信息的 coremltools 转换我的模型
python - 2.7
keras - 2.1.6
Tensorflow - 1.9
和其他相关的依赖项。
这是代码。
import numpy as np
import os
from keras.models import model_from_json
import coremltools
path = os.getcwd()
#path = input("Enter saved model path->")
#path=path.strip()
#Load weights and Models
json_file=open(os.path.join(path,'LMN.json'),'r')
model_json=json_file.read()
model=model_from_json(model_json)
model.load_weights(os.path.join(path,'LMN.h5'))
#model.compile(optimizer='adam',loss='binary_crossentropy',metrics=['accuracy'])
# convert model to Core ML
coreml_model = coremltools.converters.keras.convert(model, input_names='input', output_names='output')
# set general model metadata
coreml_model.author = 'ABC'
coreml_model.license = 'XYZ'
coreml_model.short_description = 'some details'
# set model input information
coreml_model.input_description['input'] = 'some details '
# set model output information
coreml_model.output_description['output'] = 'some details'
f_name, f_ext = os.path.splitext(coreml_model)
coreml_model.save(os.path.join(path,f_name + '.mlmodel'))
获取以下输出,然后在运行要转换的代码时出错
Using TensorFlow backend.
WARNING:root:TensorFlow version 1.9.0 detected. Last version known to be fully compatible is 1.5.0 .
2018-12-10 17:27:34.650748: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
0 : conv2d_input, <keras.engine.topology.InputLayer object at 0x7f4e81179750>
1 : conv2d, <keras.layers.convolutional.Conv2D object at 0x7f4e81179790>
2 : conv2d__activation__, <keras.layers.core.Activation object at 0x7f4e8102de10>
3 : max_pooling2d, <keras.layers.pooling.MaxPooling2D object at 0x7f4e81179950>
4 : conv2d_1, <keras.layers.convolutional.Conv2D object at 0x7f4e81179a90>
5 : conv2d_1__activation__, <keras.layers.core.Activation object at 0x7f4e8102de50>
6 : max_pooling2d_1, <keras.layers.pooling.MaxPooling2D object at 0x7f4e81179990>
7 : conv2d_2, <keras.layers.convolutional.Conv2D object at 0x7f4e8113bdd0>
8 : conv2d_2__activation__, <keras.layers.core.Activation object at 0x7f4e8102df50>
9 : max_pooling2d_2, <keras.layers.pooling.MaxPooling2D object at 0x7f4e8113b510>
10 : conv2d_3, <keras.layers.convolutional.Conv2D object at 0x7f4e810dce90>
11 : conv2d_3__activation__, <keras.layers.core.Activation object at 0x7f4e8102df90>
12 : max_pooling2d_3, <keras.layers.pooling.MaxPooling2D object at 0x7f4e810dcd50>
13 : flatten, <keras.layers.core.Flatten object at 0x7f4e810f4f90>
14 : dense, <keras.layers.core.Dense object at 0x7f4e81102b90>
15 : dense__activation__, <keras.layers.core.Activation object at 0x7f4e8102dfd0>
16 : dense_1, <keras.layers.core.Dense object at 0x7f4f19da8b90>
17 : dense_1__activation__, <keras.layers.core.Activation object at 0x7f4e81037050>
Traceback (most recent call last):
File "ios_conv.py", line 33, in <module>
f_name, f_ext = os.path.splitext(coreml_model)
File "/home/shrivaamit/miniconda3/envs/ios_conv_py2.7/lib/python2.7/posixpath.py", line 98, in splitext
return genericpath._splitext(p, sep, altsep, extsep)
File "/home/shrivaamit/miniconda3/envs/ios_conv_py2.7/lib/python2.7/genericpath.py", line 99, in _splitext
sepIndex = p.rfind(sep)
AttributeError: 'MLModel' object has no attribute 'rfind'
我经历了git并发现了类似的问题,但是我尝试了并且无法修复。需要一些具体帮助。