Python Built-in Functions in TensorFlow

Hey peeps! Welcome to an exciting tutorial on Python in which you will learn about the Python reverse list. We are on a series of deep learning phases where Python is under our observation. In the last tutorial, we saw the variables in Python and practised many codes in the TensorFlow. Today, we are interested to practice many interesting methods in an easy way. These are the built-in functions and you do not have to be an expert in the programming to perform them in TensorFlow. All you need is to read this tutorial and have the TensorFlow working fine. Before going deep into the topic, it is important to have a look at the list of content that you will learn today:

  • How do you define the python reverse list?

  • Why we should know about the python reverse list or keywords?

  • How do you practice the codes of Python reverse list in TensorFlow?

  • What is the core difference between some related keywords that seems to be work relatively?

  • How do you run some loops in the Python while working on the TensorFlow?

All these concepts will be cleared by discussing them in detail and while using the codes, you must keep in mind, there are more than one way to run the program in your own way but the one that we have defined in this lecture are the precise one and these are enough to understand the concept that we want to share with you. So work smarter then to word harder.

Python Reverse List

We know that there are some rules that have to be followed when you are naming your variables in python. Usually, these rules are applied to almost all the present programming languages but we are specifying Python because we want to connect this discussion with the Python reverse list. There are some restricted words that cannot be used as variable names. These are pre-defined in each language. You can define it in the following way:

"The Python reverse list (also known as keywords) is the complete list of pre-defined functions that are already stored in Python and these particular names are not allowed to be used as the name of variables while coding."

If you go into the detail, there are hundreds of reverse words in Python but this will be out of the scope of this course. For your information, we have added some very common keywords that you have to learn and practice to keep in mind. IT WILL HELP YOU A LOT WHEN YOU WILL WORK WITH THE COMPLEX AND LONG CODES. In Python, the following table is useful to understand what kinds of names are not allowed.

Python Reserve List

True

del

false

def

not

elif

as

class

if

break

return

  None

else

with

for

lambda

except

yield


The list does not end here, but I think it is enough to understand what types of variable names must not be used when you are practising deep learning with the help of TensorFlow (in our case). 

Python Reverse List in TensorFlow

Once you have read about the reverse list, you must practice it for the practice. Here, we are using some of the variables from the list given above. To practice it on TensorFlow, you have to follow the steps given next:

  • Open your Anaconda navigator to use TensorFlow.

  • Navigate to the environments and start the Jupyter lab.

  • The screen here will show you the cells where you can write the codes. 

  • Start writing the codes using the keywords from the list mentioned in the above table. 

Def in Python

The declaration of a function is done by using the “def” keyword. There is no need to tell the compiler the type of variable. After that, you can use this variable in other operations. Have a look at the code.

def welcome(name):

print (f"{name}, Welcome to theEngineeringProjects")

welcome ("Student")

The output of this program is given next:

Hence, you can see that we have declared the variable “welcome” and then provided the string in which we are using the function that we specified for ourselves. In the next line, we simply provide the value of the variable for that given string. You can simply change the value of a function in the last line to change the name with the same string. 

False in Python

This is a different type of keyword than in the previous case. The value “false” is declared by the compiler if we are providing information that is universally wrong. The best example in this regard is the one in which we are trying to equilibrate two different values of numbers.

The compiler is intelligent enough to clarify that the command given by you is not right. 

true in Python

This is the other simple keyword that is shown by the compiler itself, and if you are familiar with the keyword “false” given above, then it is obvious that if a universal truth or condition is fulfilled, the compiler will provide the answer in the form of the “true” keyword, as can be seen in the next image:

Another thing to notice here is, the string, or other data types may also be used with teh equality operation but as we are mentioning again and again, the Python is the case sensitive therefore, if the alphabets are the same but the case is different, the result will be contrary to the one given above:

The “L” of the second name is capitalized and therefore, the compiler is recognizing it as a different letter. It is the reason we are getting the “false” keyword as result. 

del in Python

 As you can see, del is the short form of the “Delete” operation, and therefore, you can use this to delete any specific entry, value, or object from the list or the code. Here is an example of how to do so:

subjects = ['Physics', 'Chemistry', 'Biology']

print(subjects)

    #applying the delete option

del subjects[1]

print (subjects)

When we put this code in our cells, you will get the results as expected:

At the start of the code, we declared an array of named subjects. You will learn more about these concepts in detail, but for now, just keep in mind that we have a group of sciences in our array, the index of which starts from 0. So, when you delete the first entry that is under the second name, you will get the list with only two entries.

None in Python

Here is another keyword that is used in Python for your convenience. You can think of the “None” keyword as a blank space or an empty container. Take the example of the case when the user does not put the information required on a survey that is necessary to answer, then he/she gets the error from the website that this is a required field and therefore, the user has to put the information in it to move forward. This is best understood by the code given next:

Here, you can see the error message that appears when the required field is empty and the user wants to proceed. 

If statement in Python

The “if” is a special keyword in Python, and you cannot name it as a variable because it is against the rules. This is the name of a loop, and you must know that loops will be discussed in detail when you proceed in this series; therefore, we will not explain too much about this keyword. But for now, have a look at the code given next to get an idea about the workings of this reverse word

number = 300

if number >= 18:

 print("You are eligible to become an Engineer")

Output of this code is given as:

raise in Python

Here is an interesting keyword that uses words in a very useful way. We have seen the error indication in different websites and other platforms where the user input the data and if it is not according to the rules of the input data then the screen shows the warning about the error. It can be done with the help of the raise keyword in Python. Let us take the case in mind where you have to provide your name in the form, and if the user provides the numbers rather than the name, then it will throw an error at you. 

name = 123

if not type(name) is str:

       raise TypeError("Only strings are allowed.")

So, it is clear that you have to put the name in the form of a combination of alphabets. By looking at this program deeply, we have seen the following points:

  • It is important to specify the type of content that you want to allow.

  • The “if statement” is also used in this program so that we can use more than one keyword in one line. 

  • You can also change the type of content by specifying it in the first line. 

  • The name of the variable does not matter. 

  • By deleting the word “not” in the second line, you can invert the whole program. 

  • In advanced programs, you can add more than one condition to apply all the necessary information so that any illegal way to type the name can be detected and the error may be shown. 

return in Python

The return keyword looks like the print function in the code, but both of them are not the same. The return function combines two or more results, and then control is given to the print function, which displays the results on the screen. Here is the program to do so. 

def sum(x, y,z):

       return x + y + z

print (sum(55,7,34))

The TensorFlow output is as follows:

Here, we have written a program that calculates the sum of three numbers. The start is done by using the define function, and here, we define a function that defines the pattern. This pattern will be used in the future. In the second step, the “return" function specifies the way the three components will work. In the third and last step, the values are put into the print function so that it may show us the result. This can be done in another way if we initialize another variable in which the result of summation is stored, and then we put that particular variable into the print function. The second way is more practical, but it occupies more space. 

In addition to this, you must know that you can specify any number of elements in the formula in the first step. If the pattern contains more than three elements and you do not have a large number of elements to test, you can enter "0" in place of the extra elements, but you must follow the pattern and cannot enter fewer than the specified number of elements.

elif in Python

Here is the last keyword to explain in this lecture. It is the combination of two words, “else” and "if,” and it is used in the loops. You will practice a lot about the loops in the coming sessions; therefore, I am not explaining it much. But for now, you must know that when you want to add more than two conditions to a program, you use this keyword. In the language of C++, we use the else if the keyword for the same purpose. So, have a look at this program:

So, the user with knowledge of artificial intelligence is more likely to get the skills of deep learning, and we have made this program to show you this.

So, it was a helpful tutorial to learn a lot about the Python reverse list. These are the keywords that are pre-defined in Python, so it is not advisable to name your variable exactly like these. If you do not follow this rule, the compiler will be confused between your defined variable and the keyword saved in it, and therefore, it will throw the error. You must know that there are more words in the list, but for now, it is enough to understand and practice the words mentioned here.

Types of Python Variables in TensorFlow

Hey learners! Welcome to the new lecture on deep learning, where we are using TensorFlow to learn it with the help of Python. Previously, we worked on the syntax of Python, and now it's time to discuss the variables in detail. There are some variables that you will learn about as well as get hands-on experience within TensorFlow. These are important concepts that will help you throughout your coding career. If you are new to programming, this is a crucial concept for you, and if you know it already, you can use this tutorial to polish your concepts. We will move forward after looking at the list of content for this lecture:

  • What are the variables in Python?

  • How do you assign the value to the name of the variable in Python?

  • What are some rules to define the name of the variables?

  • How do you declare or initialize the variables in Python?

  • Can you get the type of variable that is declared before?

  • What is the difference between statically and dynamically typed programs?

  • What is the purpose of re-declaration in Python?

Introduction to Variables in Python

In the previous lecture, we mentioned the name string, and the difference between the string and character is just the amount of storage these two occupy. The reason these are important to understand is to use an accurate way to store our data. This will be clearer when you see the introduction of the variables in Python:

"In Python, the variables are the containers that store the information in them and are defined as the name given to the location in the memory."

We all know that when a program is saved in the compiler, it allocates a specific amount of memory. Variables in Python work differently than variables in other programming languages such as C++ and C#. In these languages, the programmer has to define the type of the variable and allocate the specified amount of memory required to store that variable. Still, in Python, the program statically types. The other type of program in this regard is dynamically typed programming. For your convenience, I have made a comparison between these two types:

Sr#

Statistically Typed Programs

Dynamically Typed Programs

1

The checking in the code for the error is done before running the program. 

The checking for the error is ignored at the compile time and is done in the run time. 

2

The type of the object is known by the variables. 

The variable does not know the type of object but the object knows itself. 

3

At compile time, the “Unsafe operation” is rejected. 

The “Unsafe” operation is rejected at the runtime. 

4

Example: C++, C

Example: Python, PHP


So, Python is easy to understand, and you do not have to work hard for the declaration of variables of a different kind; most of the time, the declaration is super easy. You will see this when we work on the examples of the variables in just a bit. 

Assigning the Values to the Variables

When declaring the variables, you have to be very careful about the data you are placing in different containers. The reason behind this is, there are hundreds or more than it variables in the code when we start professional coding in Python. In such cases, it is important to memorize the name and working of the variables instantly. It is not advisable to name the variable without following any logic to memorise the exact information about that particular variable. The list of the variable is shown on the side of the TensorFlow but the working must be shown with the name of your variable.

For example, if you are declaring the variable that calculates the sum of numbers then the name of that particular variable must be “sum” or “addition”, or any other word that describes the function otherwise if you are naming it as “x”, or “var1” then you have to think for some moment that why you had initialized these variables. This rule is also beneficial to the case when the code is read by the other person or if you are sharing your code with the other person to work further on it.

Here, you must know, the code that we are practising is tiny and these are easy to understand to make the points clear to the beginners as well but at a professional level, the coding is different and you have to make sure that you are writing a clear, clear, and easy to understand code as the code in such cases are too long and contain many concepts in a single line sometimes.

Rules For the Variables in Python 

For the declaration of the variables in the Python programming language, you have to follow certain rules, and for the convenience of the reader, we have made the points, and there is no need to memorize them; you just have to read them first.

  • The name of the variable must always start with the alphabet or the underscore character; otherwise, it is against the rules. 

  • The variable name does not start with the number. You can use the number in between the alphabets of the variable name, but not at the beginning. 

  • Symbols are not allowed to be used in the variable name. In other words, you can use only alphabets (A to z, in which the case of the alphabet does not matter), numbers from 0 to 9, and the underscore only. As a result, you can't use symbols like @, #, and $.

  • Variables name is case sensitive. This can be understood with the example that the variables Type, Type, and Type are totally different, and these are the names of three variables. 

  • The declaration of the variable may be done with the help of a single alphabet as well such as x, j, y, etc. But it can't be a single number such as 1, 2 3, and so on.

These are the universal rules, and usually, the programmer creates his or her own code of conduct in order to ensure that he or she always follows the same route to write the code, making it easier to understand the old codes written by him.

Variable Declaration in Python vs. Other Programming Languages

Another reason why we say that Python is an easy and convenient programming language is that the declaration of different types of objects is easy in it. As we are studying the variables right now, I must tell you that in other programming languages, you have to declare the type of the variable first and then give it a name. You can set the variable's value either at the declaration or on the following line by providing the name and value. An example of the variable declaration in C++ is given below:

Int x=78;

or int x;

x=78

In contrast, when working with variables in Python, you do not need to define the type of the variable and can simply give it a name and a value. As a result, the program's work is simplified because the Python compiler is intelligent enough to recognize the type of the variable on its own and does not require the user to specify it. Here is the example that verifies the information given here:

Similarly, when you are declaring the string or character, you will simply declare it with the name and value without specifying the type. 

#Declaring the Character

character='Python'

print('Character is "', character,'"')

#Declaring the String

string="We want to work with deep learning through Python."

print('string is "', string,'"')

Just look at the output, and then I'll discuss the details of the code.

The following points are proven with this code:

  • The name of a variable may be anything, and the value determines the type of variable in Python. It can be understood with the fact that even if we name of a string is declared as a character but detail the value has double quotation marks around the values, the compiler will read it as the string and it will occupy the space in the memory accordingly. 

  • Comments in the code are totally ignored by the compiler, and these are helpful to understand the block of code defined by it. 

  • In the print function, if you want to show the values as they are, you write them in single quotation marks, and if you want to declare the value stored in the variable, the variable is written as it is. 

  • To separate the printed message and the name of the variable, we use a comma between them. 

  • Using the single "print" function, you can print multiple variables or messages. 

  • While printing more than one output on the screen, you do not have to use indentation these print functions are non-consecutive. 

  • In Python, the single quotation marks are equal to the double quotation marks but as we have seen that both of these are different in other programming languages, to illustrate the type, we have used both examples. 

The types of data will be given in the next session, where you will learn a lot about them.

Getting the Type of The Variable in Python

If you do not know the type of variable and want to get the related information for different types of operations, Python has a special pre-defined function that works in a simple way. You just have to put the value you want into the “type” function. The syntax of the “type” function is given next:

print(type(variable name))

Hence, the type of the variable will be printed on the screen. This can be best understood when you see some examples in TensorFlow. To do this, write the following code in the TensorFlow cell:

a=56

b="Deep Learning is easy with TheEngineeringProjects.com"

print(type(a))

print(type(b))

As soon as you will pop the play button, you will get the results as follow:

The reason why “class” words are used here is that Python is an Object-Oriented programming language, and it makes the classes perform the operations; therefore, it has presented the results in the form of classes. 

Re-declaration of Variable in Python

Once you have learned about the declaration of the variable, you might be thinking that the single value may be assigned to the single name only, but it is not true all the time. Suppose if you are using a large number of values in a program that will be used only once and you do not want to suggest single name to a single value, you can declare the variable again and this method is called the re-declaration. Have a look at the example to do so:

a=45

print("The value of the variable is", a)

a=90

print("The value of the same variable is now", a)

So, you have simply masked the first value and given the same name of the variable to any other value. But in such cases, you cannot get the previous value back until you provide the first value to the name again. This is the reason why we call them "variables,” which means the non-fixed process. The values in the variable keep changing over time according to the needs of the program and the code written by the programmer.

Hence, it was the day when we learned a lot about the variables in the Python programming language. We have seen a lot of information about the variables and seen how you can introduce and work with the Python variables in different ways. We have compared the declaration of the Python variables with the other programming languages and also got information about the statistically typed programs versus the dynamically typed programs. Moreover, it was interesting to know about the type function and the declaration of the variables in Python. I hope it was an informative tutorial for you and that you will practice more to get experience coding in Python.

Syntax of Python in TensorFlow

Hey learners! Welcome to another deep learning tutorial, in which we are beginning the practical implementation of Python on the TensorFlow library. We installed and checked TensorFlow in detail while we were in the previous lecture, and today we are going to use it for our practice. We have checked the presence of a perfectly installed library of TensorFlow in our tutorials and seen the basic structure of this library. As a result, we will skip the details and jump right into learning Python. In this tutorial, the main focus will be on Python instead of learning the workings of TensorFlow. You have to remember one thing: all the discussion will be from the point of view of deep learning, and it is not a general tutorial in which you will learn to develop apps or have a discussion about the details of Python; we will learn all the basics in detail, and after that, you will see Python in the field of deep learning. But first of all, we are showing you the list of content that you will learn in this lecture:

  • How do you introduce the syntax of Python?

  • What is the syntax error, and how do you define the other types of errors?

  • How can you execute the instructions of Python in TensorFlow?

  • How do we print the message in different ways while using Python?

  • What is an indentation in Python, and why is it important?

  • How can you use comments in Python?

These all concepts will be cleared as we are going to discuss all of them one after the other with the practical implementation and no step will be missing so let us discuss the detail of each of them.

Syntax of Python

As we all know, the syntax is the most important thing that you must know, even if you are typing the simplest program in any programming language. All these programming languages are recognized by their syntax, and even a single mistake with a semicolon matters a lot. When talking about Python, we have mentioned many times that it is a simple and easy programming language that is easy to understand. Before going into detail, I want to show you the definition of the syntax, and after that, we will link this to Python.

"In programming languages, the syntax is the set of predefined rules that communicate with the computer and tell it how to read the code."

 This is the combination of alphabets, numbers, and symbols in a specific way and the programmer always has to follow these rules otherwise the computer will throw errors. Most of the time, the compiler shows the suggestions if the code is slightly different from the one that must be followed. But it is not true all the time. There are two types of errors:

  • Syntax error

  • Logical error

  • Runtime error

The details of each of them are given next:

Syntax Error in Python

In the compiler, syntax errors occur when the programmer does not follow the syntax of the language exact, and the compiler is not able to understand the exact operation. Therefore, it shows the error and is not able to perform the required function. As the instructions are pre-defined, they show the list of errors and the possible solutions to the problem. This solution may be in the form of an instruction, a statement, or any other clear indication of where the error is present and how you deal with it. 

Examples of Syntax error in Python

There are many ways to show you the exact information, but I am choosing the basic way to do so because many beginner-level programmers are also there and they need the information from scratch. The discussion above will be clearer with the help of the example given below.

Here you can see that the compiler does not know the correct spelling of the command given to it, but the point to observe is that you get the suggestions and other statements to solve the error.

Other Types of Errors

The other types, which are the logical and runtime errors, are important to discuss here because, in this way, we can differentiate them better. When talking about logical error, you have to be very clear about your instructions and have to provide the best path to the compiler so that it may solve your code and present the right output. If there is a mistake in the logic, or, in other words, if you are telling it to compare illogical things or do a task that is not possible in real-time, it will not accept it and will do exactly as per your instructions, but the required results will not be obtained. This situation worsens when the programmers' concepts for solving the given problem are unclear, making it difficult to identify the error in the code.

Contrary to this situation, we observe another type of error that is a run-time error. A pure run-time error is one in which the logic and syntax are completely correct but you still do not get the desired results because the program does not receive the error during compilation but is unable to retrieve the required information from the code at runtime. The difference between logical and runtime errors is that in logical errors, the program is not compiled well because of illogical or incomplete information, whereas in runtime errors, the compiler is able to compile or gather all the information but the program is not complete because of the missing information that is to be gathered from the other piece of code. At this time, I do not want to discuss more these two error types more; my focus is on the syntax error. Truss, have a look at the table below that describes all these errors at a glance.

Name of the Error

Short Description

Possibility

Complexity to Identify

Example

Syntax error

Errors occur due to incomplete or incorrect syntax.

It happens mostly if the programmers have little practice typing or are beginners.

The compiler provides suggestions in the errors, making them easy to identify. 

Spelling mistakes, using variables before their initialization, and missing the opening or closing of the brackets. 

Logical error

Occurs when unrealistic logic is applied to the code.

These errors usually occur when the concepts of the programmer are not very clear. 

Difficult to identify the mistake. 

Infinite loops, incorrect boolean operations, the wrong type of brackets.

Runtime error

While the information is incomplete in the code and the compiler does not get the required data, the program is not run, and therefore, we get the runtime error.

These errors happen due to the carelessness of the programmers. 

Usually, the instructions from the compiler are enough to identify the runtime errors. 

Demanding the information from an array with a position that is not present in that array, getting the result from the loop that is not yet been completed yet. 


Executing The Python Instructions

The Python instructions are clean to execute, and you have to be very clear about the syntax before getting started. We believe that some of the instructions are well known to you, but for the sake of practice and to prevent any gaps in learning, we are discussing all the basic information here. 

Printing the Message in Python

The first program that is obvious to practice while programming is the Hello World program, which is always practised when learning any programming language. But I want to do something different. Instead of writing the "hello world" program, I would like to write any other message. For this, you just have to follow the instructions given next:

  • Search for the installed software of “Anaconda Navigator” and run it on your PC. 

  • Go to Jupyter Lab and launch it.

  • You have to write the code in the cells given on the screen. 

  • The syntax for the printing of a message in the form of the string is given as

print(“You message”)

So, you have to follow some important rules all the time when you want to print something. 

  • Write the keyword “print” to show any message.

  • The spelling must be exactly the same; otherwise, you will get a syntax error. 

  • The text should be wrapped in parentheses. 

  • The right data type should be mentioned. (You will learn a lot about the data types in the coming lectures, so do not bother about it.) You must know that you wanted to print the string message; therefore, you have used inverted commas.

  • There is no restriction on printing the specific message between the commas; in other words, if you make a spelling mistake or make another type of statement, the message will be printed as is and the compiler will not throw an error. Yet, the syntax should always be followed strictly. 

Once you have followed all the rules, the result obtained on the screen will be like this:

Here, you can see that the message is printed as it is in the next line, which is the output line. 

In programming, there are different ways to perform the same task, and you can choose any of them. Now, the printing of the message can also be done in another way if you do not want to print the string. You can do so with the help of variables.

We hope it is clear to you, but if you have any ambiguity, you can learn this in our upcoming lectures. For now, just look at the fact that we have stored the message in the variable and then fed this message into the print command.

Rule of Indention in Python

While we say that coding in Python is simple, you may be surprised to learn that there is an indentation rule in Python. We all know that indention is the way of writing or typing something in with a gap at the start. Here is an example of the code without indentation.

You can see that the syntax and all other parameters are okay, yet you have to write the blacks with indentations to identify their separations. So, we are just making these simple changes and trying to run the program. Let’s see what happens.

Important Tip 

As a programmer, you must know that you can specify the number of spaces of your choice, but the range is between one and four spaces. Moreover, if you have a bigger code than this and provide more than the required number of spaces, you will again get the error of too many spaces. So the number of spaces must be precise. Moreover, for such codes, the number of spaces must be equal. For example, if you are using more than one print function, then these two must be equally indented; otherwise, you will get the error.

Comments in Python

Most of programming languages have the "comment" option. These prove convenient and are also interesting to know about. The comments are defined as:

"The comments in the programming languages are the additional notes and instructions that are saved by the programmer itself and ignored by the compiler."

The comments start with special symbols to tell the compiler that the line after this symbol is to be ignored. All the programming languages have different symbols to do so, but in Python, the hashtag sign is used, and the line after this hashtag is totally ignored so that you may store the notes in that line.

Observe that your message is ignored fully, and the compiler has just printed the message without any error. Comments make the code more readable and easier to understand. The comments are usually italicized and have a different color than the usual code.

Therefore, we have learned a lot about the syntax of the programming language and how important it is to follow the syntax. We have seen the different types of errors and have learned the print command, indentation, and comments in detail. It was an interesting lecture and be with us for the advanced learning.

Getting Started with Python in TensorFlow

Hey students! Welcome to the fantastic tutorial of this series, where we are talking about deep learning. Till now, the discussion has been about artificial intelligence, deep learning, and TensorFlow, but today’s lecture will change the type of discussion from the previous one. You will see that we will now talk a lot about the Python programming language and will connect all the discussions with TensorFlow. You will see the reason for both of these choices in just a bit, but before that, I want to show you the list of the concepts that will be cleared today:

  • What is the Python programming language when we are talking about deep learning?

  • Why did we select Python for deep learning when there were other options?

  • What is the importance of TensorFlow when we are learning deep learning by keeping Python as our programming language?

  • What is the Tensor Processing Unit?

  • Do we have the projects on GitHub for inspiration for the learning of this course?

Introduction to Python for Deep Learning

The general introduction to the Python programming language differs. You can see the introduction of Python in a different way. Still, as we are learning it for the sake of deep learning, I am keeping that perspective in mind and introducing it as:

"Python is the programming language that seems to be ideal for deep learning because it has special libraries and an AI-based structure of working that makes it perfect for AI and related fields."

We have some other options for the working of deep learning subjects, but Python is one of the most convenient languages if we are talking about the syntax, working, or cleanliness of the programming language. You will see more points that prove the importance of Python for the working and learning of the subject and the applications of the deep learning subject in the next section.

Why Python for the Deep Learning?

Artificial intelligence is a different subject from other programming languages. For the implementation of these unique concepts, it is important to have a programming language that provides easy working and other different facilities for the best performance. Python is near all these requirements, and our discussion will be clear with the evidence of some points about Python given next:

Simplicity of Python

The first and most important point that every Python lover mentions is the simplicity of this programming language, which is a plus among other options for programming languages. Python provides us with clean and simple syntax in which simple lines perform complex operations, and you do not have to take care of difficult syntax such as semicolons at the end of every line, etc. In this way, developers have to focus on machine learning and deep learning instead of solving the difficult and small eros that are difficult to detect by the user. This language is close to the human language, and Python is one of the most popular programming languages because programmers are attracted to its ease, especially beginners.

Consistency in Python Language

When it comes to deep learning, the first thing to remember is consistency. It is because of the complex and unique concepts involved in the training process that every learner faces while practicing artificial intelligence and related subjects. As a result, Python is the programmers' first choice because it is less error-prone and has the fewest lines of code for the various functions used in deep learning. 

People who use Python are the most consistent in deep learning while working with it because it is a general-purpose language, and thus various types of training and work can easily be done with the help of this language; you do not have to work on different programming languages and get almost all of the work done with Python. 

Interesting Frameworks and Libraries of Python

Working with machine learning is not an easy task, and if you start from scratch without the proper working environment, it may be difficult for you to understand and then train the neural networks in a better way. The Python frameworks and environment greatly assist programmers in this regard, and the majority of the work is ready for use by learners. In this way, they can have the easiest way to understand the concepts and then apply them with the help of Python frameworks in a better way.

To understand the importance of libraries in deep learning, it is better to understand the true meaning of libraries in programming languages:

"The software library in the programming language is defined as the set of pre-defined codes presented already for the users that perform the common tasks in just a few simple steps, and programmers do not have to write the same code again and again to perform these common tasks."

Python has fantastic libraries that are not only useful in deep learning but are proving efficient in different fields. When you move forward in this course, you will see this in action. There are several libraries in Python, but those that are closely related to machine learning are the source of attraction for us. Some of these libraries are listed below:

For machine learning and related fields such as deep learning, we can use Keras, TensorFlow, and Scikit-Learn. We have had a great discussion about these libraries in the past, and I believe you understand why they are important to us. Yet, if you are interested, you must know that scikit-learn has many algorithms related to clustering that include random forest, k-means, gradient boosting, and many others that are working best in this field. 

Numpy is used in scientific research and data analysis.

SciPy is also used for advanced computing, and as you might expect, the "Py" denotes that it is a Python library. Moreover, Panda is used for the data analysis. 

Platform Independence for Deep Learning

When talking about programming languages, the independence of the platform is important because the ease of the platform does not work if you feel uncomfortable learning these languages. Python provides us with independence because of its multipurpose libraries and ease of working. No matter if you are a Windows user or have macOS, you can use this language for your learning and its applications. For all types of operating systems, you can create standalone codes with the help of Python. In other words, no interpreter is required, and your code can be used on multiple operating systems.

Other features are also discussed in the previous lectures, such as the great community and the help of professional developers in those communities that are best for a learner to grow in a professional way. Usually, the problem that the programmer faces is unbearable because a simple code is enough to stop your work. In such cases, it feels like a blessing to have a large community that has faced, experienced, solved, and tackled the same technical issue and has the experience to solve your problem in an efficient way.

 Here, let us again review the process of working in the deep learning applications and then make up our minds as to how all the features of the Python programming language are helping us at every step of the deep learning applications.

TensorFlow and Deep Learning

Till now, we have seen the features of TensorFlow and read a lot about the perfect match of this library with deep learning, but now I am going to start working on it, so it is important to know why and how this library was introduced to the market and what the features are that make it perfect for this course.

In 2015, Google launched TensorFlow under an Apache license, and at that time, it was a unique and interesting library that attracted people towards it without any delay. This was the reason why, in 2019, Google represented its updated version with the name "TensorFlow 2.0." If you are wondering why people use it with this interest, then you must know that it provides flexibility, and therefore, several applications are available for the users of TensorFlow in the market.

TensorFlow is one of the most popular libraries in the fields of research and commercial use. The ability to run with the help of more than one CPU and GPU provides us with tremendous speed and fantastic applications that are not possible in all libraries. In other words, we can say the architecture of TensorFlow makes it popular. 

Tensor Processing Unit

This may be a new term for you, and we have not put much light on this topic before; it will not be used in our course, but today I found it important to discuss it with you because we should know each and every important point about our focused library. In 2016, Google announced the application-specific integration circuit, or ASIC, that was specifically designed for machine learning and was customized with TensorFlow.

The proper introduction to this ASIC can be given as follows:

"The Tensor Processing Unit is a programmable artificial intelligence accelerator designed to provide high throughput for low-level precision, such as 8 bits, and to use the running mode rather than training the system."

The updated versions of the Tensor Processing Unit have more performance, and the detail can be seen in the given table:

Name of Version

Year of Announcement

Performance in teraflops

1st generation TPU

2016

N/A

2nd generation TPU

2017

11.5

3rd  generation TPU

2018

420

The fourth generation was also introduced, with performance that was twice as good as the previous versions. When announcing the TPU for the first time, Google revealed that it has been using it for more than one year and is getting perfect results and better performance from its system. 

TensorFlow Projects on Github

If you are a professional programmer, then you must know the importance of GitHub in different fields of computer science. Usually, it is simple to describe the significance of a code or piece of software based on its popularity among GitHub programmers because it allows developers and programmers to practice their codes with the help of this fantastic community. When it comes to TensorFlow, you will be surprised to learn that there are over 1500+ projects available for you to practice and learn TensorFlow, as well as learn about the practical applications of Python with TensorFlow. One of the best things about this library is the constant updating that makes it the real cherry on top. Thus, if you are a user of TensorFlow, you will get more and more interesting features all the time, and your skills will never get old. Not only that, but the older versions have the best working features, so if you are not ready to try the updated features, you can easily use the older ones and add creative ideas in the perfect way, so the choice is entirely in your hands.

Hence, it was an interesting and fantastic lecture in which we learned a lot about the Python programming language and TensorFlow. We had previously read about both of these, but this time we were going to start the practical implementation, so we learned it thoroughly while keeping previous knowledge in mind. We started with a basic introduction to Python and read a lot about it with the goal of deep learning. Moreover, after that, we have seen the reasons why we are choosing TensorFlow for the practical implementation because we have other options as well, but TensorFlow is our best choice. Today, the interesting thing was the information about the Tensor Processing Unit which is an ASIC designed with TensorFlow maybe, you will see its practical working in the future in this tutorial but right now, we have the focus on the TensorFlow basics and you will learn it in the coming tutorials. Till ten, you have to practice more and more about the concepts that we are describing in our sessions.

Basics of TensorFlow for Deep Learning

Hi pals! Welcome to the next deep learning tutorial, where we are at the exciting stage of TensorFlow. In the last tutorial, we just installed the TensorFlow library with the help of Anaconda, and we saw all the procedures step by step. We saw all the prerequisites and understood how you can follow the best procedure to download and install TensorFlow successfully without any trouble. If you have done all the steps, then you might be interested in knowing the basics of TensorFlow. No matter if you are a beginner or have knowledge about TensorFlow, this lecture will be equally beneficial for all of you because there is some important and interesting information that not all people know. So, have a look at the topics that will be discussed with you in just a bit.

  • What is a tensor?

  • What are some important types of tensors that we use all the time while using TensorFlow?

  • How can we start programming in TensorFlow?

  • What are the different operations on the TensorFlow?

  • How can you print the multi-dimensional array int he TensorFlow?

Moreover, you will see some important notes related to the practice that we are going to perform so, you can say, no point will be missing and we will recall our previous concepts all the time when we need them so that the beginners may also get the clear concepts that what is going on in the course.

What is a Tensor?

There are different meanings of tensors in different fields of study, but we are ignoring others and focusing on the field with which we are most concerned: the mathematical definition of the tensor. This term is used most of the time when dealing with the data structure. We believe you have a background in programming languages and know the basics, such as what a data structure is, so I will just discuss the basic definition of tensors.

"The term "tensor" is the generalization of the metrics of nth dimensions and is the mathematical representation of a scaler, vector, dyad, triad, and other dimensions."

Keep in mind, in tensor, all values are identical in the data type with a known shape. Moreover, this shape can also be unknown. There are different ways to introduce the new tensor in TensorFlow while you are programming in it. If it is not clear at the moment, leave that because you will see the practical implementation in the next section. By the same token, you will see more of the additional concepts in just a bit, but before this, let me remind you of something:


Types of Data Structure

No. of Rank

Description

No. of Components

Vector

1

There is only the magnitude but no direction. 

1

Scaler

2

It has both magnitude and direction both.

3

Dyad

3

It has both magnitude and direction both. If x, y, and z are the components of the directions,  then the overall direction is expressed by applying the sum operation of all these components. 

9

Triad

4

It has the magnitude and also have the direction that is obtained by multiplying the 3 x 3 x 3.

27


Types of TensorFlow

Before going deep into the practical work, I want to clarify some important points in the learning of TensorFlow. Moreover, in this tutorial, we will try to divide the lecture into the practical implementation and the theoretical part of the tutorial. We will see some terms often in this tutorial, and I have not discussed them before. So, have a look at the following descriptions.

The Shape of Tensor

The length of the tensor is called its shape, and we can understand the term "shape" in a way that it is defined with the help of the total number of rows and columns. While declaring the tensor, we have to provide its shape.

The Rank of Tensors

The rank defines the dimensions of the tensor. So, in other words, rank defines the order of the dimensions that starts at 1 and ends on the nth dimension.

Type of Tensor

When talking about the tensor, the “type” means the data type of that particular tensor. Just as we consider the data type in other programming languages, when talking about the language of TensorFlow, the type provides the same information about the tensor.

Moreover, in order to learn more about the type of the tensors, we examine them with respect to different operations. In this way, we found the following types of tensors:

  1. tf.Variable

  2. tf.constant

  3. tf.placeholder

  4. tf.SparseTensor

Basics of TensorFlow Programming Language

Before we get into the practical application of the information we discussed above, we'll go over the fundamentals of programming with TensorFlow. These are not the only concepts, but how you apply them in TensorFlow may be unfamiliar to you. So, have a look at the information given below:

Comment in the TensorFlow

When you want your compiler to ignore some lines that you have written as notes, you use the “sign of hash” before those lines. In other words, the compiler ignores every line that you start with this sign. In other programming languages, we use different types of signs for the same purpose, such as, // is used in C++ to start the comment line when we are using compilers such as Visual Studio and Dev C++.

Printing the Message in TensorFlow

When we want to print the results or the input to show on the screen, we use the following command:

print(message)

Where the message may be the input, output, or any other value that we want to print. Yet, we have to follow the proper pattern for this. 

Applying Operations in TensorFlow

To apply the operations that we have discussed above, we have to first launch TensorFlow. We covered this in our previous session. Yet, every time, you have to follow some specific steps. Have a look at the details of these steps:

  • Fire up your Anaconda navigator from the search bar. 

  • Go to the Home tab, where you can find the “Jupyter notebook."

  • Click on the launch button. 

  • Select “Python” from the drop-down menu on the right side of the screen. 

  • A new localhost will appear on your Google browser, where you have to write the following command:

import tensorflow as tf

from tensorflow import keras


Make sure you are using the same pattern and take care of the case of the alphabets in each word.

Here, you can see, we have provided that information about the type of tensor we want, and as an output, it has provided us with the information about the output. There is no need to provide you with the meaning of the int16 here as we all know that there are different types of integers and we have used the one that occupies the int16 space in the memory. You can change the data type for the practice. It is obvious that you are just feeding the input value, and the compiler is showing the output of the same kind as you were expecting. Here, the shape was empty because we have not input its value. So, we have understood that there is no need to provide the shape all the time. But, in the next programs, we will surely use the shape to tell you the importance of this type. 

Printing Multi-Dimensional Arrays in TensorFlow

Before the practical implementation, you have seen the information about the dimensions of the Tensors. Now, we are moving forward with these types, and here is the practical way to produce these tensors in TensorFlow.

Printing the Two Dimensions Tensor

Here, you can print the two-dimensional array with the help of some additional commands. I'll go over everything in detail one by one. In the case discussed before, we have provided information about the tensor without any shape value. Now, have a look at the case given next;

Copy the following code and insert it into your TensorFlow compiler:


a=tf.constant([[3,5,7],[3,9,1]])

print(a)


Here comes the interesting point. In this case, we are just declaring the array with two dimensions, and TensorFlow will provide you with the shape (information of the dimension) and the memory this tensor name “a" is occupying by itself. As a result, you now know that this array has two rows and three columns.

By the same token, you can use any number of dimensions, and the information will be provided to you without any issues. Let us add the other dimensions.

Let’s have another example to initialize the matrix in TensorFlow, and you will see the shortcut form of the declaration of a unit matrix of your own choice. We know that a unit matrix has all the elements equal to one. So, you can have it by writing the following code:

a=tf.ones((3,3)

print(a)

The result should look like this:

Other examples of matrices that can be generated in such a way are the identity matrix and zero matrices. The identity matrix and the zero matrices are two other matrices that can be generated in this manner. For a zero and identity matrix, we will use “zero” and “eye” respectively in place of “ones” in the code given above. 

The next step is to practice creating a matrix containing random numbers between the ranges that are specified by us. For this, we are using the random operation, and the code for this is given in the next line:

a=tf.random.uniform((1,5),minval=1, maxval=3)

print(a)

When we observe these lines, we will understand that first of all, we are using the random number where the numbers of

 Rows and columns are given by us. I have given the single-row and five-column matrix in which I am providing the compiler with the maximum and minimum values. Now, the compiler will generate random values between these numbers and display the matrix in the order you specify.

So, from the programs above, we have learned some important points:

  • Just like in the formation of matrices in MATLAB, you have to put the values of rows in square brackets. 

  • Each element is separated from the others with the help of a comma.

  • Each row is separated by applying the comma between the rows and enclosing the rows in the brackets.

  • All the rows are enclosed in the additional square bracket.

  • You have to use the commas properly, or even if you have a single additional space, you can get an error from the compiler while running it.

  • It is convenient to give the name of the matrix you are declaring so that you can feed the name into the print operation.

  • If you do not name the matrix, you can also use the whole matrix in the print operation, but it is confusing and can cause errors.

  • For the special kinds of matrices that we have learned in our early concepts of matrices, we do not have to use the square brackets, but instead, we will use the parentheses along with the number of elements so that compiler may have the information about the numbers of rows and columns, and by reading the name of the specific type of the matrix, it will automatically generate the special matrices such as the unit matrix, the null matrix, etc.

  • The special kind of matrices can also be performed in the TensorFlow but you have to follow the syntax and have to get the clear concept for the performance.

So, in this tutorial, we have started using the TensorFlow that we had installed in the previous lecture. Some of the steps to launch TensorFlow are the same and you will practice them every day in this course. We have seen how can we apply the basic functions in the TensorFlow related to the matrices. We have seen the types of tensors that are, more or less, similar to the matrices. You will see the advanced information about the same concepts in the tutorials given next as we are moving from the basics to the advance so stay with us for more tutorials.

Installation of TensorFlow for Deep Learning

Hello Peeps! Welcome to the next lecture on deep learning, where we are discussing TensorFlow in detail. You have seen why we have chosen TensorFlow for this course, and we have read a lot about the working mechanism, programming languages, and advantages of using TensorFlow instead of other libraries. Instead of using the other options for the same purpose, we have seen several reasons to use TensorFlow. Because of the latest work on the library for more improvement and better results, it's now time to learn the specifics of TensorFlow installation. But before this, you have to check the list of the concepts that will be cleared today:

Is Installation of TensorFlow Difficult?

The simple and to-the-point answer to this question is, the installation is easy and usually does not require any practice. If you are new to the technical world or have not experienced the installation of any software, do not worry because we will not skip any steps. Moreover, we have chosen the perfect way to install TensorFlow by telling you the all necessary information about the installation process so you start only if all the parameters are completed. So, first of all, let us share the prerequisites with you. 

  • What are the minimum requirements for Tensorflow to be installed on your PC?

  • How can we choose the best method for the installation of TensorFlow?

  • How can we install TensorFlow with Jupyter?

  • What is the process for the Keras to be installed?

  • How can you launch the TensorFlow and Keras with the help of Jupyter Notebook?

  • What is the significance to use Jupyter, Keras, and TensorFlow?

Pre-requisites for TensorFlow

To install TensorFlow without difficulty, you must keep all types of requirements in mind. We have categorised each type of requirement and you just have to check whether you are ready to download it or not.


System Requirements

Ubuntu

16.04 or higher 

64 bits

macOS

10.12.6 (Sierra) or higher, GPU is not supported.

N/A

Window Native

Window 7 (higher is recommended)

64 bits

Window WSL 

Window 10

64 bits


 By the same token, there are some hardware requirements and below these values, the hardware does not support the TensorFlow.


Hardware Requirement

GPU

NVIDIA® GPU card with CUDA® architectures 3.5, 5.0, 6.0, 7.0, 7.5, 8.0

Here, it is important to notice that the requirements given in all the tables are the minimum requirement s and you can go for the higher versions of all of these for the better results and quality work.


Software Requirement

Python version

3.7-3.10

Pip version

19.0 (for window and Linux),  20.3 (for macOS) 

NVIDIA® for GPU support


NVIDIA® GPU driver

version 450.80.02

CUDA® Toolkit 

11.2

cuDNN SDK

8.1.0


Moreover, to enhance the latency and performance, TesnorFlowRT is recommended. All the requirements given above are authentic and you must never skip any of these if you want to get 100 efficiencies. Moreover, for the course we are working on, there is no need for any GPU as we are moving towards the basic course and we can install GPU in future if required.

Choosing the Best Installation Method for Anaconda

Now it's time to make a decision about the type of installation you want. This is the step that makes TensorFlow different from the other simple installations. If you're going to install it on your PC, you have to get help from another software. There is certain software through which you can install the library software with the help of Anaconda software. For this, we are going to the official website and installing the anaconda software.

  • As soon as you will click on the download option, the loading will start and the software of Anaconda with the size 600+MBs will start downloading. It will take a few moments to be downloaded. 

  • Once the process discussed above is completed, you have to click on the installation button and the window will be pop-up on your screen where the installation steps have to be completed by you.  

The installation process is so simple that many of you have known them before but the purpose to tell you about each and every step is, some people do not know much about the installation or have the habit to match the steps with the tutorials so they may know that they are at the right path.

  • In the next step, you have to provide the path for the installation place of the anaconda. By default, as you expect, the C drive is set but I am going to change the directory. You can choose the path according to your choice. 

  • Now, you will see that it is asking for the settings according to your choice. By default, the second option is ticked and I am installing the Anaconda as it is and click on the installation process. 

  • Now, the installation process is starting and it will take some time.

    • While this step is taking a little time, you can read about the documentation of the TensorFlow. 

    • Once the installation is complete, the next button will direct you towards this window:

    In this way, Anaconda will be installed on your PC. You must know that it has multiple libraries, functions, and software within it and there is no need to check them all. For our practice, we just have to know about the Jupyter notebook. It will be cleared in just a bit How can we start and work with this notebook? 

    Installing the TensorFlow Framework

    It seems that you have successfully installed Anaconda and are now moving towards the installation of your required library. It is a simple and interesting process that requires no technical skills. You just have to follow the simple steps given next:

    • Go to the start menu of your window. 

    • Search for the “Anaconda command prompt."

    • Click on it, and a command prompt window will appear on your screen. 

    • You just have to write the following command and the Anaconda will automatically install this amazing library for you. 

    • As you can see, it mentions that the download of TensorFlow requires 266.3 MBs. Once this command is entered, the installation of the TensorFlow will carry out and you have to wait for some moments.

    To confirm the installation process, I am providing you with some important commands. You just have to type “python” in the command prompt, and Anaconda will confirm the presence of the python information on your PC. 

    • In the next step, to ensure that you have installed Tensorflow successfully, you can write the following command:


    Import TensorFlow as tf

    • If nothing happens in the command prompt, it means your library was successfully installed; otherwise, it throws an error.

    Hence, the TensorFlow library is successfully installed on our PCs. The same purpose is also completed with the help of Jupyter Navigator, and you will see it in detail.

    Installing the TensorFlow Environment with Jupyter Navigator

    Finally, for the perfect installation, we will search, follow the path Home>Search>Anaconda Navigator, and press enter. The following screen will appear here.

    You have to choose the “Environment” button and click on the “Create” button to create a new environment. A small window will appear, and you have to name your environment. I am going to name it "TensorFlow.”

    There is a possibility that it recommends the updated version if it is available. We recommend you have the latest version, but it is not necessary. As soon as you click on the "Create" button, in the lower right corner, you will see that your project is being loaded. 

    This step takes some time; in the meantime, you can check the other packages in the Anaconda software. 

    Installing the Keras with Jupyter

    There is a need for Keras API as you have seen in our previous lectures. But as a reminder, we must tell you that Keras is a high-level application programming interface that is specially designed for deep learning and machine learning by Google, and with the help of this PAI, TensorFlow provides you with perfect performance and efficient work. So, here are the steps to install Keras on your PC.

    • Open the Jupyter navigator.

    • Click on the "create" button. 

    • Write the name of your new environment, I am giving it the name "Keras,” as you were expecting. 

    • The next step is to load the environment, as you have seen in the case of TensorFlow as well. 

    These steps are identical to the creation of an environment for TensorFlow. It is not necessary to discuss why we are doing this and what the alternatives are. For now, you have to understand the straightforward procedure and follow it for practice. 

     Keep in mind that, till now, you have just installed the library and API, but for the working of both of these, you have to run them, and we will earn this in just a bit. 

    Checking for the Installation of TensorFlow

    The installation process does not end here. After the installation process, you have to check if everything is working properly or not. For this, go to the home page and then search for “Jupyter notebook." You must notice that there is a launch button at the bottom of this notebook’s section. If you found something else here, such as "Install,” then you have to first install the notebook by simply clicking on it, and then launch the notebook.

    As soon as you launch the Jupyter notebook, you will be directed to your browser, where the notebook is launched on the local host of your computer. Here, it's time to write the commands to check the presence and working of the TensorFlow. You have to go to the upper right side of the screen and choose the Python3 (ipykernel) mode. 

    Now, as you can see, you are directed towards the screen where a code may be run. So you have to write the following command here:

    Import tensorflow as tf

    From tensorflow import keras

    This may look the same as the previous way to install tensorflow, but it is a little bit different because now, at Jupyter, you can easily run your code and work more and more on it. It is more user-friendly and has the perfect working environment for the students and learners because of the efficient results all the time.

    Keras is imported along with TensorFlow, and it is so easy to deal with deep learning with the help of this library and API. 

    If you do not remember these steps, do not worry because you will practice them again and again in this course, and after that, you will become an expert in TensorFlow. Another thing to mention is that you can easily launch Keras and TensorFlow together; you do not have to do them one after the other. But sometimes, it shows an error because of the difference in the Python version or other related issues. So it is a good practice to install them one after the other because, for both, the procedure is identical and is not long. 

    So, it was an informative and interesting lecture today. We have utilized the information from the previous lectures and tried to install and understand TensorFlow in detail. Not only this, but we also discussed the installation process of Keras, which has a helpful API, and understood the importance of using them together. Once you have started TensorFlow, you are now ready to use and work with it within Jupyter. Obviously, there are also other ways to do the same work as we have done here, but all of them are a little bit complex, and I found these procedures to be the best. If you have better options, let us know in the comment section or contact us directly through the website. 

    In the next session, we will work on TensorFlow and learn the basics of this amazing library. We will start from the basics and understand the workings and other procedures of this library. Till then, stay with us.

    Getting Started with TensorFlow for Deep Learning

    Hey learners! Welcome to the new tutorial on deep learning, where we are going deep into the learning of the best platform for deep learning, which is TensorFlow. Let me give you a reminder that we have studied the need for libraries of deep learning. There are several that work well when we want to work with amazing deep-learning procedures. In today’s lecture, you are going to know the exact reasons why we chose TensorFlow for our tutorial. Yet, first of all, it is better to present the list of topics that you will learn today:

    • Why do we use TensorFlow with deep learning?

    • What are some helpful features of this library?

    • How can you understand the mechanism of TensorFlow?

    • Show the light towards the architecture, and components of the TensorFlow.

    • In how many phases you can complete the work in the TensorFlow and what are the details of each step?

    • How the data is represented in the TensorFlow?

    Why TensorFlow for Deep Learning

    In this era of technology, where artificial intelligence has taken charge of many industries, there is a high demand for platforms that, with the help of their fantastic features, can make deep learning easier and more effective. We have seen many libraries for deep learning and tested them personally. As a result of our research, we found TensorFlow the best among them according to the requirements of this course. 

    There are many reasons behind this choice that we have already discussed in our previous sessions but here, for a reminder, here is a small summary of the features of TensorFlow

    • Flexibility

    • Easy to train

    • Ability to train the parallel neural network training

    • Modular nature

    • Best match with the Python programming language

    As we have chosen Python for the training process, therefore, we are comfortable with the TensorFlow. It also works with traditional machine learning and has the specialty of solving complex numerical computations easily without the requirement of minor details. TensorFlow proved itself one of the best ways to learn deep learning, therefore, google open-sourced it for all types of users, especially for students and learners. 

    Helpful Features of TensorFlow

    The features that we have discussed before we very generalized and you must know more about the specific features that are important to know before getting started with TensorFlow.

    APIs of TensorFlow

    Before you start to take an interest in any software or library, you must have knowledge about the specific programming languages in which you operate that library. Not all programmers are experts in all coding languages; therefore, they go with the specific libraries of their matching APIs. TensorFlow can be operated in two programming languages via APIs:

    1. C++ 

    2. Python

    3. Java (Integration)

    4. R (Integration)

    The reason we love TensorFlow is that the coding mechanism for deep learning is much more complicated. It is a difficult job to learn and then work with these coding mechanisms.

    TensorFlow provides the APIs in comparatively simple and easy-to-understand programming languages. So, with the help of C++ or Python, you can do the following jobs in TensorFlow:

    • To configure the neuron

    • Work with the neuron

    • Prepare the neural network

    TensorFlow Supports Different Computing Devices

    As we have said multiple times, deep learning is a complex field with applications in several forms. The training process of the neural network with deep learning is not a piece of the cake. The training process of neural networks requires a lot of patience. The computations, multiplication of the matrices, complex calculations of mathematical functions, and much more require a lot of time to be consumed, even after experience and perfect preparations. At this point, you must know clearly about two types of processing units:

    1. Central processing unit

    2. Graphical processing unit

    The central processing units are the normal computer units that we use in our daily lives. We've all heard of them. There are several types of CPUs, but we'll start with the most basic to highlight the differences between the other types of processing units. The GPUs, on the other hand, are better than the CPUs. Here is a comparison between these two:


    CPU

    GPU

    Consume less memory

    Consume more memory

    They work at a slow speed

    They work at a higher speed 

    The cores are more powerful.powerful

    They have contained relatively less powerful cores

    It has a specialty in serial instruction processing

    They are specialized to work in a parallel processing

    Lower latency

    Higher latency


    The good thing about TensorFlow is, it can work with both of them, and the main purpose behind mentioning the difference between CPU and GPU was to tell you about the perfect match for the type of neural network you are using. TensorFlow can work with both of these to make deep learning algorithms. The feature of working with the GPU makes it better for compilation than other libraries such as Torch and Keras. 

    Working Mechanism of TensorFlow

    It is interesting to note that Python has made the workings of TensorFlow easier and more efficient. This easy-to-learn programming language has made high-level abstraction easier. It makes the working relationship between the nodes and tensors more efficient. 

    The versatility of TensorFlow makes the work easy and effective. TensorFlow modules can be used in a variety of applications, including

    • Android apps

    • iOS

    • Cluster

    • Local machines

    Hence, you can run the modules on different types of devices, and there is no need to design or develop the same application for different devices.

    The history of deep learning is not unknown to us. We have seen the relationship between artificial intelligence and machine learning. Usually, the libraries are limited to specific fields, and for all of them, you have to install and learn different types of software. But TensorFlow makes your work easy, and in this way, you can run conventional neural networks and the fields of AI, ML, and deep learning on the same library if you want. 

    The Architecture of TensorFlow

    The architecture of the TensorFlow depends upon the working of the library. You can divide the whole architecture into the three main parts given next:

    • Data Processing

    • Model Building

    • Training of the data

    The data processing involves structuring the data in a uniform manner to perform different operations on it. In this way, it becomes easy to group the data under one limiting value. The data is then fed into different levels of models to make the work clear and clean.

    In the third part, you will see that the models created are now ready to be trained, and this training process is done in different phases depending on the complexity of the project. 

    Phases of the TensorFlow Projects 

    While you are running your project on TensorFlow, you will be required to pass it through different phases. The details of each phase will be discussed in the coming lectures, but for now, you must have an overview of each phase to understand the information shared with you.

    Development Phase: 

    The development phase is done on the PC or other types of a computer when the models are trained in different ways. The neural networks vary in the number of layers, and in return, the development phase also depends upon the complexity of the model.

    Run Phase

    The run phase is also sometimes referred to as the inference phase. In this phase, you will test the training results or the models by running them on different machines. There are multiple options for a user to run the model for this purpose. One of them is the desktop, which may contain any operating system, whether it is Windows, macOS, or Linux. No matter which of the options you choose, it does not affect the running procedure.

    Moreover, the ability of TensorFlow to be run on the CPU and GPU helps you test your model according to your resources. People usually prefer GPU because it produces better results in less time; however, if you don't have a GPU, you can do the same task with a CPU, which is obviously slower; however, people who are just getting started with deep learning training prefer CPU because it avoids complexities and is less expensive. 

    Components in TensorFlow

    Finally, we are at the part where we can learn a lot about the TensorFlow components. In this part, you are going to learn some very basic but important definitions of the components that work magically in the TensorFlow library. 

    Tensor

    Have you ever considered the significance of this library's name? If not, then think again, because the process of performance is hidden in the name of this library. The tensor is defined as:

    "A tensor in TensorFlow is the vector or the n-dimensional data matrix that is used to transfer data from one place to another during TensorFlow procedures."

    The tensor may be formed as a result of the computation during these procedures. You must also know that these tensors contain identical datatypes, and the number of dimensions in these matrices is known as the shape.

    Graph

    During the process of training, the operations taking place in the network are called graphs. These operations are connected with each other, and individually, you can call them "ops nodes." The point to notice here is that the graphs do not show the value of the data fed into them; they just show the connections between the nodes. There are certain reasons why I found the graphs useful. Some of them are written next:

    • These can be run or tested on any type of device or operating system. You have the versatility to run them on the GPU, OS, or mobile devices according to your resources.

      • The graphs can be saved for future use if you do not want to use them at the current time or want to reuse them in the future for other projects or for the same project at any other time, just like a simple file or folder. This portable nature allows different people sharing the same project to use the same graph without having any issues. 

      Dataflow Graphs in TensorFlow

      TensorFlow works differently than other programming languages because the flow of data is in the form of nodes. In traditional programming languages, code is executed in the form of a sequence, but we have observed that in TensorFlow, the data is executed in the form of different sessions. When the graph is created, no code is executed; it is just saved in its place. The only way to execute the data is to create the session. You will see this in action in our coming lectures. 

      • Each node in the TensorFlow graph, the mathematical operation such as addition, subtraction, multiplication, etc, is represented as the node. By the same token, the multidimensional arrays (or tensors) are shown by the nodes. 

      • In the memory of TensorFlow, the graph of programming languages is known as a "computational graph." 

      • With the help of CPUs and GPUs, large-scale neural networks are easy to create and use in TensorFlow.

      By default, a graph is made when you start the Tensorflow object. When you move forward, you can create your own graphs that work according to your requirements. These external data sets are fed into the graph in the form of placeholders, variables, and constants. Once these graphs are made and you want to run your project, the CPUs and GPUs of TensorFlow make it easy to run and execute efficiently. 

      Hence, the discussion of TensorFlow is ended here. We have read a lot about TensorFlow today and we hope it is enough for you to understand the importance of TensorFlow and to know why we have chosen TensorFlow among the several options. In the beginning, we have read what is TensorFlow and what are some helpful features of TensorFlow. In addition to this, we have seen some important APIs and programming languages of this library. Moreover, the working mechanism and the architecture of TensorFlow were discussed here in addition to the phases and components. We hope you found this article useful, stay with us for more tutorials.

      Deep Learning with Python - Getting Started Guide

      Hey buddies! Welcome to the next tutorial on deep learning, in which you are about to acquire knowledge related to Python. This is going to be very interesting because the connection between these two is easy and useful. In the last lecture, we had an eye on the latest and trendiest deep learning algorithms, and therefore, I think you are ready to take the next step towards the implementation of the information that I shared with you. To help you make up your mind about the topics of today, I have made a list for you that will surely be useful for you to understand what we are going to do today. 

      • How do you introduce the Python programming language to a deep learning developer?

      • How is Python useful for deep learning training in different ways?

      • Do Python provide the useful frameworks for the depe learning?

      • What are some libraries of Python that are useful for the deep learning?

      • Why do programmers prefer Python over other options when working with deep learning?

      • What are some other options besides Python to be used with deep learning?

      Introduction to the Python Coding Language

      Over the years, the hot topic in the world of programming languages has been Python because of many reasons that you will learn soon. It is critical to understand that when selecting a coding language, you must always be confident in its efficiency and functionality. Python is the most popular because of its fantastic performance, and therefore, I have chosen it for this course. From 2017 to the present, calculations and estimations of popularity show that Python is in the top ten in the interests of both common users and professionals due to its ease of installation and unrivaled efficiency.

      Now, recall that deep learning is a popular topic in the industry of science and technology, and people are working hard to achieve their goals with the help of deep learning because of its jaw-dropping results. When talking about complexity, you will find that deep learning is a difficult yet useful field, and therefore, to minimize the complexity, experts recommend python as the programming language. All the points discussed below are an extraction of my personal experience, and I chose the best points that every developer must know. The following is a list of the points that will be discussed next:

      Readable Code

      I am discussing this point at the start of the discussion because I think it is one of the most important points that make programming better and more effective. If the code is clean and easy to read, you will definitely be able to pay attention to the programming in a better way. Usually, the programming is done in the grouping phase, and for the testing and other phases of successful programming, it is important to understand the code written by the others. Hence, coding in Python is easy to read and understand, and by the same token, you will be able to share and practice more and more with this interesting coding language.

      The syntax and rules of the Python programming language allow you to present your code without mentioning many details. People realize that it is very close to the human language, and therefore, there is no need to have a lot of practice or knowledge to start practising. These are the important points that prove the importance of the Python language for writing more useful code. As a result, you can conclude that for complex and time taking processes such as deep learning, Python is one of the ideal languages because you do not have to spend a lot of time coding but will be able to use this energy to understand the concepts of deep learning and its applications. 

      Multiple Programming Paradigms

      Python, like other modern programming languages, supports a variety of programming paradigms. It fully supports:

      • Object-oriented Programming

      • Structured programming

      Furthermore, its language features support a wide range of concepts in functional and aspect-oriented programming. Another point that is important to notice is that Python also includes a dynamic type system and automatic memory management.

      Python's programming paradigms and language features enable you to create large and complex software applications. Therefore, it is a great language to use with deep learning. 

      Flexibility with Other Platforms

      If you are a programmer, you will have the idea that for different programming languages, you have to download and install other platforms for proper working. It becomes hectic to learn, buy, and use other platforms for the working of a single language. But when talking about Python, the flexibility can be proven by looking at the following points:

      • It supports multiple operating systems.

      • It is an interpreted programming language. That means you can run the Python code on several platforms without the headache of recompilation for the other platforms. 

      • The testing of the Python code is easier than in some other programming languages.

      All these points are enough to understand the best combination of deep learning with the Python programming language because deep learning requires the training and testing process, and there may be a need to test the same code or the network on different platforms. 

      Robust Libraries of Python

      Want to know why Python is better than other programming languages? One of the major reasons is the fantastic and gigantic library of the Python language. It is a programming tip that programmers should always check the programming language's library if they want to know its efficiency and ability to work instantly. One thing to notice is that you will get a large number of modules, and it allows you to choose the modules of your choice. So, you can ignore the unnecessary modules. This feature is also present in other popular programming languages. Moreover, you can also add more code according to your needs. For the experts, it is a blessing because they can use their creativity by using the already-saved modules.

      Deep Elarnigna only contains algorithms, and it requires a programming language that allows for simple and quick module creation. Python is therefore ideal for deep embedding in context. 

      Opensource Frameworks

      In the past lectures, we have seen the frameworks of deep learning, and therefore, for the best compatibility, the programming language in which the deep learning is being processed must also have open-source frameworks; otherwise, this advantage of deep learning will not be useful. Most of the time, the tools and frameworks are not only open source but also easily accessible, which makes your work easier. I believe that having more coding options makes your work easier because coding is a time-consuming process that requires you to have as much ease as possible for better practice. Here is the list of some frameworks that are used with the Python programming language:

      • Django

      • Flask

      • Pyramid

      • Bottle

      • Cherrypy.

      Another reason why experts recommend Python for deep learning is the Python frameworks related to graphical user interfaces. In the previous lectures, you have seen that deep learning has a major application in image and video processing, and therefore, it is a good match for deep learning with Python coding. The GUI frameworks of Python include:

      • PyQT

      • PyJs

      • PyGUI

      • Kivy

      • PyGTK

      • WxPython

      Observe that the keyword "Py" with all these frameworks indicates the specification of the Python programming language with these frameworks. At this point, it is not important to understand all of them. But as an example, I want to tell you that Kivy is used for the front end of Android apps with the help of Python. 

      This category makes it important to notice the connection between the Python programming language and deep learning because, when working with deep learning, a greater variety of frameworks results in an easier working and better training process. 

      Test Driven Approach

      If you are following our previous tutorials, you will be aware of the importance of testing in deep learning. But allow me to tell you the connection between Python and the test-driven approach. In deep learning, all efficiency depends upon the testing process. More and more training and testing means better performance, which the network can recognize better. Python provides for the rapid creation of prototype applications, and similarly, it also provides the best test driven approach when connected to networks.

      Consistency

      The first rule to learning programming languages is to have consistency in your nature. Yet, for the more difficult programming languages, where the absence of a single semicolon can be confusing for the compiler, consistency is difficult to attain. On the contrary, an easier and more readable programming language, such as Python, helps to pay more attention to the code, and thus the user is more drawn to its work. Deep learning can only be performed in such an environment. So, for peace of mind, always choose Python. 

      Massive Community Support

      Have you ever been stuck in a problem while coding and could not find the help you needed? I've seen this many times, and it's a miserable situation because the code contains your hard work from hours or even days, but you still have to leave it. Yet, because of the popularity and saturation of this field, Python developers are not alone. Python is a comparatively easy language, and normally people do not face any major issues. Yet, for the help of the developers, there is a large community related to Python where you can find the solution of your problems, check the trends, have a chit chat with other developers, etc.

      When working on deep learning projects, it's fun to be a part of a community with other people who are working on similar projects. It is the perfect way to learn from the seniors and grow in a  productive environment. Moreover, while you are solving the problems of the juniors, you will cultivate creativity in your mind, and deep learning will become interesting for you. 

      Other Programming Options for The Deep Learning

      At this point, where I am discussing a lot about Python, it must be clarified that it is not the only option for deep learning. Deep learning subjects are always wasteful, and users always have more than one option. However, we prefer Python for a variety of reasons, and now I'd like to tell you about some other options that appear useful but are, in fact, less useful than Python. The other programming languages are:

      • JavaScript

      • Swift

      • Ruby

      • R.

      • C

      •  C++

      • Julia

      • PHP

      No doubt, people are showing amazing results when they combine one or more of these programming languages with deep learning, but usually, I prefer to work more with Python. It totally depends on the type of project you have or other parameters such as the algorithm, frameworks, hardware the user has, etc. to effectively choose the best programming language for deep learning. An expert always has an eye on all the parameters and then chooses the perfect way to solve the deep learning problems, no matter what the difficulty level of the language is.

      Hence, we have discussed a lot about the Python today. Before all this discussion, our focus was on the deep learning and its working so you amy have the idea what actually si going on. In this article, we have seen the compatibility of the Python programming language with deep learning. We knew about the parameters of the deep learning and therefore were able to understand the reason of choosing the Python for our work. Throughout this article, we have seen different reasons why we have chosen TensorFlow and related libraries for our work. It is important to notice that Python works best with the TensorFlow and Keras APIs, and therefore, from day one, we have focused on both of these. In the next lecture, you will see some more important information about deep learning, and we are moving towards the practical implementation of this information. Once we have performed the experiment, all the points will be crystal clear in your mind. So until then, learn with us and grow your knowledge.

      List of Top Trending Deep Learning Algorithms

      Hello pupils! Welcome to the following lecture on deep learning. As we move forward, we are learning about many of the latest and trendiest tools and techniques, and this course is becoming more interesting. In the previous lecture, you saw some important frameworks in deep learning, and this time, I am here to introduce you to some fantastic algorithms of deep learning that are not only important to understand before going into the practical implementation of the deep learning frameworks but are also interesting to understand the applications of deep learning and related fields. So, get ready to learn the magical algorithms that are making deep learning so effective and cool. Yet before going into details, let me discuss the questions for which we are trying to find answers.

      • How does deep learning algorithms are introduced?

      • What is the working of deep learning algorithms?

      • What are some types of DL algorithms?

      • How do deep learning algorithms work?

      • How these algorithms are different from each other?

      Deep learning plays an important role in the recognition of objects and therefore, people use this feature in image, video and voice recognition where the objects are not only detected but can be changed, removed, edited, or altered using different techniques. The purpose to discuss these algorithms with you is, to have more and more knowledge and practice to choose the perfect algorithm for you and to have the concept of the efficiency and working of each algorithm. Moreover, we will discuss the application to provide you with the idea to make new projects by merging two or more algorithms together or creating your own algorithm.

      What is a Deep Learning Algorithm?

      Throughout this course, you are learning that with the help of the implementation of deep learning, computers are trained in such a way that they can take human-like decisions and can have the ability to act like humans with the help of their own intelligence. Yet, it is time to learn about how they are doing this and what the core reason is behind the success of these intelligent computers. 

      First of all, keep in mind that deep learning is done in different layers, and these layers are run with the help of the algorithm. We introduce the deep learning algorithm as:

      “Deep learning algorithms are the set of instructions that are designed dynamically to run on the several layers of neural networks (depending upon the complexity of the neural networks) and are responsible for running all the data on the pre-trained decision-making neural networks.”

      One must know that, usually, in machine learning, there is tough training to work with complex datasets that have hundreds of columns or features. This becomes difficult with the classic deep learning algorithm, so the developers are constantly designing a more powerful algorithm with the help of experimentation and research.

      How Does Deep Learning Algorithm Work?

      When people are using different types of neural networks with the help of deep learning, they have to learn several algorithms to understand the working of each layer of the algorithm. Basically, these algorithms depend upon the ANNs (artificial neural networks) that follow the principles of human brains to train the network.

      While the training of the neural network is carried out, these algorithms take the unknown data as input and use it for the following purposes:

      • To group the objects

      • To extract the required features

      • To find out the usage patterns of data

      The basic purpose of these algorithms is to build different types of models. There are several algorithms for neural networks, and it is considered that no algorithm is perfect for all types of tasks. All of them have their own pros and cons, and to have mastery over the deep learning algorithm, you have to study more and more and test several algorithms in different ways. 

      Types of Deep Learning Algorithms

      Do you remember that in the previous lectures we discussed the types of deep learning networks? Now you will observe that, while discussing the deep learning algorithms, you will utilize your concepts of neural networks. With the advancement of deep learning concepts, several algorithms are being introduced every year. So, have a look at the list of algorithms.

      1. Convolutional Neural Networks (CNNs)

      2. Long Short-Term Memory Networks (LSTMs)

      3. Deep Belief Networks (DBNs)

      4. Generative Adversarial Networks (GANs)

      5. Autoencoders

      6. Radial Basis Function Networks (RBFNs)

      7. Multilayer Perceptrons (MLPs)

      8. Restricted Boltzmann Machines( RBMs)

      9. Recurrent Neural Networks (RNNs)

      10. Self-Organizing Maps (SOMs)

      Do not worry because we are not going to discuss all of them at a time but will discuss only the important ones to give you an overview of the networks.

      Convolutional Neural Networks (CNNs)

      Convolutional neural networks are also known as "ConvNets," and the main applications of these networks are in image processing and related fields. If we look back at its history, we find that it was first introduced in 1998. Yan LeCun initially referred to it as LeNet. At that time, it was introduced to recognize ZIP codes and other such characters.

      Layers in CNN

      We know that neural networks have many layers, and similar is the case with CNN. We observe different layers in this type of network, and these are described below:


      Sr #

      Name of the Layer

      Description of the Layer

      1

      Convolution layer

      The convolution layer contains many filters and is used to perform the convolution operations.

      2

      Rectified linear unit

      The short form of this layer is ReLu, and it is used to perform different operations on the elements. It is called “rectified” because the output is obtained as a rectified feature map by using this layer. 

      3

      Pooling layer 

      This is the layer where the results of the ReLu are fed as the input. Pooling is defined as the downsampling operation, and it is used to reduce the dimension of a feature map. The next phase is to convert this feature map, and then this two-dimensional array is converted into a single flat, continuous, and single vector. 

      4

      Fully connected layer

      The single vector from the pooling layer is finally fed into this last layer. At the end, classification of the image is done to identify it.



      As a reminder, you must know that neural networks have many layers, and the output of one layer becomes the input for the next layer. In this way, we get refined and better results in every layer. 

      Long Short-Term Memory Networks (LSTMs)

      This is a type of RNN (recurrent neural network) with a good memory that is used by experts to remember long-term dependencies. By default, it has the ability to recall past information over a long period of time. Because of this ability, LSTMs are used in time series prediction. It is not a single layer but a combination of four layers that communicate with each other in a unique way. Some very typical uses of LSTM are given below:

      • Speech recognition

      • Development in pharmaceutical operations

      • Different compositions in music 

      Recurrent neural networks (RNNs)

      If you are familiar with the fundamentals of programming, you will understand that if we want to repeat a process, loops, or recurrent processes, are the solution. Similarly, the recurrent neural network is the one that forms the directed cycles. The unique thing about it is that the output of the LSTM becomes the input of the RNN. It means these are connected in a sequence, and in this way, the current phase becomes the output of the LSTM.

      The main reason why this connection is magical is that you can utilize the feature of memory storage in LSTM and the ability of RNNs to work in a cyclic way. Some uses of RNN are given next:

      • Recognition of handwriting

      • Time series analysis

      • Translation by the machine

      • Natural language processing

      • captioning the images

      Working of RNN

      The output of the RNN is obtained by following the equation given next:

      If 

      output=t-1

      Then 

      input=1

      So at the output t

      input=1+1

      And this series goes on

      Moreover, RNN can be used with any length of the input, but the size of the model does not increase when the input size is increased.

      Generative Adversarial Networks (GANs)

      Next on the list is the GAN or the generative adversarial network. These are known as “adversarial networks" because they use two networks that compete with each other to generate real-time synthesized data. It is one of the major reasons why we found applications of the generative adversarial network in video, image, and voice generation.

      GANs were first described in a paper published in 2014 by Ian Goodfellow and other researchers at the University of Montreal, including Yoshua Bengio. Yann LeCun, Facebook's AI research director, referred to GANs as "the most interesting idea in ML in the last 10 years." This made GANs a popular and interesting neural network. Another reason why I like this network is the fantastic feature of mimicking. You can create music, voice, video, or any related application that is difficult to recognize as being made by a machine. The impressive results are making this network more and more popular every day, but the evil of this network is equal. As with all technologies, people can use them for negative purposes, so check and balance are applied to such techniques. Moreover, GAN can generate realistic images and cartoons with high-quality results and render 3D objects.

      Working of GAN

      At first, the network learns to distinguish between the generated fake data and sampled data. It happens when fake data is produced and the discriminator learns to recognise if it is real or false. After that, GAN is responsible to send the results to the generator so that it can learn and memorize the results and go for further training.

      If it seems a simple and easy task, then think again because the recognition part is a tough job and you have to feed the perfect data in the perfect way so you may have accurate results every time. 

      Radial Basis Function Networks (RBFNs)

      For the problems in the function approximation, we use an artificial intelligence technique called the radial basis function network. It is somehow a little bit different from the previous ones. These are the types of forward-feed neural networks, and the speed and performance of these networks make them better than the other neural networks. These are highly efficient and have a better learning speed than others, but they require experience and hard work. Another reason to call them better is the presence of only one hidden layer and one radial basis function that is used as an activation function. Keep in mind that the activation function is highly efficient in its approximation of the results.

      Working of Radial Basis Function Network

      • It takes the data from a training set and measures the similarities in the input. In this way, it classifies the data. 

      • In the layer of RBF neurons, the input vector is then fed into the input layer. 

      • After finding the weighted sum of the inputs, we obtain the output. Each category or class of data has one node. 

      • The difference from the other network is, the neurons contain a gaussian transfer function, and the output is inversely proportional to the distance between the centre of the network and the neuron. 

      • In the end, we get the output, which is a combination of both, the input of the radial basis function and the neuron parameters. 

      So, it seems that these networks are enough for today. Although there are different types of neural networks as well, as we have said earlier, with the advancement in deep learning, more and more algorithms for the neural networks are being introduced that have their own specifications, yet at this level, we just wanted to give you an idea about the neural networks. At the start of this article, we have seen what deep learning algorithms are and how they are different from other types of algorithms. We have seen the types of neural networks that include CNNs, LSTMNs, RNNs, GANs, and RBFs.

      IoT based Web Controlled Home Automation using Raspberry Pi 4

      Greetings, and welcome to today's tutorial. In the last tutorial, we learned how to construct a system for tallying individuals using Raspberry Pi, astute subtraction, and blob tracking. We demonstrated the total number of building entrances and exits. Feature computation and HOG theory were also discussed. The tests proved that a device based on the raspberry pi could effectively function as a people counting station. One of the many benefits of the Pi 4 is its internet connectivity, which is especially useful for home automation projects due to its low price and ease of use. We're going to see if we can use a web page's buttons to manage our air conditioner today. With this Internet of Things (IoT) based home automation, you can command your home gadgets from the comfort of your couch. The user can access this web server from any gadget capable of loading HTML apps, such as a smartphone, tablet, computer, etc.

      Where To Buy?
      No.ComponentsDistributorLink To Buy
      1BreadboardAmazonBuy Now
      2DiodesAmazonBuy Now
      3Jumper WiresAmazonBuy Now
      4LEDsAmazonBuy Now
      5ResistorAmazonBuy Now
      6TransistorAmazonBuy Now
      7Raspberry Pi 4AmazonBuy Now

      Components

      The needs of this project can be broken down into two broad classes: hardware and software.

      Hardware Requirement

      • Raspberry Pi 4

      • Memory card 8 or 16GB running Raspbian Jessie

      • 5v Relays

      • 2n222 transistors

      • Diodes

      • Jumper Wires

      • Connection Blocks

      • LEDs to test.

      • AC lamp to Test

      • Breadboard and jumper cables

      • 220 or 100 ohms resistor

      Software Requirement

      We'll be using the WebIOPi framework, notepad++ on your PC, and FileZilla to transfer files (particularly web app files) from your computer to the raspberry pi and the Raspbian operating system.

      The Raspberry Pi Setup Process

      As a good habit, I constantly update the Raspberry Pi before using it for the first time. In this project phase, we will handle the web-to-raspberry-pi connection by upgrading the Pi and setting up the WebIOPi framework. The python Flask framework provides a potentially more straightforward alternative, but getting your hands dirty and looking at how things operate makes DIY appealing. When you get to that point, the fun of DIY begins. Use the updated commands below to upgrade your Raspberry Pi and restart the RPi.

      sudo apt-get update

      sudo apt-get upgrade

      sudo reboot

      After this is finished, we can set up the webIOPi framework. Using, verify that you are in your home directory.

      cd ~

      To download the files from the google page, type wget.

      wget http://sourceforge.net/projects/webiopi/files/WebIOPi-0.7.1.tar.gz

      Then, once the download is complete, unzip the file and enter the directory;

      tar xvzf WebIOPi-0.7.1.tar.gz

      cd WebIOPi-0.7.1/

      Unfortunately, I could not locate a version of WebIOPi that is compatible with the Pi 4; thus, we have to download a patch before proceeding with the setup. Run the instructions below from within the WebIOPi directory to apply the patch.

      wget https://raw.githubusercontent.com/doublebind/raspi/master/webiopi-pi2bplus.patch

      patch -p1 -i webiopi-pi2bplus.patch

      Once we have those things, we can begin the WebIOPi setup installation process by using the;

      sudo ./setup.sh

      Just click "Yes" when prompted to install more components during setup. Upon completion, restart your Pi.

      sudo reboot

      Verify the WebIOPi Setup

      Before diving into the schematics and programs, we should power on the Raspberry Pi and ensure our WebIOPi installation is functioning as expected. Execute the command below;

      sudo webiopi -d -c /etc/webiopi/config

      After running the above command on the pi, open a web browser and navigate to http://raspberrypi.mshome.net:8000 (or HTTP;//thepi'sIPaddress:8000) on the computer that is attached to the pi. When logging in, you'll be asked for a username and password.

      Username is webiopi

      Password is raspberry

      You may permanently disable this login if you no longer need it. Still, it's important to keep unauthorized users from taking control of your home's appliances and Internet of Things (IoT) components. After you've logged in, go to the GPIO header link.

      Make GPIO 17 an output; we'll use it to power an LED in this Test.

      Following this, attach the led to the Pi 4 as depicted in the schematics.

      When you're ready to activate or deactivate the LED, return to the web page where you made the connection and select the pin 11 button. This allows us to use WebIOPi to manage the Raspberry Pi's GPIO pins. If the Test is successful, we can return to the console and exit the program by pressing CTRL + C. Please let me know in the comments if this arrangement has any problems. Once the pilot is finished, we can begin the actual project.

      Developing a Web-Based Home-Control application for the Raspberry Pi

      In this section, we will alter the WebIOPi service's standard setup and inject our code to be executed on demand. FileZilla or another FTP/SCP copy program will be the first tool we install on our computer. You'll agree that using the terminal to write code on the Pi is a stressful experience, so having access to Filezilla or another SCP program will be helpful. Let's make a project directory in which all our web scripts will be stored before we begin writing the HTML, CSS, and javascript programs for this Internet - of - things Home automated Web app and transferring them to the RPi.

      First, make sure you're in your home directory using; next, create the folder; finally, open the newly constructed folder and make an HTML folder inside it.

      cd ~

      mkdir webapp

      cd webapp

      mkdir HTML

      Make subfolders inside the HTML folder for scripts, CSS, and graphics.

      mkdir html/css

      mkdir html/img

      mkdir html/scripts

      Now that we have our files prepared, we can start coding on the computer and transfer our work to the Pi using Filezilla.

      The JavaScript Code

      Writing the javascript will be our first order of business. An easy-to-use script for interacting with the WebIOPi server. Our four-button web app will only use two relays in the demonstration, and we only intend to control four GPIO pins for this project.


       webiopi().ready(function() {

                              webiopi().setFunction(17,"out");

                              webiopi().setFunction(18,"out");

                              webiopi().setFunction(22,"out");

                              webiopi().setFunction(23,"out");

                                                      var content, button;

                              content = $("#content");

                                                      button = webiopi().createGPIOButton(17," Relay 1");

                              content.append(button);

                                                      button = webiopi().createGPIOButton(18,"Relay 2");

                              content.append(button);

                                                      button = webiopi().createGPIOButton(22,"Relay 3");

                              content.append(button);

                                                      button = webiopi().createGPIOButton(23,"Relay 4");

                              content.append(button);

                                      });

      Once the WebIOPi is ready, the preceding code is executed. To help you understand JavaScript, we've explained below:

      • webiopi().ready(function()

      All this tells our system to make this function and call it once the webiopi is set.

      • webiopi().setFunction(23,"out")

      We can instruct the WebIOPi program to use GPIO23 for output. Four buttons are now available, but you may add more if necessary.

      • var content, button

      With this line, we're instructing the system to make a new variable called content into a button.

      • content = $("#content")

      We will continue using the content variable in our HTML and CSS. As a result, the WebIOPi framework generates everything connected to #content when it is mentioned.

      • button = webiopi().createGPIOButton(17,"Relay 1")

      WebIOPi can make several distinct types of push buttons. This code instructs the WebIOPi program to generate a GPIO key that operates on the GPIO pin identified as "Relay 1" above. The other ones are the same, too.

      • content.append(button)

      Add this code to the button's existing HTML or external code. New buttons can be made that are identical to this one in every respect. This is especially helpful while coding or writing CSS.

      If you made your JS files the same way I did, you can save them and then move them with Filezilla to webapp/HTML/scripts after you've finished making them. Now we can move on to developing the CSS.

      The CSS Code:

      With the aid of CSS, our Internet of Things (IoT) Rpi 4 home automation website now looks fantastic. So that the website will look like the one in the picture below, I built a custom style sheet called smarthome.css.

      I don't want to paste the entire CSS script here, so I'll use a subset for the explanation. If you want to learn CSS, all you have to do is read the code. You can skip this and use our CSS code if you want to.

      The first section of the script, displayed below, represents the web application's main stylesheet.

       body {

               background-color:#ffffff;

               background-image:URL('/img/smart.png');

               background-repeat:no-repeat;

               background-position:center;

               background-size:cover;

               font: bold 18px/25px Arial, sans-serif;

               color:LightGray;

           }

      The above code, which I hope needs no explanation, begins by setting the background colour to white (#ffffff), adds a background image to the document from the specified folder (remember the one we created earlier? ), makes sure the picture doesn't duplicate by setting the background-repeat to no-repeat, and finally tells the CSS to center the background. Next, we adjust the background's text size, font, and colour.

      After finishing the main content, we styled the buttons with CSS.

      button {

               display: block;

               position: relative;

               margin: 10px;

               padding: 0 10px;

               text-align: center;

               text-decoration: none;

               width: 130px;

               height: 40px;

               font: bold 18px/25px Arial, sans-serif;  color: black;

               text-shadow: 1px 1px 1px rgba(255,255,255, .22);

               -WebKit-border-radius: 30px;

                -Moz-border-radius: 30px;

                border-radius: 30px;

      }

      Everything else in the script is similarly optimized for readability and brevity. You can play with them and see what happens; this kind of learning is known as "learning by doing," I believe. However, CSS's strengths lie in its simplicity, and its rules are written in plain English. The button's text shadow and button shadow are two of the few supplementary features found in the block's other section. To top it all off, pressing the button triggers a subtle transition effect, making it look polished and lifelike. To guarantee optimal page performance on all browsers, these are defined independently for WebKit, firefox, opera, etc.

      The following code snippet notifies the WebIOPi service that it is receiving data as input.

      input[type="range"] {

                                                      display: block;

                                                      width: 160px;

                                                      height: 45px;

                              }

      Providing feedback on when a button is pressed will be the last element we want to implement. As a result, the screen's colour scheme and button hues provide a quick indicator of progress. To accomplish this, the following line of code is added to each button's HTML.

                              #gpio17.LOW {

                                                      background-color: Gray;

                                                      color: Black;

                              }

                              #gpio17.HIGH {

                                                      background-color: Red;

                                                      color: LightGray;

                              }

      The code snippets up top alter the button's color depending on the user's selection. The button's background is gray when it is inactive (at LOW) and red when it is active (at HIGH). Now that we have our CSS under control let's save it as smarthome.css, upload it to our raspberry pi's styles folder using FileZilla (or another SCP client of your choosing), and fix the remaining HTML code.

      HTML Code

      The HTML code unifies the style sheets and java scripts.

      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

      <html>

      <head>

              <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

              <meta name="mobile-web-app-capable" content="yes">

              <meta name="viewport" content = "height = device-height, width = device-width, user-scalable = no" />

              <title>Smart Home</title>

              <script type="text/javascript" src="/webiopi.js"></script>

              <script type="text/javascript" src="/scripts/smarthome.js"></script>

              <link rel="stylesheet" type="text/CSS" href="/styles/smarthome.css">

              <link rel="shortcut icon" sizes="196x196" href="/img/smart.png" />

      </head>

      <body>

                              </br>

                              </br>

                              <div id="content" align="center"></div>

                              </br>

                              </br>

                              </br>

                              <p align="center">Push button; receive bacon</p>

                              </br>

                              </br>

      </body>

      </html>

      The head tag contains several crucial elements.

      <meta name="mobile-web-app-capable" content="yes"> 

      The code line above makes it possible to add the web app to the mobile device's home screen when using Chrome or Safari. You can access this function using the Chrome menu. This makes it so the app may be quickly launched on any mobile device or desktop computer.

      The following line of code provides a measure of responsiveness for the web app. Because of this, it can take up the entire display of any gadget on which it is run.

      <meta name="viewport" content = "height = device-height, width = device-width, user-scalable = no" /> 

      The web page's title is defined in the following line of code.

      <title>Smart Home</title>

      The following four lines of code all connect the Html file to multiple resources it requires to function as intended.

              <script type="text/javascript" src="/webiopi.js"></script>

              <script type="text/javascript" src="/scripts/smarthome.js"></script>

              <link rel="stylesheet" type="text/CSS" href="/styles/smarthome.css">

              <link rel="shortcut icon" sizes="196x196" href="/img/smart.png" />

      The first line above directly connects to the WebIOPi framework JavaScript, which is stored in the server's root directory. This method must be invoked whenever WebIOPi is used.

      The second line tells the HTML document where to find our jQuery script, and the third tells where to get our style sheet. The last line prepares an icon for the mobile desktop, which can be useful if we use the website as an app or a favicon.

      To ensure that our HTML code displays whatever is contained in the JavaScript file, we include break tags in the body portion of the code. The definition of our button's content was made previously in the JavaScript code, and its id="content" should bring that to mind.

      <div id="content" align="center"></div>

      Everybody is familiar with the routine of saving an Html file as index.html and then transferring it to the Pi's HTML folder via Filezilla.

      Modifications to the WebIOPi Server for Use in Automated Household Tasks

      Before we can begin sketching out circuit diagrams and running tests on our web app, we need to make a few adjustments to the webiopi service's configuration file, instructing it to look for configuration information in our HTML folder rather than the default location.

      Edit the configuration by executing the following commands as root:

      sudo nano /etc/webiopi/config

      Find the section of the configuration file labelled "HTTP" and look for the line that begins with "#" Modify the directory where HTML and resources are stored by default with doc-root.

      Remove the # comments from anything below it, and if your folder is organized like mine, set the doc-root to the location of your project file.

      doc-root = /home/pi/webapp/html

      Lastly, save your work and exit. If you already have another server installed on the Pi utilizing port 8000, you may easily change it. If not, let's stop saving and call it a day.

      It's worth noting that the WebIOPi service password can be changed using the command;

      sudo webiopi-passwd

      A new login name and password will be required. Getting rid of this entirely is possible, but safety comes first.

      Finally, issue the following command to start the WebIOPi service.

      sudo /etc/init.d/webiopi start

      If you want to see how the server is doing, you can do so by;

      sudo /etc/init.d/webiopi status

      That's why there's a way to halt its execution:

      sudo /etc/init.d/webiopi stop

      Setup WebIOPi to start automatically with;

      sudo update-RC.d webiopi defaults

      To do the opposite and prevent it from starting up automatically, use the following;

      sudo update-RC.d webiopi remove

      Schematic and Explanation of a Circuit

      Now that we have everything set up, we can begin developing the schematics for our Web-controlled home appliance.

      Whereas I could not procure relay modules, which in my experience, make electronics projects simpler for do-it-yourselfers. So, I'm going to draw some diagrams for regular, single-relay, 5V-powered standalone devices.

      Join the components as seen in the fritzing diagram. It's important to remember that your Relay's COM, NO (usually open), and NC (typically Close) contacts could be on opposite sides. Please verify this with a millimetre.

      Relays Underlying Operating Principles

      Relays can be found anywhere that electricity is being switched, from a simple traffic light controller to a high-voltage switchyard. Relays, in the broadest sense, are equivalent to any other switch. They can connect or disconnect a circuit and are frequently employed to activate or deactivate an electrical load. However, this is a comprehensive statement; there are many other relays, and each Relay behaves slightly differently depending on the task at hand; as the electromechanical Relay is one of the most widely used relays, we will devote more space to discussing it here. In spite of variations in design, all relays work according to the same fundamental concept, so let's dive into the nuts and bolts of relays and talk about how they function.

      So, what exactly is Relay?

      A relay is called an electromechanical switch that may either establish or rupture an electrical connection. A relay is like a mechanical switch, except that it is activated and deactivated by an electronic signal rather than by physically flipping a switch. It comprises a flexible movable mechanical portion controlled electrically through an electromagnet. Once again, this Relay operating concept is suitable exclusively for electromechanical relays.

      A common and widely used relay consists of electromagnets typically employed as a switch. However, there are many kinds of relays, each with its purpose. When a signal is received on one side of the device, it controls the switching activity on the other, much like the dictionary definition of Relay. That's right, a relay is an electromechanical switch that can open and close circuits. This device's primary function is to establish or sever contact with the aid of a signal to turn it ON or OFF automatically and without human intervention. Its primary use is to allow a low-power signal to exert control over a circuit with a high power consumption. Typically, the high-voltage circuit is controlled by a direct current (DC) signal.

      How the Relay is Built and Functions

      The following diagram depicts the internal structure and design of a Relay.

      A coil of copper wire is wound around a core, which is then placed inside a housing. When the coil is electrified, it attracts the movable armature, which is supported by a spring or stand and has a metal contact attached to one end. This assembly is positioned over the core. In most cases, the movable armature is a shared connection point for the motor's internal components and the other wiring harness. The usually closed (NC) pin is linked to the common terminal, while the ordinarily opened (NO) pin is not used in operation. By connecting the armature to the usually open contact whenever the coil is activated, current can flow uninterruptedly through the armature. When the power is turned off, it returns to its starting position.

      The picture below shows a schematic of the Relay's circuit in its most basic form.

      Relay Teardown: An Inside Look

      In the images below, you can see the main components of an electromechanical relay—an electromagnet, a flexible armature, contacts, a yoke, and a spring/frame/stand. They have been thoughtfully placed into a relay.

      The workings of a Relay's mechanical components have been outlined below.

      1. Electromagnet

      An electromagnet is crucial to the operation of a relay. This metal lacks magnetic properties but can be transformed into a magnet when exposed to an electrical current. It is healthy knowledge that a conductor takes on the magnetic characteristics of the current flowing through it. Thus, a metal can operate as a magnet and attract magnetic objects within its range when wound with a conductive material and powered by an adequate power source.

      1. Movable Armature

      A moveable armature is just one piece of metal that can rotate or stand on its own. It facilitates connection-making and -breaking with the contacts attached to it.

      1. Contacts

      Internal conductors are the wires that run through a device and hook up to its terminals.

      1. Yoke

      It's a tiny metal piece attached to a core that attracts and retains the armature whenever the coil is activated.

      1. Spring (optional)

      While some relays can function without a spring, those that do have one attach it to the armature at one end to prevent any snagging or binding. One can use a metal "stand" in place of a spring.

      Mechanism of Action of a Relay

      Let's examine the differences between a relay's normally closed and normally open states. 

      Relay's NORMALLY CLOSED state

      If no current flows through the core, there will be no magnetic field, and the device will not be a magnet. As a result, it is unable to draw in the flexible framework. So, the ordinarily closed position of the armature is the starting point (NC).

      Relay in NORMALLY OPENED state

      When a high enough voltage is supplied to the core, it begins to have a strong magnetic field around itself, allowing it to function as a magnet. The magnetic field produced by the core attracts the movable armature whenever it comes within its field of influence, changing the armature's location. As it has been wired to a normally open relay pin, any external circuits attached to it will no longer operate in the same way.

      It is important to connect the relay pins correctly so that the external circuit can do its job. When a coil is powered, the armature is drawn toward it, revealing the switching action; when the power is cut, the coil loses its magnetic property, and the armature returns to its original location. The animation provided below shows the Relay in action.

      Transistor functions in the circuit

      There is nothing complicated about a transistor, yet there is a lot going on inside it. Okay, so first, we'll tackle the easy stuff. An electronic transistor is a small component that can switch between two functions. It's a switch that can also act as an amplifier.

      An amplifier is a device that takes in a little electric current and outputs a significantly larger electric current (called an output current). It can be thought of as a current booster. One of the earliest applications for transistors, this is particularly helpful in devices like hearing aids. A hearing aid contains a microscopic microphone that converts ambient sound into electrical signals. These are then amplified by a transistor and used to power a miniature loudspeaker, which reproduces the ambient noise at a much higher volume.

      It is possible to use a transistor as a switch. A transistor is a device that allows for the passage of one electrical current to induce a much larger current to flow through the next part of the device. What this means is that a relatively small current can activate a much larger one. All computer chips function in this general way. As an illustration, a memory chip may have as many as a billion individually controllable transistors. Due to the fact that each transistor can exist in either of two states, it is capable of storing either a zero or a one. A chip's ability to hold billions of zeroes and ones, as well as almost as many regular numbers and letters, is made possible by its billions of transistors.

      Diode functions in the circuit

      Diodes can range in size from what's shown in the image up top. They feature a cylindrical body that is usually black with a stripe at one end and certain leads that protrude so that we may plug it into a circuit. The opposite terminal is called the cathode and is opposite the anode.

      A diode is an electrical component that restricts current flow in one direction.

      To illustrate, picture a swing valve fitted in a water line. The water pressure inside the pipe will force open the swing gate, allowing the water to flow uninterrupted. In contrast, the gate will be forced shut, and water flow will stop if the river alters its course. As a result, there is only one direction for water to flow.

      Very much like a diode, which we also employ to alter the current flow through a circuit, it allows us to switch it on and off at will.

      We have now animated this process using electron flow, in which electrons move from negative to positive. However, traditional flow, positive to negative, is the norm in electronics engineering. It's usually best to start with the conventional current because it's more familiar to most people, but feel free to use either one; we'll assume you're aware of the difference.

      It's important to remember that the light-emitted diode will only light up properly if the diode is connected to the circuit in the correct orientation when adding it to a simple Light emitted diode circuit like the one shown above. Only one direction of current can travel through it. Accordingly, its conductive or insulating properties are determined by the orientation in which it is mounted.

      So that it can conduct electricity, you must join the black end to the neutral and the striped end to the positive. The forward bias is the condition in which current can flow. If we invert the diode, it will become an insulator and stop the passage of electricity. The term for this is "the reverse bias."

      Exactly how would a diode function?

      You probably know that electricity is the transfer of electrons between atoms that are not bound. Because of its high number of unpaired electrons, copper is widely used for electrical wiring. Since rubber is an insulator—its electrons are kept very securely, so they cannot flow between atoms—it is used to wrap around the copper wires for our protection.

      In a simplified form of a metal conducting atom, the nucleus is at the center, and the electrons are housed in a series of shells around it. It takes a specific amount of energy for an electron to be absorbed into each shell, and each shell has a max number of electrons it can hold. Those electrons that are furthest from the nucleus are the most energetic. Conductors have between one and three electrons in their outermost "valence" shell.

      The nucleus acts as a magnet, keeping the electrons in place. However, there is yet another layer, the conduction band. If an electron gets here, it can leave its atom and travel to another. Because the valence shell and conduction band of a metal atom overlap, the electron can move quickly and easily between the two.

      The insulator has a tightly packed outer layer. No free space for electrons to occupy. Because of the strong attraction between the nucleus and the electrons and the great distance between the nucleus and the conduction band, the electrons are trapped inside the nucleus and cannot leave. Because of this, electricity is unable to travel through it.

      Of course, a semiconductor is also a different type of material. A semiconductor might be silicon, for instance. This material behaves as an insulator because it has one more electron than is necessary in its outermost shell to be a conductor. However, with enough external energy, a few valence electrons can generate enough momentum to hop across to the conduction band, where they can finally break free. Consequently, this substance can perform the roles of both an insulator and a conductor.

      Due to the lack of free electrons in pure silicon, engineers must add a small number of materials (called "doping") to the silicon to alter its electrical properties.

      This process gives rise to P-type and N-type doping, respectively. The diode itself is a combination of these doped materials.

      Two leads connect the anode and cathode to various thin plates inside the diode. P-Type doped silicon is on the anode side of these plates, and the cathode side is N-Type doped silicon—an insulating and protective resin that coats the entire structure.

      Consider the material to be pure silicon before it has been doped. There are four silicon atoms surrounding each one. Because silicon atoms need eight electrons to fill their valence shells but only have four available, they share one with their neighbours. Covalent bonding describes this type of interaction.

      Phosphorus, an N-type element, can be substituted for a number of silicon atoms in a compound semiconductor. Phosphorus has a 5-electron valence shell because of this. This extra electron isn't needed because particles are sharing them to reach the magic number of 8. This means there's an extra electrons in the material, and it's free to go wherever it wants.

      In P-type doping, a substance like aluminum is introduced. Due to its limited valence electron pool of 3, this atom is unable to share an electron with any of its four neighbours. An electron-sized void is therefore made available.

      We now have silicon with either too many or too few electrons, depending on the doping method.

      Upon joining, the two substances forge a p-n junction. This is a depletion region, and it forms at the intersection. Here, some of the surplus electrons on the N-type side migrate over to fill the vacancies on the P-type side. By moving in this direction, electrons and holes will accumulate on either side of a barrier. Holes are thought to be positively charged since they are the opposite of electrons, which are negatively charged. The resulting accumulation produces two distinct regions, one slightly negatively charged and the other slightly positively charged. This forms an electric field that blocks the path of any more electrons. In regular diodes, the voltage drop over this area is only 0.7V.

      By applying a voltage across the diode with the P-Type anode linked to the positive and the N-Type cathode attached to the negative, a forward bias is established, and current can flow. The electrons can't get over the 0.7V barrier unless the voltage source is higher.

      We can achieve this by connecting the positive terminal of the power supply to the cathode of an N-type device and the negative terminal to the anode of a P-type device. The diode functions as a conductor to block current because the barrier expands as holes are drawn toward the negative and electrons are drawn toward the positive.

      Resistor functions in the circuit

      A resistor is a two-terminal, non-active electrical component that reduces the amount of current in electric and electronic circuits. A certain amount can lower the current by strategically placing a resistor in a circuit. From the outside, most resistors will appear identical. But if you crack it open, you'll find a ceramic rod used for insulation within, with copper wire covering the rest of the structure. Those copper twists are crucial to the resistance. When copper is sliced thinner, resistance rises because electrons have more difficulty penetrating the material. We now know that electrons can move more freely through some conductors than insulators.

      George Ohm investigated the correlation between resistor size and material thickness. His proof showed that an object's resistance (R) grows in proportion to its length. Because of this, the resistance offered by the lengthier and thin wires is greater. However, wire thickness has a negative effect on resistance.

      Once everything is hooked up, you can start your server by browsing to the IP address of your RPi and entering the port you chose earlier (as mentioned in the previous section), entering your password and username and seeing a page that looks like the one below.

      All it takes is a few clicks of your mouse to operate four AC home appliances from afar. This can be controlled from a mobile device (phone, tablet, etc.) and expanded with additional switches and relays. Thank you all for reading to the end.

      Conclusion

      This guide showed us how to set up a web-based control system for our home automation system based on the Raspberry Pi 4. We have learned how to utilize the WebIOPi API to manage, debug, and use raspberry Pi's GPIO, sensors, and adapters from an internet browser or any application. We have also implemented JavaScript, CSS, and HTML code for the web application. For those who thrive on difficulty, feel free to build upon this base and add whatever demanding module you can think of to the project. The following tutorial will teach you how to use a Raspberry Pi 4 to create a Line Follower robot that can navigate obstacles and drive itself.

      Syed Zain Nasir

      I am Syed Zain Nasir, the founder of <a href=https://www.TheEngineeringProjects.com/>The Engineering Projects</a> (TEP). I am a programmer since 2009 before that I just search things, make small projects and now I am sharing my knowledge through this platform.I also work as a freelancer and did many projects related to programming and electrical circuitry. <a href=https://plus.google.com/+SyedZainNasir/>My Google Profile+</a>

      Share
      Published by
      Syed Zain Nasir