0% found this document useful (0 votes)
26 views2 pages

Helping Blind People To Be Aware of The Logos Around Themselves

This document outlines a step-by-step process for developing a logo detection system to assist blind individuals in recognizing logos. It includes instructions for installing necessary libraries, loading and displaying a dataset of images, creating a MobileNetV2 model for logo classification, and providing audio feedback of detected logos. The final step demonstrates testing the model with an example image to produce an audio output of the detected logo name.

Uploaded by

SHRIGAYATHRI S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views2 pages

Helping Blind People To Be Aware of The Logos Around Themselves

This document outlines a step-by-step process for developing a logo detection system to assist blind individuals in recognizing logos. It includes instructions for installing necessary libraries, loading and displaying a dataset of images, creating a MobileNetV2 model for logo classification, and providing audio feedback of detected logos. The final step demonstrates testing the model with an example image to produce an audio output of the detected logo name.

Uploaded by

SHRIGAYATHRI S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

4.

helping blind people to be aware of the logos around themselves

# 🚀 Step 1: Install Required Libraries


!pip install numpy==1.26.4 --force-reinstall
!pip install tensorflow keras matplotlib opencv-python pyttsx3 gtts pillow
!sudo apt-get update
!sudo apt-get install -y espeak ffmpeg libespeak1

# 🚀 Step 2: Import Required Libraries


import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
import cv2
import os
import pyttsx3
from tensorflow.keras.preprocessing.image import load_img, img_to_array
from tensorflow.keras.applications import MobileNetV2
from tensorflow.keras.layers import Dense, GlobalAveragePooling2D, Dropout
from tensorflow.keras.models import Model
from google.colab import drive
from sklearn.preprocessing import LabelEncoder

# 🚀 Step 3: Mount Google Drive


drive.mount('/content/drive', force_remount=True)

# Dataset Path (Update this if necessary)


DATASET_PATH = "/content/drive/MyDrive/dataset/images"

# 🚀 Step 4: Load Dataset & Display All Images


IMG_SIZE = (224, 224) # Image size for MobileNetV2

def load_dataset(directory):
images = []
labels = []
image_files = []

for filename in os.listdir(directory):


if filename.endswith(".jpg") or filename.endswith(".png"):
img_path = os.path.join(directory, filename)
img = load_img(img_path, target_size=IMG_SIZE)
img_array = img_to_array(img) / 255.0 # Normalize
images.append(img_array)
labels.append(filename.split(".")[0]) # Label is the filename without extension
image_files.append(img_path)

return np.array(images), np.array(labels), image_files

X, y, image_files = load_dataset(DATASET_PATH)

# 🚀 Step 5: Display All Images with Labels


fig, axes = plt.subplots(1, len(image_files), figsize=(15, 5))

for i, img_path in enumerate(image_files):


img = load_img(img_path, target_size=IMG_SIZE)
axes[i].imshow(img)
axes[i].axis("off")
axes[i].set_title(y[i]) # Set label as title

plt.show()

# 🚀 Step 6: Create Model using MobileNetV2


base_model = MobileNetV2(weights="imagenet", include_top=False, input_shape=(224, 224, 3))
x = base_model.output
x = GlobalAveragePooling2D()(x)
x = Dropout(0.4)(x)
x = Dense(128, activation="relu")(x)
x = Dropout(0.3)(x)
predictions = Dense(len(np.unique(y)), activation="softmax")(x)

model = Model(inputs=base_model.input, outputs=predictions)

# Freeze Base Model Layers


for layer in base_model.layers:
layer.trainable = False

#🚀 Step 7: Compile the Model


model.compile(optimizer="adam", loss="sparse_categorical_crossentropy", metrics=["accuracy"])

# Convert labels to numerical values


label_encoder = LabelEncoder()
y_encoded = label_encoder.fit_transform(y)

# 🚀 Step 8: Train the Model


model.fit(X, y_encoded, epochs=10, batch_size=8, validation_split=0.2)

# 🚀 Step 9: Function for Logo Detection & Audio Output


def predict_logo(image_path):
img = load_img(image_path, target_size=IMG_SIZE)
img = img_to_array(img) / 255.0
img = np.expand_dims(img, axis=0)

pred = model.predict(img)
label = label_encoder.inverse_transform([np.argmax(pred)])[0]

print(f"Detected Logo: {label}")

# Convert Prediction to Audio for Blind People


engine = pyttsx3.init()
engine.say(f"Detected Logo is {label}")
engine.runAndWait()

#🚀 Step 10: Test with an Example Image


test_image_path = "/content/drive/MyDrive/dataset/images/bmw.jpg"

predict_logo(test_image_path)

You might also like