The effect
The development of preparation
Tensorflow 2. Tensorflow/Hub 3.Ubuntu 16.04 LTS 4
First, train your own category model with the Hub
① Install Linux. Ubuntu is recommended
② Install Git and clone tensorFlow /hub project
③ Go to the hub project directory, hub/examples/image_retraining
Put your own pictures in your own folder (different categories of pictures in different subdirectories), like animal:
④ Open the command terminal in the image_retraining directory and enter the training command. For details, refer to the documentationThe Hub document
sudo python3 retrain.py --image_dir ./animal \
--tfhub_module https://tfhub.dev/google/imagenet/mobilenet_v1_100_224/feature_vector/1Copy the code
This command is used to produce light cell phone model data, picture size is 224×224, start training as shown below:
Note that before running retrain.py, use PIP to add dependencies.
⑤ Completion of training
The computer/TMP directory will generate the corresponding PB file and labels file, this is the data we need
Second, use AS to develop image recognition applications
① Copy the generated PB file and labels file to the project Assets directory, as follows:
② Add the tensorFlow dependency to the AS project
implementation 'org.tensorflow:tensorflow-android:+'Copy the code
Photo attachment: animal.zip