Skip to content

andresWeitzel/Modulo_MobileNET_CNN_Tensorflow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Index app




MobileNET_CNN_Tensorflow_Module (status-completed)

Module for implementing the MobileNET Convolutional Neural Network Model for Image Classification.


Index 📜

See

Section 1) Description, configuration and technologies.

Section 2) Models

Section 3) Documentation



Section 1) Description, configuration and technologies.

1.0) Project Description

See

This module implements the MobileNet convolutional neural network model for image classification using TensorFlow.js in Node.js. It allows efficient image classification with the pre-trained MobileNet model. The MobileNet architecture is optimized for mobile and embedded vision applications while maintaining high accuracy. This implementation includes:

  • Integration with TensorFlow.js and Node.js for server-side image classification
  • Pre-trained MobileNet model weights for fast inference without training
  • Support for classifying common objects across 1000 categories
  • Efficient processing pipeline for image loading and classification
  • Example code showing how to use the model for real-world image classification tasks
  • High performance with low computational requirements compared to larger CNN models

1.1) Requirements (For W10/11 OS)

See
* [Microsoft Visual Studio](https://bobbyhadz.com/blog/npm-err-gyp-err-find-vs-you-need-to-install-the-latest-version) - Required for building native Node.js modules and TensorFlow.js bindings * [Python](https://www.python.org/downloads/) - Version 3.6 or higher, needed for TensorFlow.js and node-gyp * [Node.js](https://nodejs.org/) - Version 14.x or higher recommended * [npm](https://www.npmjs.com/) - Node.js package manager (comes with Node.js) * At least 2GB of RAM. * 1GB of free disk space.

1.2) Project Execution

See
  • Create a working environment through an IDE (Visual Studio Code recommended for best TensorFlow.js integration)
  • Clone the Project (git clone https://github.com/andresWeitzel/Modulo_MobileNET_CNN_Tensorflow_NodeJs)
  • IMPORTANT: For using tensorflow on w10/11 it is necessary to have the Desktop development with C++ add-on for visual studio installed. To install it follow these steps. In addition to having Python installed and configured its PATH.
  • Inside the directory install all implemented plugins
    • npm update (Update npm repositories)
    • npm install -g npm@latest (Latest compatible version of npm)
    • npm install -S @tensorflow/tfjs(TensorFlow.js Core) - Core TensorFlow.js library for building and training neural networks
    • npm install -S @tensorflow/tfjs-node (TensorFlow.js Node.js extension) - Node.js binding providing CPU/GPU acceleration
    • npm install -S @tensorflow-models/mobilenet (MobileNet Model) - Pre-trained MobileNet model for image classification
  • Verify installations:
    • Run node -v to confirm Node.js version
    • Run npm -v to verify npm version
    • Run python --version to check Python installation
  • Test the setup:
    • Create a test file and import TensorFlow.js
    • Try loading the MobileNet model
    • If any errors occur, check the troubleshooting section

1.3) Possible Solutions for Library Installation Errors

See

Section 2) Models

2.0) Image Reading and Decoding Layer Model

See
//Imports
const tf = require('@tensorflow/tfjs');
const tfnode = require('@tensorflow/tfjs-node');
const fs = require('fs');

module.exports.exec = (path) => {
    const imageBuffer = fs.readFileSync(path);
    const tfimage = tfnode.node.decodeImage(imageBuffer);
    return tfimage;
}
  1. Reading the image file from the specified path
  2. Converting the image into a format that TensorFlow can process
  3. Decoding the image buffer into a tensor

Key components:

  • Uses fs.readFileSync() to read the image file into a buffer
  • Uses tfnode.node.decodeImage() to convert the buffer into a TensorFlow tensor
  • Returns the tensor for use in classification

2.1) MobileNet Model Architecture

See

Image Classification Layer Model

//Imports
const read= require('../fileSystem/read');
const mobileNet = require('@tensorflow-models/mobilenet');

const classificator = async(path) =>{
    try {
        const img = read.exec(path);
        const model = await mobileNet.load();
        const predictions = await model.classify(img);
        console.log('Classification Results : ', predictions);
    } catch (error) {
        console.log(error);
    }
}

if (process.argv.length !== 3) throw new Error('Incorrect arguments!');
classificator(process.argv[2]);

MobileNET Model Execution

  • Images are stored in the src/img directory
  • We select an image for the model to classify.

First Model Classification

First Classification

  • In my case I have removed the image metadata and name so that the model classifies according to its confidence level.
  • We execute the model from src/runners/classificator with node classificator.js ../img/test04.jpg
  • Expected Output...
2022-11-20 20:09:04.459159: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in 
performance-critical operations:  AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
Classification Results :  [
  { className: 'espresso', probability: 0.9372739195823669 },        
  { className: 'cup', probability: 0.02711259014904499 },
  { className: 'mortar', probability: 0.008303580805659294 }
]
  • High probability for espresso (espresso coffee). High Confidence Interval and Correct Classification.

Second Model Classification

Second Classification

  • In my case I have removed the image metadata and name so that the model classifies according to its confidence level.
  • We execute the model from src/runners/classificator with node classificator.js ../img/test05.jpg
  • Expected Output...
2022-11-20 20:11:07.652384: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in 
performance-critical operations:  AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
Classification Results :  [
  {
    className: 'microwave, microwave oven',
    probability: 0.3682105839252472
  },
  { className: 'coffeepot', probability: 0.08597368746995926 },      
  { className: 'paper towel', probability: 0.08168061077594757 }     
]
  • High probability for microwave (microwave oven). We can notice that the Model does not apply an acceptable confidence interval for several objects. The model managed to predict that there is a coffeepot (coffee maker) but with low probability. Low Confidence Interval and Correct Classification. For this case, a fine-tuning of model parameters should be applied.

Section 3) Documentation

3.0) Official Documentation

See

3.1) Unofficial Documentation

See

3.2) Video Tutorials

See

About

✅ Module for the implementation of the MobileNET Convolutional Neural Network Model for Image Classification

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •