上QQ阅读APP看书,第一时间看更新
Using the retrained models in the sample Android app
To use our retrained Inception v3 model and MobileNet model in Android's TF Classify app is also pretty straightforward. Follow the steps here to test both retrained models:
- Open the sample TensorFlow Android app, located in tensorflow/examples/android, using Android Studio.
- Drag and drop two retrained models, quantized_stripped_dogs_retrained .pb and dog_retrained_mobilenet10_224.pb as well as the label file, dog_retrained_labels.txt to the assets folder of the android app.
- Open the file ClassifierActivity.java, to use the Inception v3 retrained model, and replace the following code:
private static final int INPUT_SIZE = 224; private static final int IMAGE_MEAN = 117; private static final float IMAGE_STD = 1; private static final String INPUT_NAME = "input"; private static final String OUTPUT_NAME = "output";
With these lines:
private static final int INPUT_SIZE = 299; private static final int IMAGE_MEAN = 128; private static final float IMAGE_STD = 128; private static final String INPUT_NAME = "Mul"; private static final String OUTPUT_NAME = "final_result"; private static final String MODEL_FILE = "file:///android_asset/quantized_stripped_dogs_retrained.pb"; private static final String LABEL_FILE = "file:///android_asset/dog_retrained_labels.txt";
- Or, to use the MobileNet retrained model, replace the code with these lines:
private static final int INPUT_SIZE = 224; private static final int IMAGE_MEAN = 128; private static final float IMAGE_STD = 128; private static final String INPUT_NAME = "input"; private static final String OUTPUT_NAME = "final_result"; private static final String MODEL_FILE = "file:///android_asset/dog_retrained_mobilenet10_224.pb"; private static final String LABEL_FILE = "file:///android_asset/dog_retrained_labels.txt";
- Connect an Android device to your computer and run the app on it. Then tap the TF Classify app and point the camera to some dog pictures, and you'll see top results on your screen.
That's all it takes to use the two retrained models in the sample TensorFlow iOS and Android apps. Now that you've seen how to use our retrained models in the sample apps, the next thing you may want to know is how to add TensorFlow to a new or an existing iOS or Android app of your own, so you can start adding the power of AI to your own mobile apps. That's what we'll discuss in detail in the rest of the chapter.