The TensorFlow Lite Model Maker library simplifies the process of training a
TensorFlow Lite model using custom dataset. It uses transfer learning to reduce
the amount of training data required and shorten the training time.
Supported Tasks
The Model Maker library currently supports the following ML tasks. Click the
links below for guides on how to train the model.
If your tasks are not supported, please first use
TensorFlow to retrain a TensorFlow model
with transfer learning (following guides like
images,
text,
audio) or
train it from scratch, and then convert it to TensorFlow
Lite model.
End-to-End Example
Model Maker allows you to train a TensorFlow Lite model using custom datasets in
just a few lines of code. For example, here are the steps to train an image
classification model.
fromtflite_model_makerimportimage_classifierfromtflite_model_maker.image_classifierimportDataLoader# Load input data specific to an on-device ML app.data=DataLoader.from_folder('flower_photos/')train_data,test_data=data.split(0.9)# Customize the TensorFlow model.model=image_classifier.create(train_data)# Evaluate the model.loss,accuracy=model.evaluate(test_data)# Export to Tensorflow Lite model and label file in `export_dir`.model.export(export_dir='/tmp/')
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-08-30 UTC."],[],[],null,["# TensorFlow Lite Model Maker\n\nOverview\n--------\n\nThe TensorFlow Lite Model Maker library simplifies the process of training a\nTensorFlow Lite model using custom dataset. It uses transfer learning to reduce\nthe amount of training data required and shorten the training time.\n\nSupported Tasks\n---------------\n\nThe Model Maker library currently supports the following ML tasks. Click the\nlinks below for guides on how to train the model.\n\n| Supported Tasks | Task Utility |\n|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------|\n| Image Classification: [tutorial](./image_classification), [api](https://www.tensorflow.org/lite/api_docs/python/tflite_model_maker/image_classifier) | Classify images into predefined categories. |\n| Object Detection: [tutorial](./object_detection), [api](https://www.tensorflow.org/lite/api_docs/python/tflite_model_maker/object_detector) | Detect objects in real time. |\n| Text Classification: [tutorial](./text_classification), [api](https://www.tensorflow.org/lite/api_docs/python/tflite_model_maker/text_classifier) | Classify text into predefined categories. |\n| BERT Question Answer: [tutorial](./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. |\n| Audio Classification: [tutorial](./audio_classification), [api](https://www.tensorflow.org/lite/api_docs/python/tflite_model_maker/audio_classifier) | Classify audio into predefined categories. |\n| Recommendation: [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. |\n| Searcher: [tutorial](./text_searcher), [api](https://www.tensorflow.org/lite/api_docs/python/tflite_model_maker/searcher) | Search for similar text or image in a database. |\n\nIf your tasks are not supported, please first use\n[TensorFlow](https://www.tensorflow.org/guide) to retrain a TensorFlow model\nwith transfer learning (following guides like\n[images](https://www.tensorflow.org/tutorials/images/transfer_learning),\n[text](https://www.tensorflow.org/official_models/fine_tuning_bert),\n[audio](https://www.tensorflow.org/tutorials/audio/transfer_learning_audio)) or\ntrain it from scratch, and then [convert](../../models/convert) it to TensorFlow\nLite model.\n\nEnd-to-End Example\n------------------\n\nModel Maker allows you to train a TensorFlow Lite model using custom datasets in\njust a few lines of code. For example, here are the steps to train an image\nclassification model. \n\n from tflite_model_maker import image_classifier\n from tflite_model_maker.image_classifier import DataLoader\n\n # Load input data specific to an on-device ML app.\n data = DataLoader.from_folder('flower_photos/')\n train_data, test_data = data.split(0.9)\n\n # Customize the TensorFlow model.\n model = image_classifier.create(train_data)\n\n # Evaluate the model.\n loss, accuracy = model.evaluate(test_data)\n\n # Export to Tensorflow Lite model and label file in `export_dir`.\n model.export(export_dir='/tmp/')\n\nFor more details, see the [image classification guide](./image_classification).\n\nInstallation\n------------\n\nThere are two ways to install Model Maker.\n\n- Install a prebuilt pip package.\n\n pip install tflite-model-maker\n\nIf you want to install nightly version, please follow the command: \n\n pip install tflite-model-maker-nightly\n\n- Clone the source code from GitHub and install.\n\n git clone https://github.com/tensorflow/examples\n cd examples/tensorflow_examples/lite/model_maker/pip_package\n pip install -e .\n\nTensorFlow Lite Model Maker depends on TensorFlow [pip\npackage](https://www.tensorflow.org/install/pip). For GPU drivers, please refer\nto TensorFlow's [GPU guide](https://www.tensorflow.org/install/gpu) or\n[installation guide](https://www.tensorflow.org/install).\n\nPython API Reference\n--------------------\n\nYou can find out Model Maker's public APIs in [API\nreference](https://www.tensorflow.org/lite/api_docs/python/tflite_model_maker)."]]