我正在使用 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