machine-learning - 将 MobileNet 从 Keras 转换为 Tensorflow Lite
问题描述
我正在使用 Keras 2.2.5、Tensorflow 1.15.0,并且我想将 MobileNet 转换为 Tensorflow Lite 以便在颤振应用程序中使用: 我在此链接中的代码
我已经尝试了一切,但仍然卡住了
from keras.layers import DepthwiseConv2D, ReLU
from pathlib import Path
from keras.models import model_from_json
from tensorflow.python.keras.utils.generic_utils import CustomObjectScope
model_architecture = '/content/model_mobilenet.json'
model_weights = '/content/weights-improvement-42-0.03.hdf5'
model_structure = Path(model_architecture).read_text()
with CustomObjectScope({'relu6': ReLU ,'DepthwiseConv2D': DepthwiseConv2D}):
model = model_from_json(model_structure)
model.load_weights(model_weights)
import tensorflow as tf
converter = tf.lite.TFLiteConverter.from_saved_model(model)
tflite_model = converter.convert()
错误是:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-14-136d2dc1e3d0> in <module>()
10
11 with CustomObjectScope({'relu6': ReLU ,'DepthwiseConv2D': DepthwiseConv2D}):
---> 12 model = model_from_json(model_structure)
13 model.load_weights(model_weights)
14
11 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)
165 if fn is None:
166 raise ValueError('Unknown ' + printable_module_name +
--> 167 ':' + function_name)
168 return fn
169 else:
ValueError: Unknown activation function:relu6
解决方案
推荐阅读
- python - django。表单为空字段创建空白对象。如何防止这个/只为填充字段创建对象?
- c++ - 额外资格 C++
- python - 读取 wav 文件时出现 Unicode 解码错误
- sql - 使用PostgreSQL脚本在windows中创建指定目录路径
- lua - Lua 获取文件最后修改时间
- python-3.x - python3正则表达式不将替换限制为仅第一个计数
- r - 如何根据 spearman 计算值
- excel - 更改 Selection.ColumnDifferences 的样式
- flutter - 检查 JSON 在颤动中是否有超过 2 个数组
- r - R:如何用 ggplot2 绘制“时间序列”