Machine Learning (Aryan Kumar 7th Sem) PDF
Machine Learning (Aryan Kumar 7th Sem) PDF
A
Summer
“Training Report”
On
“WebTek Labs Pvt. Ltd”
Submitted in Partial fulfillment
For the award of the Degree of
B.Tech in Department of Computer Science & Engineering
( With Specialization in Computer Science & Engineering )
Session – 2020-2021
Submitted To : Submitted By :
Mr. Devendra Suthar Aryan Kumar
(Assistant Professor) Roll no. 17ERACS007
Computer Science (B.Tech, 7th Sem)
I hereby declare that the summer training from “WEBTEK LABS PVT. LTD,
JAIPUR, RAJASTHAN”. in partial fulfilment for the award of degree of
“Bachelor of technology in Department of Computer Science, Aravali Institute
of Technical Studies, Udaipur is a record of my own investigation carried under
the guidance of Mr. Jitendra Singh, Department of Computer Engineering,
Aravali Institute Of Technical Studies.
I have not submitted the presented in this report anywhere for the award of any
other degree.
Aryan Kumar
Computer Science
R no. 17ERASC007
AITS - Udaipur, Rajasthan
H.O.D DIRECTOR
Dr. Jitendra Singh Dr.Hemant Dhabhai
ACKNOWLEDGEMENT
I have gave my best for this project , And it was possible for me without any
guides of other people .But I would like to thanks my friends for the reason is
they are help me all time if any problem is occur . I am highly indebted to
WEBTEK LABS PVT. LTD, JAIPUR, RAJASTHAN
For providing me a creative environment and all the faucitis to learn advance
think. WEBTEK LABS PVT. LTD, doing best in IT field for providing us more
opportunity to explore our ideas and make a really great project in our field .And
also I would like thank Dr. Jitendra Singh Chauhan, head of Department of
computer science and engineering for the support and encouragement during the
project. I perceive this project as a big milestone in our career I will strive to use
gained skills and knowledge in the best possible way, and I will continue to work
on their improvement in Order to attain desired objective .
Aryan Kumar
Computer Science
R no. 17ERASC007
AITS - Udaipur, Rajasthan
COMPANY PROFILE
Having partnered and worked with some of the leading names across Education, IT,
ITES, Banking, Insurance, Aviation, Retail, Healthcare, Hospitality, Media,
Manufacturing and FMCG sectors, WebTek Labs has explored business
opportunities in software solutions with the Government, Corporate and Institutes.
INTRODUCTION
About
1. Machine Learning
2. Supervised Machine Learning
3. Unsupervised Machine Learning
4. Semi-Supervised Machine Learning App Permissions
5. Reinforcement Machine Learning
Core Topics
6. Environment Setup For Machine Learning
7. Installing All Required Modules For Machine Learning
My Projects
8. Create your emoji with Deep Learning
9. Testing
10. Conclusion
11. Refrences
Chapter-1
MACHINE LEARNING
What is Machine Learning?
Machine learning is a subfield of computer science that evolved from the study of pattern
recognition and computational learning theory in artificial intelligence. Machine learning
explores the construction and study of algorithms that can learn from and make predictions on
data. Such algorithms operate by building a model from example inputs in order to make data
driven predictions or decisions, rather than following strictly static program instructions.
Machine learning is closely related to and often overlaps with computational statistics; a
discipline that also specializes in prediction-making. It has strong ties to mathematical
optimization, which deliver methods, theory and application domains to the field. Machine
learning is employed in a range of computing tasks where designing and programming explicit
algorithms is infeasible. Example applications include spam filtering, optical character
recognition (OCR), search engines and computer vision. Machine learning is some times
conflated with data mining, although that focuses more on exploratory data analysis. Machine
learning and pattern recognition “can be viewed as two facets of the same field.” When
employed in industrial contexts, machine learning methods may be referred to as predictive
analytics or predictive modelling.
In 1959, Arthur Samuel defined machine learning as a “Field of study that gives computers the
ability to learn without being explicitly programmed”. Tom M. Mitchell provided a widely
quoted, more formal definition: “A computer program is said to learn from experience E with
respect to some class of tasks T and performance measure P, if its performance at tasks in T,
as measured by P, improves with experience E”. This definition is notable for its defining
machine learning in fundamentally operational rather than cognitive terms, thus following
Alan Turing's proposal in his paper "Computing Machinery and Intelligence" that the question
“Can machines think?" be replaced with the question “Can machines do what we (as thinking
entities) can do?"
7
Steps involved in Machine Learning:
1. Defining a Problem
2. Preparing Data
3. Evaluating Algorithms
4. Improving Results
5. Presenting Results
The best way to get started using Python for machine learning is to work through a project
endto-end and cover the key steps like loading data, summarizing data, evaluating algorithms
and making some predictions. This gives you a replicable method that can be used dataset after
dataset.
1.On basis of the nature of the learning “signal” or “feedback” available to a learning
system
9
•Supervised learning: The computer is presented with example inputs and their desired
outputs, given by a “teacher”, and the goal is to learn a general rule that maps inputs to outputs.
The training process continues until the model achieves the desired level of accuracy on the
training data. Some real-life examples are:
•Image Classification: You train with images/labels. Then in the future you give a new image
expecting that the computer will recognize the new object.
•Market Prediction/Regression: You train the computer with historical market data and ask the
computer to predict the new price in the future.
•Unsupervised learning: No labels are given to the learning algorithm, leaving it on its own
to find structure in its input. It is used for clustering population in different groups.
Unsupervised learning can be a goal in itself (discovering hidden patterns in data).
•Clustering: You ask the computer to separate similar data into clusters, this is essential in
research and science.
•High Dimension Visualization: Use the computer to help us visualize high dimension data.
•Generative Models: After a model captures the probability distribution of your input data, it
will be able to generate more data. This can be very useful to make your classifier more robust.
A simple diagram which clears the concept of supervised and unsupervised learning is shown
below:
As you can see clearly, the data in supervised learning is labelled, where as data in
unsupervised learning is unlabelled.
•Semi-supervised learning: Problems where you have a large amount of input data and only
some of the data is labeled, are called semi-supervised learning problems. These problems sit
in between both supervised and unsupervised learning. For example, a photo archive where
only some of the images are labeled, (e.g. dog, cat, person) and the majority are unlabeled.
10
•Reinforcement learning: A computer program interacts with a dynamic environment in
which it must perform a certain goal (such as driving a vehicle or playing a game against an
opponent). The program is provided feedback in terms of rewards and punishments as it
navigates its problem space.
•Classification: Inputs are divided into two or more classes, and the learner must produce a
model that assigns unseen inputs to one or more (multi-label classification) of these classes.
This is typically tackled in a supervised way. Spam filtering is an example of classification,
where the inputs are email (or other) messages and the classes are “spam” and “not spam”.
•Regression: It is also a supervised learning problem, but the outputs are continuous rather
than discrete. For example, predicting the stock prices using historical data.
•Clustering: Here, a set of inputs is to be divided into groups. Unlike in classification, the
groups are not known beforehand, making this typically an unsupervised task.
As you can see in the example below, the given dataset points have been divided into groups
identifiable by the colours red, green and blue.
11
•Density estimation: The task is to find the distribution of inputs in some space.
• Vision processing
• Language processing
• Pattern recognition
• Games
• Data mining
• Expert systems
• Robotics
12
How does Machine Learning Work?
Machine Learning algorithm is trained using a training data set to create a model. When new
input data is introduced to the ML algorithm, it makes a prediction on the basis of the model.
The prediction is evaluated for accuracy and if the accuracy is acceptable, the Machine
Learning algorithm is deployed. If the accuracy is not acceptable, the Machine Learning
algorithm is trained again and again with an augmented training data set.
This is just a very high-level example as there are many factors and other steps involved.
13
Chapter-2
Supervised learning is commonly used in real world applications, such as face and speech
recognition, products or movie recommendations, and sales forecasting.
Supervised learning is when the model is getting trained on a labelled dataset. Labelled dataset
is one which have both input and output parameters. In this type of learning both training and
validation datasets are labelled as shown in the figures below.
14
Both the above figures have labelled data set –
•Figure A: It is a dataset of a shopping store which is useful in predicting whether a
customer will purchase a particular product under consideration or not based on his/ her
gender, age and salary.
Input: Gender, Age, Salary
Output: Purchased i.e. 0 or 1;1 means yes, the customer will purchase and 0 means that
customer won’t purchase it.
•Figure B: It is a Meteorological dataset which serves the purpose of predicting wind speed
based on different parameters.
Input: Dew Point, Temperature, Pressure, Relative Humidity, Wind Direction
Output: Wind Speed
Training the system:
While training the model, data is usually split in the ratio of 80:20 i.e. 80% as training data and
rest as testing data. In training data, we feed input as well as output for 80% data. The model
learns from training data only. We use different machine learning algorithms (which we will
discuss in detail in next articles) to build our model. By learning, it means that the model will
build some logic of its own.
Once the model is ready then it is good to be tested. At the time of testing, input is fed from
remaining 20% data which the model has never seen before, the model will predict some value
and we will compare it with actual output and calculate the accuracy.
15
Types of Supervised Learning:
1.Classification: It is a Supervised Learning task where output is having defined labels
(discrete value). For examples in above Figure A, Output – Purchased has defined labels i.e. 0
or 1;1 means the customer will purchase and 0 means that customer won’t purchase. The goal
here is to predict discrete values belonging to a particular class and evaluate on the basis of
accuracy.
It can be either binary or multi class classification. In binary classification, model predicts
either 0 or 1 ; yes or no but in case of multi class classification, model predicts more than one
class.
Example: Gmail classifies mails in more than one classes like social, promotions, updates,
forum.
A classification problem is when the output variable is a category, such as “red” or “blue” or
“disease” and “no disease”. A classification model attempts to draw some conclusion from
observed values. Given one or more inputs a classification model will try to predict the value
of one or more outcomes.
For example, when filtering emails “spam” or “not spam”, when looking at transaction data,
“fraudulent”, or “authorized”. In short Classification either predicts categorical class labels or
classifies data (construct a model) based on the training set and the values (class labels) in
classifying attributes and uses it in classifying new data. There are a number of classification
models. Classification models include logistic regression, decision tree, random forest,
gradient-boosted tree, multilayer perceptron, one-vs-rest, and Naive Bayes.
For example:
Which of the following is/are classification problem(s)?
• Predicting the gender of a person by his/her handwriting style
• Predicting house price based on area
16
• Predicting whether monsoon will be normal next year
• Predict the number of copies a music album will be sold next month
Solution: Predicting the gender of a person Predicting whether monsoon will be normal next
year. The other two are regression.
As we discussed classification with some examples. Now there is an example of classification
in which we are performing classification on the iris dataset using RandomForestClassifier in
python.
Dataset Description
Title: Iris Plants Database
Attribute Information:
1. sepal length in cm
2. sepal width in cm
3. petal length in cm
4. petal width in cm
5. class:
-- Iris Setosa
-- Iris Versicolour
-- Iris Virginica
Missing Attribute Values: None
Class Distribution: 33.3% for each of 3 classes
Program:
# Python code to illustrate
# classification using data set #Importing the required
library import pandas as pd from
sklearn.cross_validation import train_test_split from
sklearn.ensemble import RandomForestClassifier
from sklearn.preprocessing import LabelEncoder
17
from sklearn.metrics import confusion_matrix from
sklearn.metrics import accuracy_score from
sklearn.metrics import classification_report
18
print ('Report : ') print (classification_report(y_test,
predicted))
Output:
Confusion Matrix:
[[16 0 0]
[ 0 17 1]
[ 0 0 11]]
Report:
precision recall f1-score support
0 1.00 1.00 1.00 16
1 1.00 0.94 0.97 18 2
0.92 1.00 0.96 11 avg/total
0.98 0.98 0.98 45
19
Example in above Figure B, Output – Wind Speed is not having any discrete value but is
continuous in the particular range. The goal here is to predict a value as much closer to actual
output value as our model can and then evaluation is done by calculating error value. The
smaller the error the greater the accuracy of our regression model.
A regression problem is when the output variable is a real or continuous value, such as “salary”
or “weight”. Many different models can be used, the simplest is the linear regression. It tries
to fit data with the best hyper-plane which goes through the points.
For Examples:
Which of the following is a regression task?
• Predicting age of a person
• Predicting nationality of a person
20
• Predicting whether stock price of a company will increase tomorrow
• Predicting whether a document is related to sighting of UFOs?
Solution: Predicting age of a person (because it is a real value, predicting nationality is
categorical, whether stock price will increase is discrete-yes/no answer, predicting whether a
document is related to UFO is again discrete- a yes/no answer).
Let’s take an example of linear regression. We have a Housing data set and we want to predict
the price of the house. Following is the python code for it
Y = df['price']
X = df['lotsize']
X=X.reshape(len(X),1)
Y=Y.reshape(len(Y),1)
21
# Plot outputs plt.scatter(X_test,
Y_test, color='black') plt.title('Test
Data') plt.xlabel('Size')
plt.ylabel('Price') plt.xticks(())
plt.yticks(())
22
• Support Vector Machine (SVM)
• Random Forest
Chapter-3
23
When learning data contains only some indications without any description or labels, it is up
to the coder or to the algorithm to find the structure of the underlying data, to discover hidden
patterns, or to determine how to describe the data. This kind of learning data is called unlabeled
data.
Unlike supervised learning, no teacher is provided that means no training will be given to the
machine. Therefore, machine is restricted to find the hidden structure in unlabelled data by
ourself.
For instance, suppose it is given an image having both dogs and cats which have not seen
ever.
Thus, the machine has no idea about the features of dogs and cat so we can’t categorize it in
dogs and cats. But it can categorize them according to their similarities, patterns, and
differences i.e., we can easily categorize the above picture into two parts. First may contain all
pics having dogs in it and second part may contain all pics having cats in it. Here you didn’t
learn anything before, means no training data or examples.
24
For ex– The data points in the graph below clustered together can be classified into one single
group. We can distinguish the clusters, and we can identify that there are 3 clusters in the below
picture.
25
DBSCAN Density data
These data points are clustered by using the basic concept that the data point lies within the
given constraint from the cluster centre. Various distance methods and techniques are used for
calculation of the outliers.
2) Association: An association rule learning problem is where you want to discover rules that
describe large portions of your data, such as people that buy X also tend to buy Y.
Chapter-4
Today’s Machine Learning algorithms can be broadly classified into three categories,
Supervised Learning, Unsupervised Learning and Reinforcement Learning. Casting
Reinforced Learning aside, the primary two categories of Machine Learning problems are
Supervised and Unsupervised Learning. The basic difference between the two is that
Supervised Learning datasets have an output label associated with each tuple while
Unsupervised Learning datasets do not.
26
The most basic disadvantage of any Supervised Learning algorithm is that the dataset has to
be hand-labeled either by a Machine Learning Engineer or a Data Scientist. This is a very
costly process, especially when dealing with large volumes of data. The most basic
disadvantage of any Unsupervised Learning is that its application spectrum is limited.
Intuitively, one may imagine the three types of learning algorithms as Supervised learning
where a student is under the supervision of a teacher at both home and school, Unsupervised
learning where a student has to figure out a concept himself and Semi-Supervised learning
where a teacher teaches a few concepts in class and gives questions as homework which are
based on similar concepts.
27
A Semi-Supervised algorithm assumes the following about the data –
1. Continuity Assumption: The algorithm assumes that the points which are closer to each
other are more likely to have the same output label.
2. Cluster Assumption: The data can be divided into discrete clusters and points in the same
cluster are more likely to share an output label.
1) Speech Analysis: Since labelling of audio files is a very intensive task, Semi-Supervised
learning is a very natural approach to solve this problem.
3) Protein Sequence Classification: Since DNA strands are typically very large in size, the
rise of Semi-Supervised learning has been imminent in this field.
28
Chapter-5
Example: The problem is as follows: We have an agent and a reward, with many hurdles in
between. The agent is supposed to find the best possible path to reach the reward. The
following problem explains the problem more easily.
The above image shows robot, diamond and fire. The goal of the robot is to get the reward that
is the diamond and avoid the hurdles that is fire. The robot learns by trying all the possible
paths and then choosing the path which gives him the reward with the least hurdles. Each right
29
step will give the robot a reward and each wrong step will subtract the reward of the robot. The
total reward will be calculated when it reaches the final reward that is the diamond.
1)Positive –
a) Maximizes Performance
i) Too much Reinforcement can lead to overload of states which can diminish the results 2)
Negative –
a) Increases Behaviour
reinforcement learning:
30
Chapter-6
Sterp-2:
Click the Windows link (two lines below the Download Python 3.7.4 button).
31
The following page will appear in your browser.
Step-3:
Click on the Download Windows x86-64 executable installer link under the top-left Stable
Releases.
32
Click the Save
File button.
1. Move this file to a more permanent location, so that you can install Python (and
reinstall it easily later, if necessary).
2. Feel free to explore this webpage further; if you want to just continue the installation,
you can terminate the tab browsing this webpage.
3. Start the Installing instructions directly below. Installing Step-1:
33
Ensure that the Install launcher for all users (recommended) and the Add Python 3.7 to
PATH checkboxes at the bottom are checked.
If the Python Installer finds an earlier version of Python installed on your computer, the Install
Now message may instead appear as Upgrade Now (and the checkboxes will not appear).
Step-2:
Highlight the Install Now (or Upgrade Now) message, and then click it.
When run, a User Account Control pop-up window may appear on your screen. I could not
capture its image, but it asks, Do you want to allow this app to make changes to your device.
Step-3:
A new Python 3.7.4 (64-bit) Setup pop-up window will appear with a Setup
Progress message and a progress bar.
34
During installation, it will show the various components it is installing and move the progress
bar towards completion. Soon, a new Python 3.7.4 (64-bit) Setup pop-up window will appear
with a Setup was successfully message.
35
Step-4:
Verifying
To try to verify installation,
You should keep the file python-3.7.4.exe somewhere on your computer in case you need to
reinstall Python (not likely necessary).
As an existing or experienced Python user, you may wish to install Jupyter using Python’s
package manager, pip.
36
If you have Python 2 installed:
Congratulations, you have installed Jupyter Notebook! To run the notebook, run the
following command at the Terminal (Mac/Linux) or Command Prompt (Windows):
jupyter notebook
37
Chapter-7
MACHINE LEARNING
STEP-1:
Enter the following keyword in the command prompt shell for installing corresponding
Modules
1. PANDAS:
2. NUMPY:
3. SCIPY:
4. MATPLOTLIB:
5. SCIKIT LEARN:
6. SPEECH RECOGNITION:
7. PYTTSX3:
PROJECT WORK:
Why IRIS project:
39
• Attributes are numeric so you have to figure out how to load and handle data.
• It is a classification problem, allowing you to practice with perhaps an easier type of
supervised learning algorithm.
• It is a multi-class classification problem (multi-nominal) that may require some specialized
handling.
• It only has 4 attributes and 150 rows, meaning it is small and easily fits into memory (and a
screen or A4 page).
• All of the numeric attributes are in the same units and the same scale, not requiring any
special scaling or transforms to get started
40
Step-
2: Import Libraries
41
Step-
9: Data Visualization:
Univariate Plots
42
Step-
Histogram plots
Multivariate Plots
43
Step-10: Evaluate some Algorithms
44
45
Chapter-8
The FER2013 dataset ( facial expression recognition) consists of 48*48 pixel grayscale face
images. The images are centered and occupy an equal amount of space. This dataset consist of
facial emotions of following categories:
1. Angry
2. Disgust
3. Feat
4. Happy
5. Sad
6. Surprise
7. Natural
import numpy as np
import cv2
from keras.emotion_models import Sequential
from keras.layers import Dense, Dropout, Flatten
from keras.layers import Conv2D
from keras.optimizers import Adam
from keras.layers import MaxPooling2D
from keras.preprocessing.image import ImageDataGenerator
46
2. Initialize the training and validation generators:
train_dir = 'data/train'
val_dir = 'data/test'
train_datagen = ImageDataGenerator(rescale=1./255)
val_datagen = ImageDataGenerator(rescale=1./255)
train_generator = train_datagen.flow_from_directory(
train_dir,
target_size=(48,48),
batch_size=64,
color_mode="gray_framescale",
class_mode='categorical')
validation_generator = val_datagen.flow_from_directory(
val_dir,
target_size=(48,48),
batch_size=64,
color_mode="gray_framescale",
class_mode='categorical')
47
3. Build the convolution network architecture:
emotion_model = Sequential()
emotion_model.add(Flatten())
emotion_model.add(Dense(1024, activation='relu'))
emotion_model.add(Dropout(0.5))
emotion_model.add(Dense(7, activation='softmax'))
emotion_model.compile(loss='categorical_crossentropy',optimizer=Adam(
['accuracy'])
lr=0.0001, decay=1e-6),metrics=['accuracy'])
emotion_model_info
emotion_model_info==emotion_model.fit_generator(
emotion_model.fit_generator(
train_generator,
train_generator,
steps_per_epoch=28709
steps_per_epoch=28709////64,
64,
epochs=50,
epochs=50,
validation_data=validation_generator,
validation_data=validation_generator,
validation_steps=7178 // 64)
48
5. Save the model weight
emotion_model.save_weights('model.h5')
6. Using openCV haarcascade xml detect the bounding boxes of face in the
webcam and predict the emotions:
cv2.ocl.setUseOpenCL(False)
cap = cv2.VideoCapture(0)
while True:
ret, frame = cap.read()
if not ret:
break
bounding_box = cv2.CascadeClassifier('/home/shivam/.local/lib/python3.6/site-
packages/cv2/data/haarcascade_frontalface_default.xml')
gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2gray_frame)
num_faces = bounding_box.detectMultiScale(gray_frame,scaleFactor=1.3,
minNeighbors=5)
cv2.imshow('Video', cv2.resize(frame,(1200,860),interpolation =
cv2.INTER_CUBIC))
49
if cv2.waitKey(1) & 0xFF == ord('q'):
cap.release()
b6. Using openCV haarcascade xml detect the bounding boxes of face in
cv2.imshow('Video', cv2.resize(frame,(1200,860),interpolation =
webcam and predict the emotions:
cv2.INTER_CUBIC))
if cv2.waitKey(1) & 0xFF == ord('q'):
cap.release()
cv2.destroyAllWindows()
emotion_model = Sequential()
50
emotion_model.add(Conv2D(128, kernel_size=(3, 3), activation='relu'))
emotion_model.add(MaxPooling2D(pool_size=(2, 2)))
emotion_model.add(Conv2D(128, kernel_size=(3, 3), activation='relu'))
bre
emotion_model.add(MaxPooling2D(pool_size=(2, 2)))
emotion_model.add(Conv2D(128, kernel_size=(3, 3), activation='relu'))
emotion_model.add(MaxPooling2D(pool_size=(2, 2)))
emotion_model.add(Dropout(0.25))
emotion_model.add(Flatten())
emotion_model.add(Dense(1024, activation='relu'))
emotion_model.add(Dropout(0.5))
emotion_model.add(Dense(7, activation='softmax'))
emotion_model.load_weights('model.h5')
cv2.ocl.setUseOpenCL(False)
emotion_dict = {0: " Angry ", 1: "Disgusted", 2: " Fearful ", 3: " Happy ", 4: " Neutral
", 5: " Sad ", 6: "Surprised"}
emoji_dist={0:"./emojis/angry.png",2:"./emojis/disgusted.png",2:"./emojis/fearful.png",3:"./e
mojis/happy.png",4:"./emojis/neutral.png",5:"./emojis/sad.png",6:"./emojis/surpriced.png"}
global last_frame1
last_frame1 = np.zeros((480, 640, 3), dtype=np.uint8)
global cap1
show_text=[0]
def show_vid():
cap1 = cv2.VideoCapture(0)
if not cap1.isOpened():
print("cant open the camera1")
flag1, frame1 = cap1.read()
frame1 = cv2.resize(frame1,(600,500))
51
bounding_box = cv2.CascadeClassifier('/home/shivam/.local/lib/python3.6/site-
packages/cv2/data/haarcascade_frontalface_default.xml')
gray_frame = cv2.cvtColor(frame1, cv2.COLOR_BGR2GRAY)
num_faces = bounding_box.detectMultiScale(gray_frame,scaleFactor=1.3,
minNeighbors=5)
maxindex = int(np.argmax(prediction))
cv2.putText(frame1, emotion_dict[maxindex], (x+20, y-60),
cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2, cv2.LINE_AA)
show_text[0]=maxindex
if flag1 is None:
print ("Major error!")
elif flag1:
global last_frame1
last_frame1 = frame1.copy()
pic = cv2.cvtColor(last_frame1, cv2.COLOR_BGR2RGB)
img = Image.fromarray(pic)
imgtk = ImageTk.PhotoImage(image=img)
lmain.imgtk = imgtk
lmain.configure(image=imgtk)
lmain.after(10, show_vid)
if cv2.waitKey(1) & 0xFF == ord('q'):
exit()
52
def show_vid2():
frame2=cv2.imread(emoji_dist[show_text[0]])
pic2=cv2.cvtColor(frame2,cv2.COLOR_BGR2RGB)
img2=Image.fromarray(frame2)
imgtk2=ImageTk.PhotoImage(image=img2)
lmain2.imgtk2=imgtk2
lmain3.configure(text=emotion_dict[show_text[0]],font=('arial',45,'bold'))
lmain2.configure(image=imgtk2)
lmain2.after(10, show_vid2)
if __name__ == '__main__':
root=tk.Tk()
img = ImageTk.PhotoImage(Image.open("logo.png"))
heading = Label(root,image=img,bg='black')
heading.pack()
heading2=Label(root,text="Photo to Emoji",pady=20,
font=('arial',45,'bold'),bg='black',fg='#CDCDCD')
heading2.pack()
lmain = tk.Label(master=root,padx=50,bd=10)
lmain2 = tk.Label(master=root,bd=10)
lmain3=tk.Label(master=root,bd=10,fg="#CDCDCD",bg='black')
lmain.pack(side=LEFT)
lmain.place(x=50,y=250)
lmain3.pack()
lmain3.place(x=960,y=250)
lmain2.pack(side=RIGHT)
lmain2.place(x=900,y=350)
53
` root.title("Photo To Emoji")
root.geometry("1400x900+100+10")
root['bg']='black'
exitbutton = Button(root,
text='Quit',fg="red",command=root.destroy,font=('arial',25,'bold')).pack(side =
BOTTOM)
show_vid()
show_vid2()
root.mainloop()
54
Chapter-9
Testing
55
Chapter-10
CONCLUSION
In this deep learning project for beginners, we have built a convolution neural network to recognize
facial emotions. We have trained our model on the FER2013 dataset. Then we are mapping those
emotions with the corresponding emojis or avatars.
Using OpenCV’s haar cascade xml we are getting the bounding box of the faces in the webcam.
Then we feed these boxes to the trained model for classification.
Chapter-11
REFRENCES
DataFlair is committed to provide all the resources to make you a data scientist, which includes
detailed tutorials, practicals, use-cases as well as projects with source code. Did you like our
efforts? if yes, please give DataFlair 5 Stars on Google.
56