
Research
/Security News
Shai Hulud Strikes Again (v2)
Another wave of Shai-Hulud campaign has hit npm with more than 500 packages and 700+ versions affected.
@tensorflow-models/mobilenet
Advanced tools
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 (<img>, <video>, <canvas>
elements, for example) and returns an array of most likely predictions and
their confidences.
For more information about MobileNet, check out this readme in tensorflow/models.
There are two main ways to get this model in your JavaScript project: via script tags or by installing it from NPM and using a build tool like Parcel, WebPack, or Rollup.
<!-- Load TensorFlow.js. This is required to use MobileNet. -->
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@1.0.1"> </script>
<!-- Load the MobileNet model. -->
<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/mobilenet@1.0.0"> </script>
<!-- Replace this with your image. Make sure CORS settings allow reading the image! -->
<img id="img" src="cat.jpg"></img>
<!-- Place your code in the script tag below. You can also use an external .js file -->
<script>
// Notice there is no 'import' statement. 'mobilenet' and 'tf' is
// available on the index-page because of the script tag above.
const img = document.getElementById('img');
// Load the model.
mobilenet.load().then(model => {
// Classify the image.
model.classify(img).then(predictions => {
console.log('Predictions: ');
console.log(predictions);
});
});
</script>
// Note: you do not need to import @tensorflow/tfjs here.
const mobilenet = require('@tensorflow-models/mobilenet');
const img = document.getElementById('img');
// Load the model.
const model = await mobilenet.load();
// Classify the image.
const predictions = await model.classify(img);
console.log('Predictions: ');
console.log(predictions);
mobilenet is the module name, which is automatically included when you use the <script src> method. When using ES6 imports, mobilenet is the module.
mobilenet.load({
version: 1,
alpha?: 0.25 | .50 | .75 | 1.0,
modelUrl?: string
inputRange?: [number, number]
}
)
For users of previous versions (1.0.x), the API is:
mobilenet.load(
version?: 1,
alpha?: 0.25 | .50 | .75 | 1.0
)
Args:
tf.io.IOHandler object.
Returns a model object.mobilenet is the module name, which is automatically included when you use
the
You can make a classification with mobilenet without needing to create a Tensor
with MobileNet.classify, which takes an input image element and returns an
array with top classes and their probabilities.
If you want to use this for transfer learning, see the infer method.
This method exists on the model that is loaded from mobilenet.load.
model.classify(
img: tf.Tensor3D | ImageData | HTMLImageElement |
HTMLCanvasElement | HTMLVideoElement,
topk?: number
)
Args:
Returns a Promise that resolves to an array of classes and probabilities that looks like:
[{
className: "Egyptian cat",
probability: 0.8380282521247864
}, {
className: "tabby, tabby cat",
probability: 0.04644153267145157
}, {
className: "Siamese cat, Siamese",
probability: 0.024488523602485657
}]
You can also get the embedding of an image to do transfer learning. The size of the embedding depends on the alpha (width) of the model.
model.infer(
img: tf.Tensor3D | ImageData | HTMLImageElement |
HTMLCanvasElement | HTMLVideoElement,
embedding = false
)
FAQs
Pretrained MobileNet in TensorFlow.js
The npm package @tensorflow-models/mobilenet receives a total of 5,080 weekly downloads. As such, @tensorflow-models/mobilenet popularity was classified as popular.
We found that @tensorflow-models/mobilenet demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 9 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
/Security News
Another wave of Shai-Hulud campaign has hit npm with more than 500 packages and 700+ versions affected.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.