Конвертировать Mobil eNet из Кераса в Tensorflow Lite - PullRequest
0 голосов
/ 09 марта 2020

Я использую Keras 2.2.5, Tensorflow 1.15.0 и хочу конвертировать Mobil eNet в 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
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...