MobileNets are small, low-latency, low-power models parameterized to meet the resource constraints of a variety of use cases. They can be built upon for classification, detection, embeddings and segmentation similar to how other popular large scale models, such as Inception, are used.
MobileNets trade off between latency, size and accuracy while comparing favorably with popular models from the literature.
This TensorFlow.js model does not require you to know about machine learning.
It can take as input any browser-based image elements (
elements, for example) and returns an array of most likely predictions and
For more information about MobileNet, check out this readme in tensorflow/models.
via Script Tag
<!-- Load TensorFlow.js. This is required to use MobileNet. --><!-- Load the MobileNet model. --><!-- Replace this with your image. Make sure CORS settings allow reading the image! --><!-- Place your code in the script tag below. You can also use an external .js file -->
// Note: you do not need to import @tensorflow/tfjs here.;const img = document;// Load the model.const model = await mobilenet;// Classify the image.const predictions = await model;console;console;
Loading the model
mobilenet is the module name, which is automatically included when you use the
<script src> method. When using ES6 imports, mobilenet is the module.
For users of previous versions (1.0.x), the API is:
mobilenet.loadversion?: 1,alpha?: 025 | 50 | 75 | 10
- version: The MobileNet version number. Use 1 for MobileNetV1, and 2 for MobileNetV2. Defaults to 1.
- alpha: Controls the width of the network, trading accuracy for performance. A smaller alpha decreases accuracy and increases performance. 0.25 is only available for V1. Defaults to 1.0.
- modelUrl: Optional param for specifying the custom model url or
tf.io.IOHandlerobject. Returns a
- inputRange: Optional param specifying the pixel value range expected by the trained model hosted at the modelUrl. This is typically [0, 1] or [-1, 1].
mobilenet is the module name, which is automatically included when you use