TensorFlow Object Detection Starter is a sample project also a guide of how you can train your own data for object detection.
Now we're working on the easiest one, which is called "Image Retraining".
- Install Python 3.6.x (At this moment the Tensorflow does not support Python 3.7.x)
- Install TensorFlow & TensorFlow Hub
pip install tensorflow
pip install tensorflow_hub
Note: if you have seen this kind of error: could not find a version that satisfies the requirement tensorflow
, please Use Python 3.6.x.
- Prepare the images to be trained & verified (tested), please check them here for example, tag the pictures by naming the folders
There is an official tutorial of How to Retrain an Image Classifier for New Categories
python retrain.py --image_dir=samples/retrain/ \
--saved_model_dir=result/saved_model/ \
--output_graph=result/foo.pb \
--output_labels=result/foo.txt \
-—bottleneck_dir=result/bottleneck/ \
--summaries_dir=result/retrain_logs/ \
-—intermediate_output_graphs_dir=result/intermediate_graph/ \
--tfhub_module=https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/1 \
--how_many_training_steps=4000
After running through the training process, you'll get the trained model
(foo.pb), label
(foo.txt) and saved_model
files from the result
folder.
Verify the model with label_image.py
, which comes from the official tensorflow repository, and we only changed the default settings so we don't have to type too many parameters. Check out the original folder here for label_image.py
Execute the label_image.py
:
python label_image.py
And you should see the output something like:
r2d2 0.99754924
bb8 0.0024507595
- There is an official link of Tensorflow TFLite: Introduction to TensorFlow Lite
For the trained data, we can easily use tflite_convert
command like this:
tflite_convert --output_file=result/foo.tflite --input_format=TENSORFLOW_GRAPHDEF --output_format=TFLITE --input_array=Placeholder --output_array=final_result --inference_type=FLOAT --input_data_type=FLOAT --graph_def_file=result/foo.pb