Live Emoji Prediction Project Notes

Jul 24, 2024

Live Emoji Prediction Project - Part 2

Overview

  • This part of the project focuses on finalizing the emoji prediction system.
  • Previously covered in Part 1: Data collection, recommended to watch for better understanding.

Learning Objectives

  • Finalize project by loading collected data, training the model, and running inference.
  • Create and implement two Python scripts:
    • data_training.py for training the model
    • inference.py for making predictions.

Data Collection

  • Run data_collection.py multiple times to gather emoji data:
    • Collected data files:
      • hello.npy
      • good_luck.npy
      • nope.npy
  • Ensure all data files end with .npy to filter correctly.

Data Training Script (data_training.py)

  1. Imports Needed:

    • os for file handling.
    • numpy as np for array manipulation.
    • cv2 if using OpenCV.
  2. Load Data Files:

    • Use os.listdir() to retrieve all files in the directory.
    • Filter files to only include those ending with .npy.
  3. Initialize Data Arrays:

    • Create x for features and y for labels initially set to empty.
    • Concatenate loaded data from files into x and create corresponding y labels.
    • Ensure y is set as an array of integers corresponding to the labels.
  4. Handle Label Encoding:

    • Create a dictionary for emoji labels to unique integers.
    • Convert the y data into categorical format using to_categorical from Keras utilities.
  5. Model Creation:

    • Use Keras to define the model architecture with input and dense layers.
    • Compile model with rmsprop optimizer and categorical_crossentropy loss function.
  6. Training the Model:

    • Fit the model on x and y data for a defined number of epochs.
    • It's suggested to shuffle data to mix the training samples effectively.
    • Save the trained model and labels into files for later use.

Inference Script (inference.py)

  1. Setup:

    • Import necessary libraries: cv2, numpy, mediapipe, and Keras model loading utilities.
    • Load the trained model and labels saved from the training phase.
  2. Capture Video:

    • Initialize video capture from the webcam.
    • Process frames to detect hands using mediapipe hands landmark solutions.
  3. Prediction Logic:

    • Convert captured landmarks into the right shape for model input.
    • Use the model to predict the emoji based on the captured hand gestures.
    • Output the predictions dynamically on the capture window.

Improvements and Considerations

  • Ensure error handling for file operations and model predictions.
  • Consider adding more emojis and ensuring model retraining as new data is collected.

Conclusion

  • Successfully implemented a project to predict emojis based on hand gestures.
  • Future work could involve refining model performance and expanding the emoji set.

Call to Action

  • Viewers encouraged to engage with questions or problems in the comments.
  • Reminder to like the video and subscribe for upcoming content.

Emoji: 🚀