Pre-made models are models that are already trained for a specific purpose. There are a variety of already trained, open source models you can use immediately with TensorFlow.js to accomplish many machine learning tasks. This topic provides guidance on how to find and select pre-made models for your use case.
Benefits of using pre-made models
TensorFlow.js has a broad spectrum of pre-made models that can be used in any project out of the box and provide you with the following significant benefits:
- Save Time and Resources: Avoid the time-consuming processes of gathering, preparing, and labeling data, then training, evaluating, and improving the model. Be able to prototype your ideas rapidly.
- Leverage existing research and documentation: The state-of-the-art research used in developing pre-made models enables you to quickly deploy them while understanding how they perform in different real-world scenarios.
- Enable transfer learning: Pre-made models allow you to use information learned by a model for a task on another, similar use-case. This transfer learning process will enable you to train existing models rapidly on custom data.
Find a model
Finding an existing TensorFlow.js model for your use case depends on what you are trying to accomplish. For example, does your app need to run on the client-side or server-side? How important are factors such as privacy, speed and accuracy? etc.
Here are a few recommended ways to discover models for use with TensorFlow.js:
By example: The fastest way to find and start using models with TensorFlow.js is to browse the TensorFlow.js demos section to find demos that perform a task similar to your use case. This catalog provides fun example use cases with links to the code that will help you get started.
By data input type: Aside from looking at examples similar to your use case, another way to discover models for your own use is to consider the type of data you want to process, such as audio, text, or images. Machine learning models are frequently designed for use with one of these types of data, so looking for models that handle the data type you want to use can help you narrow down what models to consider. You can start browsing TensorFlow.js models based on general use cases in the TensorFlow.js models section, or browse a larger set of models on TensorFlow Hub. On TensorFlow Hub, you can use the Problem domain filter to view model data types and narrow your list.
The following list links to TensorFlow.js models on TensorFlow Hub for common use cases:
- Image classification models
- Object detection models
- Text models
- Audio models
Choose between similar models
If your application follows a common use case such as image classification or object detection, you may find multiple TensorFlow.js models that fit your need. Once you have some models that are applicable to your use case, you want to identify the model that will provide the best solution. To do this, consider the following aspects of each model:
- Inference speed
- File size
- Runtime RAM usage
- Model features/capabilities
When deciding between a number of models, you can narrow your options based first on your most limiting constraint such as size of model, size of data, inference speed, or accuracy, etc.
If you are not sure what your most limiting constraint is, assume it is the size of the model and pick the smallest model available. Picking a small model gives you the most flexibility in terms of where you can successfully deploy and run the model. Smaller models also typically produce faster inferences, and speedier predictions generally create better end-user experiences. However, smaller models typically have lower accuracy rates, so you may need to pick larger models if prediction accuracy is your primary concern.
Sources for models
Pre-made models in TensorFlow.js are typically available in two forms. Official models come wrapped in JavaScript classes making them simple to deploy in your app. Others are in a raw form that may require additional code to pre/post process input and output data.
Use the TensorFlow.js models as your first destination for finding and selecting models for use with TensorFlow.js. These are the official models provided by the TensorFlow.js team which already have the JavaScript wrappers that make it simple to integrate into your code. The TensorFlow Hub site provides additional models. Note that models in the Hub may be in a raw format that requires additional work on your part to integrate.
TensorFlow models
It is possible to convert regular TensorFlow models to TensorFlow.js format. For more information about converting models, see the Model conversion topic. You can find TensorFlow models on TensorFlow Hub and in the TensorFlow Model Garden.
Further reading
- Now that you know where to find models ready for use, see the React native tutorial to learn how you can use such a model in a web app.