If the answer is yes for any of the above questions, Strategy Pattern might be a good option for you. Definition: The strategy pattern is a behavioral pattern that enables selecting an algorithm at…
This is a guide on how to create a model to recognize celebrities using a face matching algorithm.
This article includes the following topics:
All the code mentioned in this article is available on my GitHub repository.
The basic algorithm of the model includes the following:
So, in order to train your own celeb model, you need to provide a dataset of celebrities you need to recognize. Data can be scraped easily using sites like Google images, DuckDuckGo, Bing, etc. This data has to be arranged in a proper folder structure, with a separate folder for each celeb. The name of the celeb for the model is taken from the folder name (so make sure there are no spaces or special characters in the folder names). Provide as many celeb images are you can. The model will keep on improving as more data is added.
Now, you only need to provide the path of the folder in which all the folders with celeb images are stored. Details for using the code will be shown in the next section.
After the model has been created, we need to make predictions. During predictions, each images goes through the same process, face detection and encoding creation. The encoding of the face is search using the annoy index model that was created, which gives us the closest matching faces. The annoy library provides as many closest matches as we want, we can use only the top closest match for prediction. But in order to reduce false detections, a simple trick is added. We find the 10 closest matches, and if 3 or more of the matches belong to the same celeb, then the result is considered, else it is discarded.
There are several ways to use the library:
First clone the library to your local system. Install the dependencies using the requirements.txt file:
2. Pip package
To install pip package, run:
If you are using conda on Linux or Ubuntu, you can use the following commands to create and use a new environment called celeb-detector (this will install all the required dependencies):
For using my model for predictions, use the following lines of code after installation:
This returns a list of dictionaries, each dictionary contains bbox coordinates, celeb name and confidence for each face detected in the image (celeb name will be unknown if no matching face detected).
For using your own custom model, also provide path to json and ann files as shown below:
For creating your own model and run as follows:
3. Jupyter notebook
Making your own pip package is surprising easy, provided your code is clean and built using appropriate functions and classes.
General guide for creating a pip package can be found on the official documentation at:
The basic requirements are to create a LICENSE file, setup.py file and a folder which should have all the codes to be included in the pip package.
Python setuptools package can directly find all the necessary functions that are to be included in the pip package. You also need to make an account on the PyPI site and get your token for publishing the package.
In my case, I have added a folder called celeb-detector (which is the name of my pip package). This folder has files which include functions for getting image predictions and creating the model.
Once the pip package is installed and imported, you can use these functions to get predictions or create your own model.
The rise of your mouth mischievous, delicious smile. Your eyes know how to talk, soul searching for delight, always ready to laugh. Hands soft, strong, knowing… Your playful touch pulls shivers to…
Segmentation is the fact of grouping similar elements having the same characteristics into the same segment. The resulting segments split the concerned population into groups that share the same…
The fatal accident that killed 288 people in Balasore, Odisha on June 2, once again raised questions about Indian Railways' safety. However, in the past years, there has been a continuous decrease in…