In the world of marketing and advertising, brand exposure plays a pivotal role in assessing the effectiveness of promotional strategies. This project aims to measure brand exposure during an IPL match video. The primary objective is to calculate key performance metrics (KPIs) for each brand logo, including the number of logo appearances, area coverage, frame frequency, and area percentage variations.
For this case study, we utilize a video clip from an IPL match between CSK and RCB. This 2-minute 35-second dataset, downloaded from YouTube, undergoes further processing, including frame extraction and object detection. Annotators convert the data into XML files, which are later transformed into CSV files for KPI computation.
The primary objectives of this project are as follows:
- Calculate KPI metrics for each brand logo.
- Determine the number of logo appearances.
- Compute the total area occupied by each logo.
- Analyze the frequency of logos across frames.
- Measure the shortest and longest area percentage relative to logo size.
- Language:
Python
- Libraries:
TensorFlow
,Pillow
,OpenCV
,Matplotlib
,NumPy
,uuid
-
Download the input video:
- Obtain the video from YouTube.
- Utilize a Python script (Youtube_downloader.py) for downloading.
-
Use the annotation tool (LabelImg) to create XML files:
- Annotate images with logo positions and details.
-
Set up TensorFlow for object detection:
- Clone the necessary repositories and set up the environment.
-
Convert XML files to CSV files:
- Transform annotation data into CSV format for training.
-
Convert CSV files to TFRecords:
- Prepare data for TensorFlow model training.
-
Configure base model:
- Download and customize the base model (e.g., ssd resnet 50fpn coco).
-
Train the model:
- Initiate model training and monitor results using TensorBoard.
-
Freeze the model:
- Combine checkpoint files (data, index, meta) into a single frozen model.
-
Export inference graph:
- Generate the frozen_inference_graph.pb for making predictions.
-
Predict brand logos in test images:
- Utilize the trained model to detect logos in video frames.
-
Tweak visualization utilities:
- Modify utilities to return bounding boxes and associated scores.
-
Video frame processing:
- Process the video into frames for logo detection.
-
Compute KPI metrics:
- Calculate KPIs such as logo appearance count, total area, frame frequency, and area percentage variations.
input
: Contains input data, including test_video.mp4, labels.txt, and frozen_inference_graph.pb.src
: Contains modularized code for various project steps.output
: Stores the output data, which includes a dictionary with key performance metrics for each logo.lib
: Reference folder containing the original iPython notebook and a reference presentation (ppt).
The modular code of the project assumes that we already have a trained object detection model and it does not focus on data collection, labelling and preparation. Although the step by step process has been explained in the video lectures to be replicated by the learners.
-
Data Collection: Collect the video of Pepsi brand exposure on YouTube with the youtube_downloader.py script. Video Link - https://www.youtube.com/watch?v=xWOoBJUqlbI
-
Data Labelling: Label each frame of the video with the object detection tool LabelImg to identify the appearance of Pepsi and other brands in the video.
-
Data Preparation: Prepare the labelled data for training by splitting it into training and testing sets and converting it into a format (XML to CSV to TFrecords) suitable for training an object detection model.
-
Setting up Tensorflow for Object Detection:
- Clone the repository
git clone https://github.com/tensorflow/models.git
- Run
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
inside /models/research directory.
- Clone the repository
-
Download the Base Model: Download the base model- ssd_resnet_50_fpn_coco from the repository https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/tf1_detection_zoo.md and extract.
-
Model Training: Get the training files from the previously cloned Tensorflow repository models/research/object_detection. Copy the train.py file from legacy and paste into the base folder and Train an object detection model on the labelled data as explained in the video lectures.
-
Model Freezing: Freeze the ckpt files into a frozen graph file for inference.
-
KPI Calculation: Calculate Key Performance Indicators (KPIs) such as the total appearance count, largest area percentage, smallest area percentage, and exposure over time comparison to understand the impact of the video on brand exposure.
The modular code is specifically for inference purposes and not training.
-
Install requirements.txt using following command
pip install -r requirements.txt
-
Clone the repository
git clone https://github.com/tensorflow/models.git
-
Run
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
inside /models/research directory. -
Run Engine.py for all the KPI's metrics