Labelling Images Application for Machine Learning – update 3

On this update I did implement an Export Data script , this data object will contain all feedbacks (images labelled) by users, it will help me to train the model.

exportData.js


import { initializeApp } from "firebase/app";
import { getFirestore, collection, getDocs } from "firebase/firestore";
import fs from 'fs';
import path from 'path';


// Firebase configuration (hardcoded for this standalone script)
const firebaseConfig = {
    apiKey: "########################",
    authDomain: "########################",
    projectId: "########################",
    storageBucket: "########################",
    messagingSenderId: "########################",
    appId: "########################",
    measurementId: "########################"
};

// Initialize Firebase
const app = initializeApp(firebaseConfig);
const db = getFirestore(app);

const exportData = async () => {

    try {
        const feedbackCollection = collection(db, "feedback");
        const snapshot = await getDocs(feedbackCollection);
        
        // Log the snapshot size to check if documents are retrieved
        console.log("Number of documents retrieved:", snapshot.size);

        // Map document to an array
        const data = snapshot.docs.map(doc => ({ id: doc.id, ...doc.data() }));

        // Ensure the output directory exists
        const outputDir = path.resolve('./backend');
        if (!fs.existsSync(outputDir)){
            fs.mkdirSync(outputDir, { recursive: true });
        }

        // Save data to a file
        const outputPath = path.join(outputDir, 'feedbackData.json');
        fs.writeFileSync(outputPath, JSON.stringify(data, null, 2));
        console.log(`Data exported to ${outputPath}`);
    } catch (error) {
        console.error("Error exporting data: ", error);
    }
};

exportData();

it is executed by node on command line and the JSON file is saved on /backend folder where the model will train with the data.

node exportData.js

data exported from Firebase

How the Model Works

  1. Input Features:
    • The model takes a feature vector (e.g., new_features) as input. This feature vector represents some data (e.g., an image, user feedback, or other structured data) that was preprocessed and transformed into numerical values.
  2. Prediction:
    • The model uses the patterns it learned during training to predict the class (e.g., 01, etc.) that the input feature vector most likely belongs to.
  3. Decoding the Class:
    • The numerical class (e.g., 0) is decoded back into its original label (e.g., "apple" or "pear") using the LabelEncoder.
  4. Output:
    • The model outputs the predicted label (e.g., "apple") for the given feature vector.

What This Means

  • The model can take a feature vector (without a label) and predict which label (e.g., "apple" or "pear") it most likely belongs to.
  • This is because the model was trained on labeled data, where it learned the relationship between feature vectors and their corresponding labels.

Example Workflow

  1. Training:
    • During training, the model was given feature vectors (e.g., extracted from images) and their corresponding labels (e.g., "apple""pear").
    • It learned to associate specific patterns in the feature vectors with their labels.
  2. Prediction:
    • Now, when you provide a new feature vector (e.g., new_features), the model uses what it learned during training to predict the label for this feature vector.

Real-World Example

Imagine you have a dataset of fruit images:

  • During training:
    • The feature vector for an image of an apple is labeled as "apple".
    • The feature vector for an image of a pear is labeled as "pear".
  • During prediction:
    • You provide a new feature vector (e.g., extracted from an image of an apple) to the model.
    • The model predicts that this feature vector belongs to the label "apple".

Key Points

  • The model does not need the label during prediction. It only needs the feature vector.
  • The label ("apple""pear", etc.) is predicted based on the patterns the model learned during training.

I’ll appreciate your advices or feedbacks.

URL: https://josesuarezcordova.github.io/pwa_app/

CATEGORIES:

PWA-R&D

Comments are closed