Keras Learning Model for Android

I am developing a real-time object classification application for Android. First, I created a deep training model using "keras", and I already prepared a model saved as a file "model.h5". I would like to know how I can use this model in android to classify images.

+6
source share
2 answers

You cannot export Keras directly to Android, but you must save the model

  • Configure Tensflow as your Keras backend.

  • Save model values ​​with model.save(filepath)(you've already done this)

Then download it with one of the following solutions:

1. Tensflow

1- Tensorflow

  • keras,

2- Android tenflow. Google, , .

2: Java
1- deeplearning4j java, keras:
2- deeplearning4j Android: , Java.

+7

Keras Tensorflow:

def export_model_for_mobile(model_name, input_node_names, output_node_name):
    tf.train.write_graph(K.get_session().graph_def, 'out', \
        model_name + '_graph.pbtxt')

    tf.train.Saver().save(K.get_session(), 'out/' + model_name + '.chkp')

    freeze_graph.freeze_graph('out/' + model_name + '_graph.pbtxt', None, \
        False, 'out/' + model_name + '.chkp', output_node_name, \
        "save/restore_all", "save/Const:0", \
        'out/frozen_' + model_name + '.pb', True, "")

    input_graph_def = tf.GraphDef()
    with tf.gfile.Open('out/frozen_' + model_name + '.pb', "rb") as f:
        input_graph_def.ParseFromString(f.read())

    output_graph_def = optimize_for_inference_lib.optimize_for_inference(
            input_graph_def, input_node_names, [output_node_name],
            tf.float32.as_datatype_enum)

    with tf.gfile.FastGFile('out/tensorflow_lite_' + model_name + '.pb', "wb") as f:
        f.write(output_graph_def.SerializeToString())

input_nodes_names output_node_names . . tensorflow_lite_. , Android-.

Tensorflow Android TensorFlowInferenceInterface, .

implementation 'org.tensorflow:tensorflow-android:1.5.0'

XOR Github:

https://github.com/OmarAflak/Keras-Android-XOR

+1

Source: https://habr.com/ru/post/1684434/


All Articles