• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# TensorFlow Lite Model Maker
2
3## Overview
4
5The TensorFlow Lite Model Maker library simplifies the process of training a
6TensorFlow Lite model using custom dataset. It uses transfer learning to reduce
7the amount of training data required and shorten the training time.
8
9## Supported Tasks
10
11The Model Maker library currently supports the following ML tasks. Click the
12links below for guides on how to train the model.
13
14Supported Tasks                                                                                                                                                                                                                                                                                                                             | Task Utility
15------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------
16Image Classification: [tutorial](https://www.tensorflow.org/lite/tutorials/model_maker_image_classification), [api](https://www.tensorflow.org/lite/api_docs/python/tflite_model_maker/image_classifier)                                                                                                                                    | Classify images into predefined categories.
17Object Detection: [tutorial](https://www.tensorflow.org/lite/tutorials/model_maker_object_detection), [api](https://www.tensorflow.org/lite/api_docs/python/tflite_model_maker/object_detector)                                                                                                                                             | Detect objects in real time.
18Text Classification: [tutorial](https://www.tensorflow.org/lite/tutorials/model_maker_text_classification), [api](https://www.tensorflow.org/lite/api_docs/python/tflite_model_maker/text_classifier)                                                                                                                                       | Classify text into predefined categories.
19BERT Question Answer: [tutorial](https://www.tensorflow.org/lite/tutorials/model_maker_question_answer), [api](https://www.tensorflow.org/lite/api_docs/python/tflite_model_maker/question_answer)                                                                                                                                          | Find the answer in a certain context for a given question with BERT.
20Audio Classification: [tutorial](https://www.tensorflow.org/lite/tutorials/model_maker_audio_classification), [api](https://www.tensorflow.org/lite/api_docs/python/tflite_model_maker/audio_classifier) | Classify audio into predefined categories.
21Recommendation: [demo](https://github.com/tensorflow/examples/blob/master/tensorflow_examples/lite/model_maker/demo/recommendation_demo.py), [api](https://www.tensorflow.org/lite/api_docs/python/tflite_model_maker/recommendation)                                                                                                       | Recommend items based on the context information for on-device scenario.
22
23If your tasks are not supported, please first use [TensorFlow](https://www.tensorflow.org/guide)
24to retrain a TensorFlow model with transfer learning (following guides like
25[images](https://www.tensorflow.org/tutorials/images/transfer_learning),
26[text](https://www.tensorflow.org/official_models/fine_tuning_bert),
27[audio](https://www.tensorflow.org/tutorials/audio/transfer_learning_audio)) or
28train it from scratch, and then [convert](https://www.tensorflow.org/lite/convert)
29it to TensorFlow Lite model.
30
31## End-to-End Example
32
33Model Maker allows you to train a TensorFlow Lite model using custom datasets in
34just a few lines of code. For example, here are the steps to train an image
35classification model.
36
37```python
38from tflite_model_maker import image_classifier
39from tflite_model_maker.image_classifier import DataLoader
40
41# Load input data specific to an on-device ML app.
42data = DataLoader.from_folder('flower_photos/')
43train_data, test_data = data.split(0.9)
44
45# Customize the TensorFlow model.
46model = image_classifier.create(train_data)
47
48# Evaluate the model.
49loss, accuracy = model.evaluate(test_data)
50
51# Export to Tensorflow Lite model and label file in `export_dir`.
52model.export(export_dir='/tmp/')
53```
54
55For more details, see the
56[image classification guide](https://www.tensorflow.org/lite/tutorials/model_maker_image_classification).
57
58## Installation
59
60There are two ways to install Model Maker.
61
62*   Install a prebuilt pip package.
63
64```shell
65pip install tflite-model-maker
66```
67
68If you want to install nightly version, please follow the command:
69
70```shell
71pip install tflite-model-maker-nightly
72```
73
74*   Clone the source code from GitHub and install.
75
76```shell
77git clone https://github.com/tensorflow/examples
78cd examples/tensorflow_examples/lite/model_maker/pip_package
79pip install -e .
80```
81
82TensorFlow Lite Model Maker depends on TensorFlow
83[pip package](https://www.tensorflow.org/install/pip). For GPU drivers, please
84refer to TensorFlow's [GPU guide](https://www.tensorflow.org/install/gpu) or
85[installation guide](https://www.tensorflow.org/install).
86
87## Python API Reference
88
89You can find out Model Maker's public APIs in
90[API reference](https://www.tensorflow.org/lite/api_docs/python/tflite_model_maker).
91