【问题标题】:Issue with Keras model running with TensorFlow for Android使用 TensorFlow for Android 运行的 Keras 模型出现问题
【发布时间】:2017-09-06 15:22:05
【问题描述】:

我尝试用 Keras 训练模型并在 android 上运行。

我的模型(扩展名为 .pb)被正确加载和解析,之后我调用了这个:

tensorFlowInferenceInterface.run(outputNames, true);

之后我遇到了这个问题:

E/TensorFlowInferenceInterface: Failed to run TensorFlow inference with inputs:[main_input], outputs:[action_sm/Relu]
E/TensorflowAndroid: java.lang.IllegalArgumentException: No OpKernel was registered to support Op 'NotEqual' with these attrs.  Registered devices: [CPU], Registered kernels:
                   <no registered kernels>

                     [[Node: NotEqual = NotEqual[T=DT_FLOAT](action_sm_sample_weights, NotEqual/y)]]

我尝试使用最新版本的库 (1.3.1-alpha),但没有帮助。

【问题讨论】:

    标签: android tensorflow keras


    【解决方案1】:

    此代码可以帮助我保存适用于 Android 的模型:

    from keras import backend as K
    from tensorflow.python.framework import graph_util
    
    sess = K.get_session()
    K.set_learning_phase(0)
    constant_graph = graph_util.convert_variables_to_constants(sess, 
        sess.graph.as_graph_def(), outputs)
    
    tf.train.write_graph(constant_graph, out_dir, "model.pb", False)
    

    【讨论】:

      猜你喜欢
      • 2021-05-08
      • 1970-01-01
      • 1970-01-01
      • 2019-10-08
      • 2019-05-14
      • 2022-10-14
      • 2020-07-07
      • 2018-02-05
      • 2017-11-21
      相关资源
      最近更新 更多