Noddy 2
Noddy 2
ON
Submitted to
PHAGWARA, PUNJAB
SUBMITTED BY
Page 1
DECLARATION
I, Saksham Rastogi (12008593), hereby declare that the work done by me on Six weeks summer
training from J u n e - 2 0 2 2 t o J u l y - 2 0 2 2 , is done with full dedication to meet
the learning outcome and certificate criteria for Object Oriented Programming using Python
from CODETANTRA.
I would like express my sincere gratitude towards CODETANTRA for providing the platform to
learn in depth about the programming language of Python. I would also like to thank my parents
and peers, who helped me to provide mental support for me to complete my training.
Finally, I would like to thank Lovely Professional University, for providing me the opportunity to
work on the training and produce my learning outcomes.
The world is tending towards an era of Automation from the past decade, devices are becoming
smart and intelligence is becoming artificial day by day. And the only way to create a control
over this fast paced automated world is to learn the language of the masses.
The masses translate to complex machines and languages translate to programming languages
which is one of the key reasons which prompted me to undergo this valuable training by
CODETANTRA
Learning any language helps us to reach to a limited number of machines at a certain time, or
take huge strides to reach any high complexity machine. But learning a popular language helps
us communicate with a wider array of machines which may vary from any zone of complexity.
This was another of my key reason to undergo this summer training on Object Oriented
Programming using Python from CODETANTRA
That was my most important point to undergo this training on Object Oriented
Programming using Python by CODETANTRA.
• OOP- Stands for Object Oriented Programming was a term coined by Alan Kay Circa in
the year 1967. The basics of OOP model states that any software should be a CLASS and
that class should comprise of OBJECTS and DATA, rather than any sort of
FUNCTION and LOGIC.OOP follows bottom up approach.
• POP- Stands for Procedure Oriented Programming follows a more primitive method of
programming associated with functions only. The functions are the point of object
utilization and each function can communicate without any hierarchical structure unlike
OOP. POP follows top down approach.
• COMPILERS- Compilers are special programs, which converts High Level Codes into
machine level codes i.e low level codes. The main principle of compilers is to take the
whole program at one instance and convert it at a single go.
• VARIABLES: These are containers which holds changeable data in them. Variables are
one of the most essential components of any programming language. They are used to
pass the data used in the program to process an output.
• DATATYPES-Are the type of data stored in variables. Similar types of data type can be
used to perform similar types of functions. Examples of datatypes are- int,
double,char,etc.
• TENSORFLOW- An open source framework for machine learning has a lot of packages
and tools useful training and predictions of datasets. One of the packages use in my
project was keras from tensor flow, which provides optimization to the datasets passed in
the program.
• EPOCHS- It is a cycle of machine training which gives a score at the end. EPOCHS are
cycles of to and fro from a Artificial Neuron. It uses the data provided to it and goes to
and fro until a suitable threshold value is achieved. The time taken to achieve the
threshold value is the EPOCH score.
Looking upon the evolution of High Level Programming languages, one thing makes the
principle of evolution clear, increase of power and productivity.
So keeping these points in mind, let me state the reason for choosing to do a training Python
Programming Language:
• OOP capabilities: The POP approach for C was a good idea for the initial start,
but the most important drawbacks of POP is the reason, the OOP module was
opted by it’s successor C++, management. POP was based around functions and
logic, which proved to be huge challenge for storing and managing data, OOP on
the other hand is based around objects and classes modules, which proves to be
much easier to handle data for the software. Python being the latest iteration of
OOP programming language makes it an obvious choice for the above reason.
• A productive language: Might not be the most powerful language but definitely, a
productive language. Housing a huge amount package storage, Python is one of
those languages which can deploy machine learning models with relative ease.
With the “simple” installation of Tensor flow into any python IDEs, you can
easily deploy CV2 capabilities to detect images and produce revolutionary
products like face detectors, optical fingerprint sensors and a lot more.
• Leading programming languages: And last but not the least, the prime reasons
or me choosing this programming language is being one of the leading
programming languages in this growing market of technology. Being and
Artificial Intelligence enthusiast and a newbie to programming language
definitely puts me in a prior position to choose this programming language for
sure.
• Classes and Objects: The most basic principle of OOP as discussed earlier is dividing a
software into classes and objects, but how are they co-related to each other? To speak in
Layman’s terms, a class is a collection of objects. It’s a key term every programming
student is taught at the starting of any OOP language. Lets elaborate it further,
Class can be compared to group of any things, these things have to be necessarily
placed inside the class one way or the other. For example: A Class of students were
every student in the class, belongs to that class.
Object similarly on the other hand can be compared to students who are present inside
the class, objects are functional things which constitute together to give an output whole
as a class, Effectively called objects are also called instances of a class. Looking from a
software’s perspective, objects are the individual modules which comprise together to
give an output to a class i.e Software in this case.
Comparing these things with the previous generations of POP languages like C, we can
understand how much important it is to group things under specific groups. This is the
most key factor for the usage of OOP languages as a trend.
• Methods/Functions: After grouping all the objects separately under separate classes, we
can proceed to the step of utilizing those things to produce the output we desire. That is
where methods come into play. Methods or Functions are one of the most
fundamental components of for a functioning class. In a single line, ‘functions
provide functionality to a class’. Combining with syntax and objects storing data,
functions help the class utilize the data to produce a productive output.
Now, Functions are divided into two types, i.e Pre-defined and User Defined functions:
Pre-Defined functions are those type of functions which are already defined inside the
programming language, they are defined inside a particular package which when
called, can be utilized fully without any hindrance. Example: the print() statement.
a=1,b=2
print(a+b)
• Abstraction: A concept of OOP which says, ‘show essential details and hide
unnecessary details’. Abstraction is one of the key concepts of OOP which hides,
unnecessary information from the standpoint of users, in order to make them focussed
into the main program.
Abstraction also helps in security purpose also, as in hiding important information in the
program in the way we hide unwanted details. This is one of the valuable features of
OOP.
• Encapsulation: ‘Wrapping up of data into a single unit’, explained into a single line,
Encapsulation basically means constituting every objects, every functions and every
class into a single unit which collectively in programming language is a package.
The concept of encapsulation is one of the essential concepts in OOP languages. It is one
of the reason due to which, arranging and accessing of data is made simple in OOP
programming languages.
Let’s take a real life example, synonymous to the term encapsulation, we’ll take a capsule
for an example. The capsule comprises of ton of chemicals as classes and the chemicals
comprises of ton of matters as objects. All these things are packed inside a single small
unit of capsule .
Page 15
Inheritance: As much as it’s real world meaning, Inheritance is one of the key concepts of OOP. In a
single line ‘inheriting objects and classes from another class’. One of the best features of OOP languages
is the concept of hierarchy. This prompts a ‘parent child relationship’ where children inherit the objects
and classes of a parent child.
Inheritance in OOP allows functions and classes to communicate with other functions
and classes present in a particular package.
In Python, Association is also used as a type of inheritance, Association bascically states
the relationship between two classes without any bounded rules.Association comprises of
Composition and Aggregation.
def disp_name(self):
print(self.first_name, self.last_name)
x = Person("John", "Doe")
x.disp_name()
print(add(2, 3))
print(add(2, 3, 4))
The above function first prints the sum of 2 and 3 and in the next calling, performs
addition of 2,3 and 4.
• Lists: One of the most widely used data type in Python Programming Language, Lists
are mutable data types which helps in storing multiple values/data items of any data
types. The word mutable means any data item of any data type can be replaced without
any hindrance.
Example: a = ['Shayan', 4, 4.70, True, "World", 2.0, "False"]
In order to extract values from list, we use indexing along with the list’s name to extract a
particular data item at a particular area of the list.
Example: print(a[3]) will print “True”
• Pandas: These are packages, which help in data analysis. Specialized in data
science, pandas are used to create relationship between multiple data values.
Syntax: import pandas as pd
• Matplotlib: Matplotlib is used to depict the relationship between two data items or
datasets in the form of graphs. The most basic use of Matplotlib is to visualize any
relation if we want to present to anyone or if we are having hard time in figuring out
any relationship
Syntax: import Matlplotlib.pyplot as plt
The image shown above is an output of how the algorithm, dissects an handwritten
structure to change it’s properties according to one’s wish. Let me explain how wrote the
code.
• Packages: The Model uses, Keras, CV2 and our good old friend Numpy to achieve to
analyse any handwritten script and then, alter its shape, resolution and size according to
users wish.
How it does this is something worth explaining:
Sequential model present in keras provides training and inference features on the model.
Since we created a machine learning model, so it is destined to require training from
images. The way Sequential groups layers into tf.keras.Model is by stacking them into
linear layers.
Dense, Dropout and Flatten are used for feature engineering in the model grouped into
Sequential model. Dense layers can be used only when association can exists between
two features, Dropout in a single line, is used to prevent the problem of Overfitting.
Dropout sets the input frequency to 0. Flatten basically does what the word says,
‘Flattens the input’. Flatten basically adds an extra channel if the input does not have
a y-axis.
Convolutional in keras helps to create tensored outputs with the dimension provided during
declaration. Here, we use Convo2D because we are trying to achieve a 2D output.
Categorical is used to convert a class vector into binary class matrix. The class vectors
have to be of integer type essentially.ImageDataGenerator generally converts the
obtained image input into tensored object.
Numpy: Last but not the least, Numpy stands for Numerical Py(Python) provides
Numerical functions to any python class that’s running on it’s import.
In the lines above, we are calling the feature and grouping them in training and
testing datasets. Reshapes are required if the features happened to be uneven,
uneven features lead to bad predictions, so it’s an important step.
X_train /=255
X_test /=255
y_train = to_categorical(y_train,10)
y_test = to_categorical(y_test,10)
y_train[:3]
So, this is an essential step to produce a good Machine Learning model. Feature
scaling is the next step to features reshaping. Here we used the Categorical to
convert the integer vectors of the class into binary class matrix.
test_gen = ImageDataGenerator()
train_generator = train_gen.flow(X_train, y_train, batch_size=64)
test_generator = test_gen.flow(X_test, y_test, batch_size=64)
model.fit_generator(train_generator,steps_per_epoch=60000/64,
epochs=15,
validation_data=test_generator,
validation_steps=10000/64)
The final step for creation of the model is compiling the trained the model. By
using the generator() function, we can generate training scores in the form of
‘epochs’.
In this step, we assign categorical to make class vectors of integer value, in order to use
them in the trained Machine Learning Model.
In this step, we check the accuracy score of the model. How well it performed on testing
data after being trained on the training data.
img=cv2.imread('sha.png')
img.shape
plt.imshow(img,cmap='gray')
We upload the image show below for the model to process, it’s a handwritten script:
While undertaking the project, there were a lot of things that I pinpointed
had helped me to learn new things:
• Easy accessibility: Knowledge boundaries was set high for Python being a
relatively new language but this disadvantage is the biggest boon for the
language. Python has a huge technology accessibility boundary for usage of
new technology.
You can create, GUI based interfaces, mini games, train AI machines and a lot
more with this single language. This is a single reason which makes Python a
good language for beginners, may not be perfect. Maybe the weight of the
programs created might be a bit heavy but still, the style of commands make
the language easy to learn and use.
In conclusion, I would like to say that I learnt a lot from undergoing this training and Project
creation. It helped me introduce to new technologies and helped me in doing experimentation
with them. I look forward to extend this experience to fully fledged mastery and want to
extend an helping hand to the industry world.