tensorflow - ValueError:未知初始化程序:GlorotUniform
问题描述
我正在尝试将我的模型转换,而不是加载到 CoreML,但它一直给我这个错误,我不知道如何修复它。
这是我的代码:
import keras
import coremltools
import tensorflow as tf
model = tf.keras.models.load_model('machine')
print(model.summary())
output_labels = ['0', '1']
model = coremltools.converters.keras.convert('machine', input_names=
['text'], output_names=['output'])
model.author = 'Aarush'
model.short_description = 'My model'
model.input_description['text'] = 'Takes text as an input'
model.output_description['output'] = 'Prediction of CyberBullying
sentiment'
model.save('xcodeModel.mlmodel')
ERROR:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-62-5bde9de3c9f8> in <module>()
1 output_labels = ['0', '1']
2
----> 3 model = coremltools.converters.keras.convert('machine', input_names=['text'], output_names=['output'])
4
5 model.author = 'Aarush'
21 frames
/usr/local/lib/python3.6/dist-packages/keras/utils/generic_utils.py in deserialize_keras_object(identifier, module_objects, custom_objects, printable_module_name)
138 if cls is None:
139 raise ValueError('Unknown ' + printable_module_name +
--> 140 ': ' + class_name)
141 if hasattr(cls, 'from_config'):
142 custom_objects = custom_objects or {}
ValueError: Unknown initializer: GlorotUniform
附言
我试过做import keras
,而且tf.keras
,createObject
但他们都没有工作。任何帮助将不胜感激。
谢谢
解决方案
转换后的keras
coremltools 只支持keras
模型,不支持tf.keras
. 对于后一个库,您需要使用tensorflow
转换器,并使用以下功能:
coremltools.converters.tensorflow.convert
更多信息在源代码的注释这里。您还需要转换参数,因为它采用模型文件名 (a .h5),而不是模型实例。例如:
import coremltools
from tensorflow.keras.applications import ResNet50
model = coremltools.converters.tensorflow.convert(
'./model.h5',
input_name_shape_dict={'input_1': (1, 224, 224, 3)},
output_feature_names=['Identity']
)
推荐阅读
- mongodb - 在 Github 存储库中使用 MongoDB 连接字符串
- ffmpeg - 如何在没有 CPU 完整解码的情况下从 h264 中提取运动矢量
- amazon-web-services - 亚马逊网络服务。使用哪些?
- mysql - 生成变量的所有组合并插入临时表
- python - Selenium python google地址侧边栏结果
- firebase - 解析触发器时出错:找不到模块“firebase-admin/lib/database”
- javascript - 每秒随机从数组中选择一个新数字
- class - Flutter:将变量从 CLass A 传递到 B 到 C 类
- git - 从 .git 文件夹中删除 index.lock 文件时出现错误 EACCES Permission Denied 问题
- flutter - 在 FlatButton 翻译后 Flutter onPressed 不起作用