Search Results
737 results found with an empty search
- Introduction to Scapy
In this article we will see what is scapy? How it works but before we must know about the network, protocol and their types, TCP port number and packets. Let's start. What is a network? A network consists of two or more computers in the network that use a set of common communication protocols over digital interconnection for the purpose of sharing information. Computer networks are categorized as Local Area Network LANs, Metropolitan Area Networks MANs and Wide Area Network WANs based on the maximum distance on the network. Networks that connect hosts in a room building, or building of campus are called LANs. The distance between hosts on a LAN can be anywhere from a few meters to about one kilometer. Networks that are used to connect hosts within a city, or between small cities are known as MANs. The distance between hosts on a MANs is about one to 20 kilometers. Networks that are used to connect hosts within a state or country are known as WANs. The distance between hosts on a WANs is in the range of ten of kilometers to thousands of kilometers. Protocol is a set of rules that allow two or more devices to exchange information over the network. It is a router that determines a packet's path from source to destination hardware implemented protocols in the network interface cards of two physically connected computers control the flow of bits on the wire between the two computers. A congestion control protocol controls the rate at which packets are transmitted between sender and receiver. Protocols are running everywhere on the internet. Transmission Control Protocol (TCP) is used for a set of rules to send the data into packet form over the network and ensure the successful delivery of the data on the destination site on the network . Internet Protocol is used for a set of rules to send and receive data at the IP address. An IP address is the unique identification for every device which is connected across the network. This Internet protocol has two versions IPv4 and IPv6. IPv4 IP stands for Internet Protocol and v4 stands for version 4. It has 12 fields and Each IP address is 32 bit long (Equivalent 4 bytes). IP addresses are typically written in so-called dot decimal notation. Each byte of the address is in the decimal form and Each value should be between 0 to 255. For example, a typical address would be 193.32.216.9. The 193 is the decimal equivalent for the first 8 bits of the address and the 32 is the decimal equivalent for the second 8 bits of the address etc. IPv6 New networks and IP nodes are being attached to the internet at a breathtaking rate. To respond to this need of large IP space, a new IP protocol, IPv6, was developed. IPv6 address moves 32 bit to a 128-bit address space. It allows 340 undecillion unique address spaces. IPv6 address contains letters and numbers and it has 8 groups. For example a typical address would be 2002:db8::8a2f:362:7797. In IPv6 there are three types of addresses. In addition to unicast and multicast addresses, a new type of address, called an anycast address, has also been introduced which allows a packet addressed to an anycast address to be delivered to any one of a group of hosts TCP port number An IP address is not sufficient to run a network application. On a computer running multiple applications or services. IP address just identifies only devices not their application. Port number identifies the application and services which are running on the computer. A TCP port number is a unique identification of each application and it is used with an IP address. A port is a 16 bit unsigned integer, and the total number of ports available in the TCP/IP model is 65,535 ports. Hence the range of port numbers is 0 to 65,535. Here is an example of port number 193.32.216.9:7. In that case 192.32.216.9 is an IP address and 7 is port number. What is Scapy Scapy is a python program and it is one of the best packet manipulation tools. It enables the user to send the dissect, sniff and forge packet. This allows their construction tools to scan, probe or attack on the network. In short, scapy is a most powerful tool for packet manipulation programs. We can easily forge and dissect packets with the help of scapy. Tracerouting, probing, unit testing and network scanning are some tasks handled by scapy. It can change most important tools like hping, arpspoof, arp-sk, arping, p0f etc. We can also set the source IP and destination IP and then we can send the packet from source IP to destination IP. Scapy does two things: sending packets and receiving answers. Scapy is also capable of sending invalid frames, injecting your own 802.11 frames, combining techniques. Scapy sends a packet, and receives an answer that matches requests with answers and returns a list of packet couples (request, answer) and a list of unmatched packets. This has the big advantage over tools like Nmap or hping that an answer is not reduced to (open/closed/filtered), but is the whole packet. When we communicate or exchange the information across the network all the data is transferred in the packet form. Packet is a small segment of a large message. These packets are then recombined by the device that receives them. Packet header stores all the information like source and destination IP address TCP ports etc. Why is scapy so special ? Fast Packet Design Scapy paradigm is to propose a domain specific language enabling a powerful and fast description of any kind of packet. Scapy enables the user to describe a packet or set of packets as layers that are stacked one upon another. Scapy does not oblige the user to use predetermined methods or templates. Probe once, interpret many Scapy gives all the information, i.e. all the stimuli sent and all the responses received. Scapy gives the complete raw data, that data may be used many times allowing the viewpoint to evolve during analysis For e.g. a TCP port scan may be probed and the data visualized as the result of the port scan. Pcap is an application programming interface for capturing network traffic. Wireshark is a network analyzer that is to create the .Pcap file to collect and record data from the network. Now here Using the rdcap read the pcap file displaying data. Code Snippet : from scapy.all import * import os d = " " data = "202011251400-78-5k.pcap" d = rdpcap(data) sessions = d.sessions() print(sessions) Output : Now Let's analyze the network data. Identify elephant TCP flows, i.e., those flows that transfer a large amount of data, in a packet trace captured at a vantage point in the ISP network. Now here Read the .Pcap file using PcapReader() and store the source IP, destination IP, source port number and destination port number and also packet length in the dictionary form. Code Snippet : from scapy.layers.inet import IP, TCP pkts = 0 flows = 0 ft = {} for pkt in PcapReader(data): pkts += 1 if IP in pkt: if TCP in pkt: ft[(pkt[IP].src,pkt[IP].dst,pkt[TCP].sport,pkt[TCP].dport)]= pkt.wirelen flows +=1 ft Output : Plotting Top 100 TCP flow size distribution Code Snippet : topn = 100 data = [i/1000 for i in list(self.ft.values())] data.sort() data = data[-topn:] fig = plt.figure() ax = fig.add_subplot(1,1,1) ax.hist(data, bins=20, log=True) ax.set_ylabel('# of flows') ax.set_xlabel('Data sent [KB]') ax.set_title('Top {} TCP flow size distribution.'.format(topn)) plt.savefig(sys.argv[1] + '.flows.pdf', bbox_inches='tight') plt.close() Output : Thank You.
- Image Classification Using Keras - Chest X-Ray Image
In this article we will discuss Convolutional neural networks and perform image classification using keras. What is CNN ? CNN stands for convolutional neural networks. Convolutional is one type of scanning and the Neural network is a system of interconnected artificial neurons that exchange messages to each other. Nowadays CNN is widely used for pattern and image recognition techniques. They have a number of advantages compared to other techniques. Hence so many companies use these techniques. How does it work ? Machines identify the image as a pixel form and do these pixel scanning by filter and collect information of the input image. When we slide the filter on the image we get new values by matching from the pixel value. These values help us to identify all the image features. Image features are fed into the convolutional layer. Outputs of convolutional layers are fed into a fully connected layer. Finally CNN predicts the features of the image and we get the result. Different layers of CNN Convolutional layer Poling layer Fully connected layer Why is CNN required ? It gives high accuracy It require less memory for processing and execution Image detection using CNN is robust to distortion like shape change due to camera lens, different position, different lighting conditions etc. Now we are going to perform the Chest X-Ray image classification using Keras. We have a dataset of Chest X-Ray images (pneumonia). We will perform the image classification using keras. Keras is a deep learning API written in Python, running on top of the machine learning platform TensorFlow. It is an open-source software library that provides a Python interface for artificial neural networks. It is an open-source software library that provides a Python interface for artificial neural networks. Keras follows best practices for reducing cognitive load: it offers consistent & simple APIs, it minimises the number of user actions required for common use cases, and it provides clear & actionable error messages. It also has extensive documentation and developer guides. First we will import some important libraries. We have a dataset of chest X-Ray images which is downloaded from kaggle. The Train dataset contains a total of 5216 images, where 1341 images belong to the Normal category, 3875 images depicted Pneumonia And, Test dataset contains a total of 624 images, where 234 images belong to the normal category, 390 images depicted Pneumonia. # Importing all necessary libraries from keras.preprocessing.image import ImageDataGenerator from keras.models import Sequential from keras.layers import Conv2D, MaxPooling2D from keras.layers import Activation, Dropout, Flatten, Dense from keras import backend as K import matplotlib.pyplot as plt from os from os.path from pathlib import * import pandas as pd import seaborn as sns Create neural network models and to train a dataset. The architecture of a CNN is a key factor in determining its performance and efficiency. The way in which the layers are structured, which elements are used in each layer and how they are designed will often affect the speed and accuracy with which it can perform various tasks. The function Sequential( ) is used to group a linear stack of layers into a tf.keras.Model. We defined an instance of Sequential named 'model' and using it we added 3 hidden layers to the neural network. The first two layers have 'relu' as their activation function and the last one has 'softmax' as its activation function. We then combined all the layers using model. compile and trained the model on our training data. Convolutional layer Apply Convolutional operation on the input data using conv_2d library and passing to the MaxPooling 2 layer. Conv_2d converts the image into multiple images. Activation is the activate function. This layer computes the dot product between their weights and a small region and they are connected to the input layer. It will change the dimension depending on the filter size. Relu Relu is a Rectifying Linear Unit. The Relu function returns the positive value or 0 in place of the previous negative value. It does not change the dimension of the previous layer. Max Pooling layer Apply max_pool_2d on the convolutional layer. This layer will reduce the spatial size of the convolved features and also reduce overfitting by providing an abstract representation of them. Below is an example of a max pooling layer. Fully connected layer This layer is the final layer of the CNN model. This layer computes all the input layers and determines the final prediction. In this layer all the input layer nodes are connected to every node in the second layer. We can use one or more than fully connected layers. Dropout layer Dropout layer is a regularization technique and it is used for reducing overfitting in CNN. In general the dropout layer is used in fully connected layers in deep learning models but it is possible to use after the max_pooling layer. Dropout layer should not be used on test data because dropout is a random process of disabling the neuron in a layer and your network will have different output every sequence of activation. Code Snippet : model = Sequential() model.add(Conv2D(32, (2, 2), input_shape=input_shape)) model.add(Activation('relu')) model.add(MaxPooling2D(pool_size=(2, 2))) model.add(Conv2D(32, (2, 2))) model.add(Activation('relu')) model.add(MaxPooling2D(pool_size=(2, 2))) model.add(Conv2D(64, (2, 2))) model.add(Activation('relu')) model.add(MaxPooling2D(pool_size=(2, 2))) model.add(Conv2D(32, (2, 2))) model.add(Activation('relu')) model.add(MaxPooling2D(pool_size=(2, 2))) model.add(Flatten()) model.add(Dense(64)) model.add(Activation('relu')) model.add(Dropout(0.5)) model.add(Dense(1)) model.add(Activation('sigmoid')) model.compile(loss='binary_crossentropy',optimizer='rmsprop',metrics=['accuracy']) model.summary() Once a model is "built", you can call its summary() method to display its contents However, it can be very useful when building a Sequential model incrementally to be able to display the summary of the model so far, including the current output shape. In this case, you should start your model by passing an Input object to your model, so that it knows its input shape from the start We will plot a graph of the number of pneumonia affected X-Ray images and normal images present in the training dataset. Code Snippet : # count plot of training dataset sns.set_style('whitegrid') sns.countplot(x='Label',data=train_df) In the following count plot we can see the dataset contains pneumonia affected X-Ray are over 3500 and Normal X-Rays are below 1500. Output : We will plot some images which is present in the dataset Code snippet : # Display some pictures of the dataset fig, axes = plt.subplots(nrows=4, ncols=6, figsize=(15, 7),subplot_kw={'xticks': [], 'yticks': []}) for i, ax in enumerate(axes.flat): ax.imshow(plt.imread(train_df.Filepath[i])) ax.set_title(train_df.Label[i], fontsize = 15) plt.tight_layout(pad=0.5) plt.show() Output : We will now check the accuracy and loss of the model and will plot the same. Code Snippet : # Plot graph plt.plot(history.history['accuracy'],'r',label='training accuracy') plt.plot(history.history['val_accuracy'],'b',label='validation accuracy') plt.xlabel('epochs') plt.ylabel('accuracy') plt.legend() plt.show() plt.plot(history.history['loss'],'r',label='training loss') plt.plot(history.history['val_loss'],'b',label='validation loss') plt.xlabel('epochs') plt.ylabel('loss') plt.legend() plt.show() Output : Thank You
- INDIAN PREMIER LEAGUE DATA ANALYSIS
In this Article we are going to analyze the IPL dataset. In this analysis we are focusing on bowler performance during the Indian premier league. The data which has been used in this article has been gathered from Kaggle. The data set consists of data about IPL matches played from the 2008 to 2019. We have two dataset deliveries and matches. In Deliveries data set contains the 21 attributes and 179078 records and The matches dataset contains 18 attributes and 756 records. Our Objective To find top 10 Player names who takes most wickets To find top 10 Player names who have bowled most no balls To find top 10 Player names who have bowled most wide balls To find top 10 Player names by their bowling average To find top 10 Player names by their bowling strike rate To find top 10 Player names by their bowling Economy rate Number of winning teams To find top 10 Player names who most runs To find top 10 Player names who become the most of the time man of the match Our Goal : Basic Exploratory Analysis Features Analysis Dependencies/Libraries Required: In this step, we imported all the required libraries like seaborn, pandas(for preprocessing), math, matplotlib etc. import pandas as pd import numpy as np import matplotlib.pyplot as plt import seaborn as sns import math from IPython.display import display Loading the data ipl_deliveries = 'IPL Data 2008 to 2019\\deliveries.csv' ipl_match = 'IPL Data 2008 to 2019\\matches.csv' ipl_deliveries = pd.read_csv(ipl_deliveries) ipl_match = pd.read_csv(ipl_match) Output : Displaying deliveries dataset Attributes names of deliveries dataset Matches data Attributes name of matches dataset Data Preparation and Data Cleaning The data set found inaccurate records. the same team with two different names. So In this step, replace the team name and venue name also. Now the data is ready for analysis. Code snippet : ipl_match.team1.replace({'Rising Pune Supergiants' : 'Rising Pune Supergiant'},regex=True,inplace=True) ipl_match.team2.replace({'Rising Pune Supergiants' : 'Rising Pune Supergiant'},regex=True,inplace=True) ipl_match.winner.replace({'Rising Pune Supergiants' : 'Rising Pune Supergiant'},regex=True,inplace=True) ipl_match.venue.replace({'Feroz Shah Kotla Ground':'Feroz Shah Kotla', 'M Chinnaswamy Stadium':'M. Chinnaswamy Stadium', 'MA Chidambaram Stadium, Chepauk':'M.A. Chidambaram Stadium', 'M. A. Chidambaram Stadium':'M.A. Chidambaram Stadium', 'Punjab Cricket Association IS Bindra Stadium, Mohali':'Punjab Cricket Association Stadium', 'Punjab Cricket Association Stadium, Mohali':'Punjab Cricket Association Stadium', 'IS Bindra Stadium':'Punjab Cricket Association Stadium', 'Rajiv Gandhi International Stadium, Uppal':'Rajiv Gandhi International Stadium', 'Rajiv Gandhi Intl. Cricket Stadium':'Rajiv Gandhi International Stadium'},regex=True,inplace=True) Now here first we replace the name of id to match_id and then combined the data by their match_id Code Snippet : ipl_match.rename(columns={'id':'match_id'},inplace=True) combine_data = pd.merge(ipl_deliveries,ipl_match,on='match_id') pd.set_option('display.max_columns',None) combine_data.head(2) Now In this step, Gathered information about the bowler and then stored it into a dictionary. Code Snippet : bowler_performance={} for i in range(0, len(combine_data['bowler'])): try: total_balls = bowler_performance[combine_data['bowler'][i]][0] + 1 total_runs = bowler_performance[combine_data['bowler'][i]][1] + combine_data['total_runs'][i] total_wickets = bowler_performance[combine_data['bowler'][i]][2] wide_balls = bowler_performance[combine_data['bowler'][i]][3] no_balls = bowler_performance[combine_data['bowler'][i]][4] if(combine_data['wide_runs'][i] != 0): wide_balls = wide_balls + 1 if(combine_data['noball_runs'][i] != 0): no_balls = no_balls + 1 try: if(math.isnan(combine_data['dismissal_kind'][i])): bowler_performance[combine_data['bowler'][i]] = [total_balls, total_runs, total_wickets, wide_balls, no_balls] except: total_wickets = bowler_performance[combine_data['bowler'][i]][2] + 1 bowler_performance[combine_data['bowler'][i]] = [total_balls, total_runs, total_wickets, wide_balls, no_balls] except: try: if(math.isnan(combine_data['dismissal_kind'][i])): bowler_performance[combine_data['bowler'][i]] = [0, combine_data['total_runs'][i], 1, 0, 0 ] except: bowler_performance[combine_data['bowler'][i]] = [0, combine_data['total_runs'][i], 0, 0, 0 ] analysis_condition = [] analysis_condition.append(['Name', 'Total balls', 'Total runs', 'Total wickets','Wide balls', 'No balls']) for i in bowler_performance: analysis_condition.append([[i][0], bowler_performance[i][0], bowler_performance[i][1], bowler_performance[i][2], bowler_performance[i][3], bowler_performance[i][4]]) print(analysis_condition) Output : In this step we extract the information from the dictionary using a for loop and store it into a list after create a dataframe and store it all data from the list. Here To visualize the data defined a function to plot the bar plot Code Snippet : def bar_plot(data,x,y,titles): plt.figure(figsize=(20,10)) sns.barplot(x, y, data=data[:10]) plt.title(titles,size=20) plt.xticks(rotation=45,size=15) plt.yticks(size=15) plt.show() Calling the bar_plot function to visualize the top 10 Player names who take most wickets. In the Barplot we can see the SL malinga takes the most wickets in IPL session from 2008 to 2019 Code snippet : tw = bowler_data[:].sort_values(by='Total_wickets',ascending=False) bar_plot(tw,'Bowler_name','Total_wickets','Bowler Names vs Total Wickets') Call the defined function to visualize the top 10 Player names who have bowled most wide balls. In the Barplot we can see the SL malinga bowled the most wide ball in IPL session from 2008 to 2019 Code Snippet : twb=bowler_data[:].sort_values(by='Total_wide_balls',ascending=False) bar_plot(twb,'Bowler_name','Total_wide_balls','Bowler Names vs Total Wide Balls') Call the defined function to visualize the top 10 Player names who have bowled most No balls. In the Barplot we can see the S Sreesanth bowled the most No balls in IPL session from 2008 to 2019 Code snippet : tnb=bowler_data[:].sort_values(by='Total_No_balls',ascending=False) bar_plot(tnb,'Bowler_name','Total_No_balls','Bowler Names vs Total No Balls') Call the defined function to visualize the top 10 Player names Highest bowling average. In the Barplot we can see the K Goel is the number one position highest bowling average in IPL session from 2008 to 2019 Code snippet : tba=bowler_data[:].sort_values(by='Bowling_average',ascending=False) bar_plot(tba,'Bowler_name','Bowling_average','Bowler Names vs Bowling_average') Call the defined function to visualize the top 10 Player names Highest bowling strike rate. In the Barplot we can see the K Goel is the number one position highest bowling strike rate in IPL session from 2008 to 2019 Code snippet : tsr=bowler_data[:].sort_values(by='Strike_rate',ascending=False) bar_plot(tsr,'Bowler_name','Strike_rate','Bowler Names vs Top Strike Rate') Call the defined function to visualize the top 10 Player names Highest bowling Economy rate. In the Barplot we can see the K Goel is the number one position highest bowling Economy rate in IPL session from 2008 to 2019 Code snippet : ter=bowler_data[:].sort_values(by='Economy_rate',ascending=False) bar_plot(ter,'Bowler_name','Economy_rate','Bowler Names vs Top Economy Rate') We can see the graph most of the times Mumbai indians win the match in all IPL seasons and at the second and third position is chennai super kings and kolkata knight riders. Code snippet : plt.figure(figsize=(20,10)) ax = sns.countplot(x="winner", data=ipl_match) ax.set_title("Number of matches win",size = 15); plt.xticks(rotation=45,size=15); ax.set_xlabel('Teams',size = 15); ax.set_ylabel('Number of occurences',size = 15); plt.show() We can see in the graph that Virat kohli is in first position in making the highest runs. Code snippet : batsman_data = ipl_deliveries.groupby(['batsman']).sum().reset_index() best_batsman=batsman_data[:].sort_values(by='batsman_runs',ascending=False) bar_plot(best_batsman,'batsman','batsman_runs','Batsman Runs Vs Batsman Name') We can see in the graph that Chris Gayle is in first position for most of the time man of the match and at the second position is AB de Villiers. Code snippet : plt.figure(figsize=(20,10)) ax = sns.countplot(x="player_of_match", data=ipl_match ,order = ipl_match['player_of_match'].value_counts().index[:20:1]) ax.set_title("Top players Become man of the match",size = 15); plt.xticks(rotation=45,size=15); ax.set_xlabel('Teams',size = 15); ax.set_ylabel('Number of occurences',size = 15); plt.show() Thank You
- Real time gender recognition Using CNN
In this Article we will perform the Real time Gender Detection using CNN. Let's start. Gender is our identity. In our social life it is also a significant element. Artificial intelligence gender recognition can be used in many fields, such as smart human-machine interface growth , health, cosmetics, electronic commerce etc. Recognition of people's gender from their facial images is an ongoing and active problem of research. The researchers suggested a number of methods to resolve this problem, but the criteria and actual performance are still inadequate. A statistical pattern recognition approach for solving this problem is proposed in this project. Convolutional Neural Network (ConvNet / CNN), a Deep Learning algorithm, is used as an extractor of features in the proposed solution. CNN takes input images and assigns value to different aspects / objects (learnable weights and biases) of the image and can differentiate between them. ConvNet requires much less preprocessing than other classification algorithms. While the filters are hand-made in primitive methods, ConvNets can learn these filters / features with adequate training.In this research, face images of individuals have been trained with convolutionary neural networks, and age and sex with a high rate of success have been predicted. More than 20,000 images contain age, gender and ethnicity annotations. The images cover a wide range of poses, facial expression, lighting, occlusion, and resolution. Introduction The aim is to predict the gender of individuals using image data sets. A growing number of applications, especially after the increase in social networks and social media, are being concerned with automatic gender classification. Age and gender are the two most fundamental facial qualities in social interaction. In smart applications, such as access control, human computer interaction, enforcement, marketing intelligence and visual supervision, etc, it is important to recognize gender using one facial image. In machine learning there are many algorithms that are the most common technologies used in this project. Convolutional Neural Network (CNN) is one of the most prevalent algorithms that has gained a high reputation in image feature extraction. Methodology Architecture Gender recognition using Convolutional neural network : A Convolutional Neural Network (ConvNet / CNN) is a Deep Learning algorithm, which allows an input image to take on different aspects/objects and can be distinguished from one image (learnable weights and biases). ConvNet requires much less preprocessing than other classification algorithms. While the filters are hand-made in primitive methods, ConvNets can learn these filters / features with adequate training. The ConvNet architecture is similar to that of neurons in the human brain and was influenced by the Visual Cortex organization. Within a limited area of the visual field known as the Receptive Field, only individual neurons respond to stimuli. The entire visual area is protected by a selection of these fields. About Dataset The data collection consists of more than 20,000 facial images with age, gender and ethnicity annotations. The images cover a wide range of poses, facial expression, lighting, occlusion, resolution .It can be used for a variety of tasks, for example face detection, age estimation, gender recognition, position of landmarks etc. The survey is focused on the age detection of the neural network (CNN) image dataset architecture. We need to split our dataset into three parts: training dataset, test dataset and validation dataset. The purpose of splitting data is to avoid overfitting which is paying attention to minor details/noise which is not necessary and only optimizes the training dataset accuracy. We need a model that performs well on a dataset that it has never seen (test data), which is called generalization. The training set is the actual subset of the dataset that we use to train the model. The model observes and learns from this data and then optimizes its parameters. The validation dataset is used to select hyperparameters (learning rate, regularization parameters). When the model is performing well enough on our validation dataset, we can stop learning using a training dataset. The test set is the remaining subset of data used to provide an unbiased evaluation of a final model fit on the training dataset. Description of Library used Numpy : Numpy is the most basic yet a powerful package for mathematical and scientific computing and data manipulation in python. It is an open source library available in python. Cv2: OpenCV is a high performance library for digital image processing and computer vision, which is free and open source. Matplotlib : Matplotlib is a plotting library for the python programming language and its numerical mathematics extensions in numpy. OS : The OS module in python provides a way of using operating system dependent functionality KERAS : Keras is an open-source high-level neural network API, written in python. It allows easy and fast prototyping Technology Image Processing : Image processing is a method to perform some operations on an image, in order to get an enhanced image or to extract some useful information from it. It is a type of signal processing in which input is an image and output may be image or characteristics/features associated with that image. Computer Vision : Computer vision is a field of artificial intelligence that trains computers to interpret and understand the visual world. Using digital images from cameras and videos and deep learning models, machines can accurately identify and classify objects. Tools Used Anaconda Navigator : Anaconda is a free and open-source distribution of the Python and R programming languages for scientific computing (data science, machine learning applications, large-scale data processing, predictive analytics, etc.), that aims to simplify package management and deployment. Jupyter Notebook IDE: Jupyter Notebook is an open source web-based application which allows you to create and share documents containing live code, equations, visualizations, and narrative text. The IDE also includes data cleaning and transformation, numerical simulation, statistical modelling, data visualization, and many others. Import libraries #import libraries import cv2,os import numpy as np from keras.utils import np_utils from keras.models import Sequential from keras.layers import Dense, Activation, Dropout, Conv2D, Flatten, MaxPooling2D from keras.callbacks import ModelCheckpoint from sklearn.model_selection import train_test_split from matplotlib import pyplot as plt from keras.models import load_model from random import shuffle from scipy import misc import imageio from keras.utils.np_utils import to_categorical Procedure First we are changing the current directory to the path where our image dataset is stored by using os.chdir( ) and then we get the list of all the files and directories in the specified path using os.listdir( ). #use the file path where your dataset is stored data_path = 'UTKFace' img_files = os.listdir(data_path) len(img_files) Shuffle( ) is used to randomize all the image files. shuffle(img_files) gender = [i.split('_')[1] for i in img_files] Using split( ) we get the gender of each image file and then store it into a list. target = [] for i in gender: i = int(i) target.append(i) Using cv2.imread( ) and cv2.resize( ), we read an image from each file as an array and resize its dimensions to 32x32 and then store it in a list named data. data=[] img_size=32 for img_name in img_files: img_path = os.path.join(data_path,img_name) img = cv2.imread(img_path) try: gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) resized = cv2.resize(gray,(img_size,img_size)) data.append(resized) except Exception as e: print("Exception: ",e) Next we normalize the data by converting the datatype of variable data to float32 and dividing it by 255. Convert the class vector(integers) to a binary class matrix using to_categorical() before training our model. #data values are normalized data = np.array(data)/255.0 # Reshaping of data data = np.reshape(data,(data.shape[0],img_size,img_size,1)) new_target = to_categorical(target, num_classes=2) # saving the file np.save('target',new_target) np.save('data',data) There are two ways to build keras models : sequential and functional. In our project we are using sequential by which we create a model layer-by-layer. When we use Conv2D as the first layer we must define the input shape. This layer creates a convolution kernel that is convolved with the layer input to produce a tensor of outputs. Activation is used for “relu” The MaxPooling2D layer is used for spatial data. Dropout layer is used to prevent a model from overfitting. Dense layer is a linear operation in which every input is connected to every output by a weight. # build Convolutional neural network leyar model = Sequential() model.add(Conv2D(100,(3,3),input_shape=data.shape[1:])) model.add(Activation('relu')) model.add(MaxPooling2D(pool_size=(1,1))) model.add(Conv2D(100,(2,2))) model.add(Activation('relu')) model.add(MaxPooling2D(pool_size=(1,1))) model.add(Conv2D(100,(2,2))) model.add(Activation('relu')) model.add(MaxPooling2D(pool_size=(2,2))) model.add(Conv2D(400,(2,2))) model.add(Activation('relu')) model.add(MaxPooling2D(pool_size=(1,1))) model.add(Flatten()) model.add(Dropout(0.3)) model.add(Dense(50,activation='relu')) model.add(Dense(2,activation='softmax')) Next we compile and fit the model. We summarize the model by using model.summary( ). Total params: 3,621,752, trainable params: 3,621,752 and Non-trainable params: 0. The total length of the dataset is 23708, out of which 90% is used for training, 10% for testing and 20% for validating the data. #Split the data train_data, test_data, train_target, test_target = train_test_split(data, target, test_size=0.1) We then evaluate the model on a test set to get the accuracy up to 0.88. Now the model is trained and it's ready to recognize the gender of any random image from a dataset. We plot a random sample of 15 test images, their predicted labels and ground truth. We get the output by displaying each image along with its title. In this project, Keras is used. Keras is an open-source neural network library. It is user friendly and provides several features such as activation.functions, layers, optimizers, etc. and it supports CNN . By using the appropriate class in Keras, deep learning models can be created on iOS and Android through the JVM (Java Virtual Machine). Keras enables the model to perform random transformations and normalization operations on batches of image data by working on different attributes such as height shift, width shift, rotation range, rescale, range of shear, range of zoom, horizontal rip and fill mode. Using these attributes the system can automatically rotate, translate, rescale, and zoom into or out of images, as well as apply shearing transformations, rip images horizontally, fill in newly created pixels, etc. For the purpose of image classification, ConvNet is used. Training Dataset : The training dataset is used as a set of examples used for training the model, i.e. to fit the different parameters. Validation Dataset : A validation dataset is used to fit the hyper-parameters of the classifier. A validation dataset is necessary because it helps in the reduction of overfitting. The validation dataset is independent of the training dataset. Test Dataset : The test dataset is used to test the performance of the classifier or model and to check the performance of characteristics such as accuracy, loss, sensitivity, etc. It is independent of the training and validation dataset. Real time Gender Recognition Steps to follow : Face detection with Haar cascade Gender Recognition with CNN 1. Face detection with Haar cascades : This is a part most of us at least have heard of. OpenCV/JavaCV provide direct methods to import Haarcascades and use them to detect faces. 2. Gender Recognition with CNN : CNN algorithm is used for Gender recognition. The CNN’s output layer (probability layer) in this CNN consists of two classes ‘Male’ and ‘Female’. img_size=32 #load the best model model = load_model('model-10.model') faceCascade=cv2.CascadeClassifier('haarcascade_frontalface_default.xml') #starts the webcam cap = cv2.VideoCapture('vp_debate.mp4') ## Label and Color labels_dict = {0:'Male',1:'Female'} color_dict = { 0:(0,0,255),1:(0,255,0)} while 1: ret,frame = cap.read() gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY) faces = faceCascade.detectMultiScale(gray,1.3,5) for x,y,w,h in faces: face_img = gray[y:y+w,x:x+h] resized = cv2.resize(face_img,(img_size,img_size)) normalized = resized/255.0 reshaped = np.reshape(normalized,(1,img_size,img_size,1)) result = model.predict(reshaped) label = np.argmax(result,axis=1)[0] cv2.rectangle(frame,(x,y),(x+w,y+h),color_dict[label],2) cv2.putText(frame,labels_dict[label],(x,y-10),cv2.FONT_HERSHEY_SIMPLEX,0.8,(255,255,255),2) cv2.imshow('Video',frame) key=cv2.waitKey(1) cap.release() cv2.destroyAllWindows() Conclusion we proposed a model to Classify the gender by feeding the CNN image dataset, a deep learning algorithm and trained in broad database face-recognition. In all, we think that the accuracy of the model is decent. but can be further improved by using more data, data increase and better network architecture.
- REINFORCEMENT LEARNING AND Q LEARNING
In this blog we will discuss the Q learning type of reinforcement learning. Let's Start. What is Reinforcement learning ? Have you ever seen a dog trainer giving some food to the dog for every successful task? The food is a reward to the brain saying well done you are going in the right direction. Our brains crave rewards. Something that gives happiness and our brain tries to do those things again and again that gives it more and more reward. Similarly, We can replicate this technique used to train our robots or models. This autonomous learning is called reinforcement learning or Q learning algorithm. Using Q learning reinforcement learning algorithm agents tries to figure out the quality of its action based on the rewards it receives. So that it can decide which action to perform in sequence to get maximum reward in the long term. In reinforcement learning there are five main element Reinforcement Q learning Elements Agent Environment Reward State Action Agent : In reinforcement Q learning Agent is the one who takes decisions on the rewards and punishment. Environment : The Environment is a task or simulation and the agent is an AI algorithm that interacts with the environment and tries to solve it. Reward : A reward in RL is part of the feedback from the environment. When an agent interacts with the environment, he can observe the changes in the state and reward signals through his actions, if there is change. He can then use this reward signal (can be positive for a good action or negative for a bad action) to draw conclusions about how to behave in a state. The goal, in general, is to solve a given task with the maximum reward possible. That is why many algorithms have a very small negative reward for each action the agent takes to animate him to solve the task as fast as possible. State : State Describe the current situations. Actions : a set of actions which the agent can perform. Introduction of Q Learning In Q learning involves an AI agent operating in an environment with states & rewards(inputs) and Action(outputs). Q learning involves model free environments. The AI agent is not seeking to learn about an underlying mathematical problem or probability distribution. Instead, the AI agent attempts to construct an optimal policy directly by interacting with the environment. Q learning uses a trial and error based approach. The AI agent repeatedly tries to solve the problems using varied approaches and continuously updates policy as it learns more and more about its environment. The characteristics of the Q learning model are input and output systems, rewards, an environment, Markov decision processes, and training and inference. Additional two characteristics are the number of possible states is limited. The AI agent is always with one fixed number of possible situations. The second is that an AI agent always needs to choose from among a fixed number of possible actions. What are Q values and Q table policy in Q learning ? In Q learning Q stands for quality. Quality in this case represents how useful a given action is in gaining some future reward. Quality of particular action in a given state. Q(state, action) Q value determines how much additional reward we can accumulate through all remaining steps in the current episode if the AI agent is in state and takes action. Q value increases as the AI agent gets close to the highest reward. Q Table Q values are stored in a table which is known as Q table. Which has one row for each possible state and one column for each possible action. An optimal Q table contains values that allow the AI agent to take the best action in any possible state. Thus providing the agent with the optimal path to the highest reward. Q table represents the AI agent policy for acting in the current environment. Temporal Difference Temporal difference (TD) provides us with a method of determining how the Q value for the action taken in the previous state should be changed based on what the AI agent has learned about the Q value for the current state's actions. Where, Temporal difference for the action taken in the previous state. Our AI agent will be able to benefit from this information whenever it finds itself in that state again in future. The reward received for the action taken in the previous state. Temporal difference includes the reward that was received for the action that was taken in the previous state. This is referring to immediate reward that is different from the Q value. Which represents our current calculated sum of all future rewards if we were to take a particular action in a particular state. γ (gamma) is the discount factor Between 0 and 1 (0≤γ≤1) - determines how much importance we want to give to future rewards. A high value for the discount factor (close to 1) captures the long-term effective award, whereas, a discount factor of 0 makes our agent consider only immediate reward, hence making it greedy. max Q (st+1,a) : The largest Q value available for any action in the current state ( The largest predicted sum of future rewards ). We are calculating this temporal difference value in order to figure out by how much we should adjust the Q value for the previous action. Also Q value for the current state represents our best calculation of the sum of all the future rewards for each possible action that we might take in the current state. Q(st,at): The Q value for the action taken in the previous state. We subtract the Q value for the AI agent's most recent action yielding the temporal difference value for the most recent action. Bellman Equation Bellman equation shows the new value to use as the Q value for the action taken in the previous state. Relies on the both old Q value for the action taken in the previous state and what has been learned after moving to the next state. It include learning rate It defines how quickly Q values are adjusted. Where, The new Q value for the action taken in the previous state. This new Q value for the most recently taken action is the sum of the previous Q value for that action. This is the old Q value for the action taken in the previous state. α (alpha) is the learning rate (0 ≤ α ≤ 1) Just like in supervised learning settings, α is the extent to which our Q-values are being updated in every iteration. Q-Learning Algorithms How Q learning Works? OR Q-learning algorithm process. Step 1. Initialize Q Table The process begins by the initialization of the Q table. Q table represents the AI agent's policy for how to behave in an environment any value can be used to initialize the Q table. Example of Q table Initializations Step 2 : Choose Action We choose an action from the Q table for the current state. AI agents might choose the highest Q value. Common strategy for this is to use an epsilon greedy algorithm. In the epsilon greedy algorithm the AI agent will usually choose the action with the highest Q value 90% of the time. But we will choose an action at random for the remaining 10 % of the time. Step 3 : Perform Action After the AI agent has chosen which action to take. We take that action and transition to the next state. Step 4 : Receive reward We then receive our reward for taking the most recent action and we use that reward in conjunction with the knowledge that we have learned about our new state to compute the temporal difference value for our previous action. Step 5 : Update Q table We use the temporal difference value and bellman equation to update the Q value for our most recent action. We then loop back to the beginning by once again choosing an action for the current state; the process continues until we reach a terminal state such as the target location.
- NLP Assignment I Sample Assignment
PART-1 The Training data is in the form or a list of dictionaries (jsonl format). Each element in the list is a distinct article that has an associated summary. The format of each element of the list is shown below: {'url': 'http://fortune.com/2014/10/14/luxury-spending-bain/', 'archive': 'http://web.archive.org/web/20141015014008id_/http://fortune.com/2014/10/1 4/luxury-spending-bain/', 'title': 'U.S., with help from Chinese tourists, boosts global luxury spending', 'date': '20141015014008', 'text': 'Despite a crackdown on graft in China, Russia’s conflict with the West over Ukraine and Europe’s sick-man economy, global luxury spending is still on track to rise 5% in 2014, according to a report released on Tuesday by consulting firm Bain & Co.\n\nBain, whose projections are closely watched by the luxury industry, also stuck to its forecast that global luxury goods sales will rise between 4% and 6% a year between 2014 and 2017.\n\nSo with all the insanity going on in the world right now, what is giving luxury a much needed boost? The good ol’ U.S. of A., which has become a bigger destination for rich Chinese travelers (now that getting a visa is easier), and where millennials are developing a taste for luxury as they progress in their careers and start to make more money, said Claudia D’Arpizio, a Bain partner in Milan and leader of the firm’s Global Luxury Goods and Fashion Practice.\n\n“The U.S. is becoming a more and more important tourist destination for Chinese travelers,” D’Arpizio told Fortune. Chinese nationals spend three times more on luxury abroad than they do at home.\n\nIndeed, Nordstrom JWN , Neiman Marcus and Saks Fifth Avenue are all opening new Manhattan stores in the coming years to tap luxury’s ongoing explosion in the U.S., fueled by tourism.\n\nU.S. consumer confidence hit 14 month highs in September, and high end shopping has been on a tear this year. The stock market has fallen sharply in the last week, casting a shadow on consumer spending, but the downturn would need to last for a while to hit luxury, D’Arpizio said. “We see consumer confidence that is the most important driver.”\n\nThe uptick in the U.S. comes at an opportune time for global luxury companies. In July, French luxury group LVMH reported disappointing first-half results for 2012 while rival Kering, whose brands include Gucci, spoke of an “unsettled business environment.” Meanwhile, L’Oreal said the U.S. rebound would help its second-half results.\n\nBain, which conducted the study with Italian luxury industry group Altagamma, said the global luxury market is on target to reach 223 billion € ($283 bilion) in 2014, which represents a 5% bump this year, a slower rate than the 7% last year.\n\nAnd there undoubtedly clouds in the luxury sky: Chinese sales have been hurt by a crackdown by the government against corruption and conspicuous consumption. And Russian luxury sales are down hurt by a drop in tourism to Eastern European countries.', 'summary': 'What China, Russian slowdown? Luxury sales keep face with forecast, Bain says.', 'compression': 30.5625, 'coverage': 0.75, 'density': 1.0, 'compression_bin': 'medium', 'coverage_bin': 'low', 'density_bin': 'abstractive'} For the purposes of this exercise, you can ignore all keys other than the title, text and summary. The task is to build multiple models using any deep learning tools that can output summaries for any text article (title and text). You must evaluate the models and choose your "winning" model. PART-2 The NCBI disease corpus is fully annotated at the mention and concept level to serve as a research resource for the biomedical natural language processing community. Corpus Characteristics ● 793 PubMed abstracts ● 6,892 disease mentions ● 790 unique disease concepts ○ Medical Subject Headings (MeSH®) ○ Online Mendelian Inheritance in Man (OMIM®) ● 91% of the mentions map to a single disease concept ● divided into training, developing, and testing sets. Corpus Annotation ● Fourteen annotators ● Two annotators per document (randomly paired) ● Three annotation phases ● Checked for corpus-wide consistency of annotations The ask is to build a model to predict various Named Entities within the unlabelled text. For Solution of this assignment or any such assignments contact codersarts Codersarts is a top-rated website for students which is looking for online Programming Assignment Help, Homework Help, Coursework Help in C, C++, Java, Python, Database, Data structure, Algorithms, Final year project, Android, Web, C sharp, ASP NET to students at all levels whether it is school, college and university level Coursework Help or Real-time project. Hire us and Get your projects done by a computer science expert. Contact Codersarts for any such project/assignment help
- Digital Image Processing
In this article we will discuss Digital Image Processing. Let's begin from the basics. What is an image ? Basic definition of image is visual representation of something or someone. Example of any drawing, painting and photograph etc. It may be black and white or color. orignal image In other words, a digital image is a collection of pixels or an array or picture element (picture element) arranged in columns and rows. Image is defined in two dimensional function f(x,y) where x and y are spatial planes (co-ordinate) and the amplitude of f at any pair of coordinates (x, y) is called the intensity or gray level of image at the point. Digital image is composed of a finite number of elements each of which has a particular location and value. These elements are called picture elements, image elements and pixels. Types of images Binary image : Binary image contains only two pixels o and 1 hence it is known as binary image. 0 refers to black color and 1 refers to white color. It is also known as monochrome. Black and white image : This image contains only two colors black and white. Hence it is known as black and white image. Black and white images and binary images are the same. Format Binary image have a portable bitmap 8 bit color format : In 8 color format there are 256 different color shades. It is known as a grayscale image. The range of the colors in 8 bit varies from 0-255. Where 0 stands for black, and 255 stands for white, and 127 stands for gray color. grayscale image 16 bit color format It is a color format and contains 65,536 colors. It is also known as high color format. A 1 bit color format is divided into three color formats which are red, green and blue (RGB format). Code Snippet : #import libraries import cv2 #read image orignal_image = cv2.imread('pexels-simon-migaj-747964.jpg') #convert orignal image into grayscale image gray_Image = cv2.cvtColor(orignal_image, cv2.COLOR_BGR2GRAY) #convert orignal image into Black and white image (thresh, black_and_white) = cv2.threshold(grayImage, 127, 255, cv2.THRESH_BINARY) #save image cv2.imwrite('Blackandwhite.png', black_and_white) cv2.imwrite('grayscaleimage.png', gray_Image) #Display image cv2.imshow('Black white image', black_and_white) cv2.imshow('Original image',orignal_image) cv2.imshow('Gray image', gray_Image) cv2.waitKey(0) cv2.destroyAllWindows() How computer read the image A computer object in an image appears as an array of square blocks known as pixels assigned with the numerical values which indicate the intensity of the pixel. For a grayscale or a balck and white image each pixel have one value which ranges between to 255 but for color images each pixel have 3 values because the color image consists of 3 channels each representing red, green and blue color. pixel of image There are generally two types of image vector image and bitmap image. Bitmap image : Bitmap images are stored as a series of tiny dots which are called pixels. Vector image : Vector images are not based on the pixel pattern it is mainly based on the geometrical and mathematical formula. Some of most common files format of image Gif : Gif stands for Graphical interchange format. It is mostly used for the web. It is an 8 bit color format. It is a bitmap image. JPEG : JPEG stands for Joint photographic Expert Group. It is a 16 bit color format. It is a standard image format for containing lossy and compressed image data. PNG : PNG stands for Portable network graphics. It supports upto 16 bit channels. It uses lossless compressed data. The RGB Color model A color model is a specification of a coordinate system and a subspace within that system where its color is represented by a single point. The color subspace of interest is the cube shown in Figure What is Image Processing Image processing is a technique of applying a relevant mathematical operation or an algorithm on a digitized image to generate an enhanced image or extract some useful information like shape, color and edge. The image processing generally includes three steps. The first step is to import the image by using the scanner or by digital photography. Second step is to analyze and manipulate the image which includes data compression, Image enhancement and spotting pattern. Output is the last stage in which the result can be altered. The purpose of image processing and various image processing operations that are widely used for example image segmentation, object detection, image enhancement, image restoration, color image processing, morphological operations etc. Methods used for image processing operation Image enhancement Image enhancement is a technique of adjusting digital images so that the images are more suitable for display. For example If the image is overexposed and it needs the reduction in brightness then simply by subtracting a constant number from the pixel intensity value can reduce the brightness of the image to make it more realistic. Code Snippet #import libraries import cv2 import numpy as np # read image image = cv2.imread('pexels-simon-migaj-747964.jpg') image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) #number of increase brightness increase = 70 v = image[:, :, 2] v = np.where(v <= 255 - increase, v + increase, 255) image[:, :, 2] = v image = cv2.cvtColor(image, cv2.COLOR_HSV2BGR) #save image cv2.imwrite('increase_brightness.jpg',image) Image Segmentation Image segmentation is a process of partitioning a digital image into multiple regions and extracting the meaningful region which is known as Region of interest. For example we have an image where there is an image of cat, dog, bird, car etc. various objects are available in that particular image. Segregation of image cat, dog, bird and car. It means image segmentation is something which is about partitioning the image. Code Snippet #import libraries import pixellib from pixellib.semantic import semantic_segmentation image_segment = semantic_segmentation() #load the model image_segment.load_pascalvoc_model("data.h5") #save image image_segment.segmentAsPascalvoc('cat.jpg', output_image_name = "output_sementic_image.jpg") Object detection Object detection is the term to describe a collection of data and identify the object in digital images captured by the cameras which are mounted on cars and this is done by using convolutional neural networks. convolutional neural networks have been successful image classifications in real world applications. Image Restoration Image restoration is the technique of taking a corrupt or noisy image to make it a clean image. Corruption image means it may be blur, noisy or camera mis-focus etc. It is performed by reversing the process that blurred the image and such is performed by imaging a point source and using the point source image, which is called the Point Spread Function (PSF) to restore the image information lost to the blurring process. Image restoration is different from image enhancement. Morphological operations Morphological image processing is a collection of non-linear operations related to the shape or morphology of features in an image. Morphology is generally concerned with the shape and properties of objects. There are two basic morphological operations, Dilation and Erosion. Dilation : Add pixels to the boundaries of objects in an image. It expands the connected sets of the first binary image. It can be used for expanding shape and filling the holes, gaps and gulf. Erosion : Remove pixels on object boundaries. It removes the isolated noisy pixels and removes the outer layer of object pixels i.e object become slightly smaller. It is used for smoothies object boundaries. Morphological techniques probe an image with a small shape or template called a structuring element. Structuring element The number of pixels added or removed from the object in an image depends on the size and shape of the structuring element used to process the image.
- Image Classification, Object Detection: I Sample Project
1. Fruits 360 dataset: Dataset details: https://github.com/Horea94/Fruit-Images-Dataset (Links to an external site.)or https://www.kaggle.com/moltean/fruits (Links to an external site.) Download Link: Can be download from the above links, either from GitHub or the Kaggle competition page. Additional information: As there is no validation set for this dataset, please split the test dataset into two parts, 60% for testing and 40% validation. The Multi-fruit (103 images) set is not required for your experiment, please don't use it. 2. Multi-Class weather dataset: Description and link: https://data.mendeley.com/datasets/4drtyfjtfy/1 Object Detection Task: Object Detection (Choose any one dataset) 1. Synthetic Fruit Dataset: https://public.roboflow.com/object-detection/synthetic-fruit (Links to an external site.) Note: While downloading the dataset, export the annotations in Pascal VOC XML format, or a format required by the object detection framework. 2. PKLot Dataset: https://public.roboflow.com/object-detection/pklot (Links to an external site.) Note: While downloading the dataset, export the annotations in Pascal VOC XML format, or a format required by the object detection framework. Acknowledge the source of the dataset: PKLot Paper (Links to an external site.) in your report. 3. Red Blood Cell Detection and Counting: BloodRBC-Detection-Dataset-Processed.zip download 4. Hard Hat Workers Dataset: https://public.roboflow.com/object-detection/hard-hat-workers (Links to an external site.) Note: While downloading the dataset, export the annotations in Pascal VOC XML format, or a format required by the object detection framework. For Solution of this assignment or any such assignments contact codersarts Codersarts is a top-rated website for students which is looking for online Programming Assignment Help, Homework Help, Coursework Help in C, C++, Java, Python, Database, Data structure, Algorithms, Final year project, Android, Web, C sharp, ASP NET to students at all levels whether it is school, college and university level Coursework Help or Real-time project. Hire us and Get your projects done by a computer science expert. Contact Codersarts for any such project/assignment help
- Real time Face Mask Detection
Objective To identify the person on a real time camera wearing a face mask or not with the help of Convolutional neural network by using the keras library. Introduction COVID-19 virus has affected the whole world very badly and It has a huge impact on our everyday life. One major protection method for the people is to wear masks in public areas. Doctors recommend that wearing masks is made to play a big role to stop the spread of the virus even if vaccines are available. Which will help to control the spreading of the virus. In crowded areas manually Detection of face masks is an extremely challenging task for the present. Hence we are going to build a model which helps to identify the person whether the person is wearing a mask or not. This model is very helpful to identify the person who is not wearing a mask in crowded areas like malls, bus stands, and other public places. Methodology Dataset : The dataset which we have used consists of 1376 total images out of which 690 are of masked faces and 686 are of unmasked faces. Most of them are artificially created. Which does not represent the real world accurately. From all the three sources, the proportion of the images is equal. The proportion of masked to unmasked faces determine that the dataset is balanced. We need to split our dataset into three parts: training dataset, test dataset and validation dataset. The purpose of splitting data is to avoid overfitting which is paying attention to minor details/noise which is not necessary and only optimizes the training dataset accuracy. We need a model that performs well on a dataset that it has never seen (test data), which is called generalization. The training set is the actual subset of the dataset that we use to train the model. The model observes and learns from this data and then optimizes its parameters. The validation dataset is used to select hyperparameters (learning rate, regularization parameters). When the model is performing well enough on our validation dataset, we can stop learning using a training dataset. The test set is the remaining subset of data used to provide an unbiased evaluation of a final model fit on the training dataset. Architecture : CNN architecture is inspired by the organization and functionality of the visual cortex and designed to mimic the connectivity pattern of neurons within the human brain.The neurons within a CNN are split into a three-dimensional structure, with each set of neurons analyzing a small region or feature of the image. In other words, each group of neurons specializes in identifying one part of the image. CNNs use the predictions from the layers to produce a final output that presents a vector of probability scores to represent the likelihood that a specific feature belongs to a certain class. The architecture of a CNN is a key factor in determining its performance and efficiency. The way in which the layers are structured, which elements are used in each layer and how they are designed will often affect the speed and accuracy with which it can perform various tasks. Build a CNN model : Import some important libraries for building the CNN mode. Code snippet: import cv2,os import numpy as np from keras.utils import np_utils from keras.models import Sequential from keras.layers import Dense, Activation, Dropout, Conv2D, Flatten, MaxPooling2D from keras.callbacks import ModelCheckpoint from sklearn.model_selection import train_test_split from matplotlib import pyplot as plt from keras.models import load_model The dataset consists of 1376 images. With masks and without masks. Provide the data path for reading the dataset. Categorized the data with mask and without mask with their name and Make a list for store data and target. Store all the images in the ‘data’ list and label of images stored in ‘target’ list. Code Snippet : #use the file path where your dataset is stored file_loc = 'dataset' categories = os.listdir(file_loc) labels = [i for i in range(len(categories))] label_dict = dict(zip(categories,labels)) print(label_dict) print(categories) print(labels) img_size = 32 data = [] target = [] for category in categories: folder_path = os.path.join(file_loc,category) img_names = os.listdir(folder_path) for img_name in img_names: img_path = os.path.join(folder_path,img_name) img = cv2.imread(img_path) try: gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) resized = cv2.resize(gray,(img_size,img_size)) data.append(resized) target.append(label_dict[category]) except Exception as e: print("Exception: ",e) Output : Now the list which is formed data and target converts it into a numpy array for the data processing. Change the shape of the data array so that it can be given to neural network architecture as an input and save the npy file. Code snippet : #data values are normalized data = np.array(data)/255.0 #reshaping of data data = np.reshape(data,(data.shape[0],img_size,img_size,1)) target = np.array(target) new_target = np_utils.to_categorical(target) #saving the files np.save('data',data) np.save('target',new_target) In this step we will load the data from the file that we created in the previous step. After that we are building the Convolutional Network Model using the Convolutional and Max Pooling layers. Code snippet : # Data load data = np.load('data.npy') target = np.load('target.npy') # build Convolutional neural network leyar model = Sequential() model.add(Conv2D(100,(3,3),input_shape=data.shape[1:])) model.add(Activation('relu')) model.add(MaxPooling2D(pool_size=(2,2))) model.add(Conv2D(100,(3,3))) model.add(Activation('relu')) model.add(MaxPooling2D(pool_size=(1,1))) model.add(Conv2D(100,(3,3))) model.add(Activation('relu')) model.add(MaxPooling2D(pool_size=(1,1))) model.add(Conv2D(100,(3,3))) model.add(Activation('relu')) model.add(MaxPooling2D(pool_size=(1,1))) model.add(Conv2D(100,(3,3))) model.add(Activation('relu')) model.add(MaxPooling2D(pool_size=(2,2))) model.add(Conv2D(400,(3,3))) model.add(Activation('relu')) model.add(MaxPooling2D(pool_size=(1,1))) model.add(Flatten()) model.add(Dropout(0.5)) model.add(Dense(50,activation='relu')) model.add(Dense(2,activation='softmax')) # Compile Data model.compile(optimizer='adam', loss='categorical_crossentropy', metrics = ['acc']) At last, the output is flattened and fed into a fully connected dense layer with 50 neurons and a final layer with 2 neurons. It will predict based on probabilities for a person wearing a mask or not. Split the data and target and fit into the model. The data and target are split into training and testing data. Keeps 10 % of data as testing and 90% as training data. Code snippet : # Split Data train_data, test_data, train_target, test_target = train_test_split(data, target, test_size=0.1) Create a checkpoint, which will save the model, which will have the minimum validation loss. Then the training data is then fitted in the model so that predictions can be made in the future. Code snippet : # Create Checkpoints and model fit checkpoint=ModelCheckpoint('model-{epoch:03d}.model', monitor='val_loss', verbose = 0, save_best_only = True,mode='auto') history = model.fit(train_data,train_target,epochs = 20, callbacks = [checkpoint], validation_split = 0.2) After fitting the model, plot the accuracy and loss chart for training and validation data. Now evaluate the model on test data. We can see that the model is about 94% accurate on testing data with 0.26 loss. Output : Using the model in real time through a webcam. Load the best model through a call back. Now we will use the HaarCascade Classifier to find the face in each frame of the video. Make a label and color dictionary for two different classes. i.e Fask and No Mask. Code snippet : img_size=32 #load the best model model = load_model('model-018.model') faceCascade=cv2.CascadeClassifier('haarcascade_frontalface_default.xml') #starts the webcam video_capture = cv2.VideoCapture(0) labels_dict = {0:'NO MASK',1:'MASK'} color_dict = { 0:(0,0,255),1:(0,255,0)} In an infinite loop, capture each frame from the video stream and convert it into grayscale for better processing and apply the cascade to find the ROI, in our case- faces . Resize and normalize each ROI image and give it to the model for prediction. Through this you will get the probability for both mask and no mask. The one with higher probability is selected. A frame is drawn around the face, which also indicates whether a person has worn a mask or not. To close the webcam, press the Esc button. Code snippet : while(True): ret,frame = video_capture.read() gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY) faces = faceCascade.detectMultiScale(gray,1.3,5) for x,y,w,h in faces: face_img = gray[y:y+w,x:x+h] resized = cv2.resize(face_img,(img_size,img_size)) normalized = resized/255.0 reshaped = np.reshape(normalized,(1,img_size,img_size,1)) result = model.predict(reshaped) label = np.argmax(result,axis=1)[0] cv2.rectangle(frame,(x,y),(x+w,y+h),color_dict[label],2) cv2.putText(frame,labels_dict[label],(x,y-10),cv2.FONT_HERSHEY_SIMPLEX,0.8,(255,255,255),2) cv2.imshow('Video',frame) key=cv2.waitKey(1) if(key==27): break; cv2.destroyAllWindows() video_capture.release() The model has now been fully prepared and is ready to identify the person on a real time camera wearing a face mask or not with the help of Convolutional neural network
- Random Search Optimisation and Meta-Learning I Sample Assignment
Task Students will use one or more strategies such as (1) Random Search, (2) Meta-Learning, (3) Adaptive Boosting, or (4) Cascade Correlation to optimize the structure and parameters of Artificial Neural Networks (ANNs) on a given benchmark problem. Such optimization is required to maximize the recognition accuracy of ANNs designed for solving biometric tasks. In practice, the optimal structure and parameters of ANNs are difficult to find because of the need for multiple experiments with the different numbers of principal components, hidden neurons, learning rates, and types of gradient algorithms. COVID related alternatives There are alternatives that students can find interesting within the unit scope. Method and Technology Students will attempt to optimize ANNs which were manually designed in Assignment 1. To achieve the goal, students will apply one or more optimization strategies with different parameters. The examples of Random Search, Meta-Learning, Adaptive Boosting as well as MATLAB search strategies are provided in the unit tutorials. Advanced students can use Python, MATLAB, or R to optimize Deep Learning, Convolutional Networks, and/or Conventional ANNs. AI and ML technologies are developing in many ways and so the rigorous definitions are still developing. This means that: (i) existing textbooks are outdated and so cannot offer efficient strategies demanded by industry and academy, and (ii) textbooks nowadays are not interactive as online tutorials provided, for example, by Google Colab. The above-listed four strategies are new cutting-edge ways to the optimization task, supported with many tutorials available online. Example of Optimisation Solution An example of an ANN optimization in MATLAB is presented by a conference paper published by the Computer Science students in Springer proceedings. Other solutions will be discussed. For Solution of this assignment or any such assignments contact codersarts Codersarts is a top-rated website for students which is looking for online Programming Assignment Help, Homework Help, Coursework Help in C, C++, Java, Python, Database, Data structure, Algorithms, Final year project, Android, Web, C sharp, ASP NET to students at all levels whether it is school, college and university level Coursework Help or Real-time project. Hire us and Get your projects done by a computer science expert. Contact Codersarts for any such project/assignment help
- Master Thesis Project I Sample Project
You are given the attached CSV file for the purpose of quantifying the behavior of Drosophila Larvae using unsupervised machine learning. The data is taken from an experiment, where multiple larvae are allowed to freely explore some space, guided by an odor. Each row of the dataset captures some behavioral parameters of one individual. The column frame describes the real (physical) time of the experiment, the column id describes the id of the individual. This follows with some behavioral parameters for this larvae id and this physical time step. Example: frame id parameterA Notable parametersthat we want to focus on are the spinepoint_x_n and spinepoint_y_n columns, which depict (x,y) coordinates fitted to the spine of each larvae. Plotting the spine points creates the following picture: Now carry out the following analysis of the dataset. Document everything in a python file or an ipython notebook that you can later share with us. 1. The spine point data containssome NaN (not a number) valuesin the spinepoint_x_n and spinepoint_y_n columns, that are marked as nan in the CSV data. Carry out linear interpolation for any NaN values, using the values before and after the NaN rows. This can be done with the interp command from the numpy pack- age. 2. Now, let us fit a polynomial function with a degree of 4 to the (x,y) spine point data. This can be done with the polyfit function from numpy. Let us then compute the residual error e from the fit x ̃ to the datapoints x, using the RMSE formula 3. Now, compute a polynomial fit with the degree of 8. How doesthe RMSE change? 4. We now want to perform clustering of the absolute value of the polynomial co- efficients obtained from the first fit (4th degree). Let us for this purpose use the KMeans functionsfrom the scikit.cluster package. Carry out the k-means fittings for a cluster size k = [2, 4, 6, . . . , 30]. Using the inertia property for each clustering assignment, create a Elbow Plot that suggests the optimal k for clustering of the coefficients. 5. Now, repeat this using the 8th degree polynomial fit. What is the optimal kbased on the Elbow method for this feature set? 6. Pick one choice of k from the 4th degree polynomial fit, based on the Elbow method. Create a visualization (histogram) showing how many total data rows have been assigned to each cluster. Compare to the same k from the 8th degree fit. Bonus: visualize the average spine configuration obtained for each cluster. 7. Now, compute the average spine_length variable for each cluster. What do you observe? 8. Dividing the dataset according to the area variable in two labels (label A=area below a value of 450, label B=area above a value of 450). Create a classifier using your favorite method available in the scikit package that classifies into labels A and B. Create a random train and test data split with 10 and 90 percent of your data, respectively. First, carry out the classification based only on your regression coefficients (4th degree or 8th degree) and then, based on all the data available in the data frame. What kind of 10-fold cross-validation accuracy do you get for your method for both cases? 9. Imagine, you would want to design an artificial neural network (ANN) that needs to classify the spine point data to some training labels. You can imagine the train- ing labels to be cluster assignment obtained from your k-mean assignments. What kind of network architecture would you suggest for this kind of classification task? Sketch a network diagram that you could come up with to do this classification. 10. Create a model function that would initialize your designed ANN model in the pytorch or tensorflow development API. You can think of a class NeuralNet (nn.Module) initialization that creates the building blocks of the ANN and assigned the connections between Codersarts is a top-rated website for students which is looking for online Programming Assignment Help, Homework Help, Coursework Help in C, C++, Java, Python, Database, Data structure, Algorithms, Final year project, Android, Web, C sharp, ASP NET to students at all levels whether it is school, college and university level Coursework Help or Real-time project. Hire us and Get your projects done by a computer science expert. Contact Codersarts for any such project/assignment help
- Get Help In Python Projects | Python GUI Tools And Frameworks
Are you looking for a python developer for your python projects or Python Coding Help? Do you need any online coding help related to python? Do you need help in python machine learning? then we are ready to help you. There are many python frameworks and tools in which you can get help within affordable prices. Get Help In Python Framework: Python Django Python Flask Python Django Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. Built by experienced developers, it takes care of much of the hassle of Web development, so you can focus on writing your app without needing to reinvent the wheel. It’s free and open source. Why developer choose django: Ridiculously fast Reassuringly secure Exceedingly scalable Features of Django: Offers Model - View – Controller (MVC) Architecture. Predefined libraries for imaging, graphics, scientific calculations, etc. Supports for multiple databases. Cross-platform operating system. Site optimization across specialized servers Support for front-end tools like Ajax, jQuery, Pyjamas, etc. Supports multi-Language and multi-characters. Python Flask Flask is considered more than the Django web framework because in common situations the equivalent Flask web application is more explicit. Flask is also easy to get started with as a beginner because there is little boilerplate code for getting a simple app up and running. Simple hello word program Using flask: app.py from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return 'Hello, World!' if __name__ == '__main__': app.run() Run it using simple command: python app.py Features of Flask: Integrated support for unit testing. RESTful request dispatching. Uses a Ninja2 template engine. It is based on Werkzeug toolkit. Support for secure cookies (client-side sessions). Extensive documentation. Google app engine compatibility. APIs are nicely shaped and coherent Easily deployable in production Get Help In Python Socket Programming Sockets are the backbone of networking. They make the transfer of information possible between two different programs or devices. For example, when you open up your browser, you as a client are creating a connection to the server for the transfer of information. To achieve Socket Programming in Python, you will need to import the socket module or framework. It divided into two part: Client: A client is either a computer or software that receives information or services from the server. In a client-server module, clients requests for services from servers. Server: A server is either a program, a computer, or a device that is devoted to managing network resources. Get Help In Python Machine Learning You can get help in python machine learning. There are may areas in which you can get help in python machine learning: supervised unsupervised learning, Reinforcement Learning Get Help In python Visualization You are also get help in python visualization related to below: Matplotlib Seaborn ggplot Bokeh pygal Plotly geoplotlib Gleam missingno Leather Other Tools Related to python in which you can get help Tkinter PyQT Wxpython Pygame Kevy Python Tkinter The tkinter package (“Tk interface”) is the standard Python interface to the Tk GUI toolkit. Both Tk and tkinter are available on most Unix platforms, as well as on Windows systems. How to import tkinter: import tkinter or from tkinter import * Simple tkinter example: #!/usr/bin/python import Tkinter top = Tkinter.Tk() # Code to add widgets will go here... top.mainloop() Output: PyQT: PyQt is a Python binding for Qt, which is a set of C++ libraries and development tools that include platform-independent abstractions for Graphical User Interfaces (GUI), as well as networking, threads, regular expressions, SQL databases, SVG, OpenGL, XML, etc. PyQt is available in two editions: PyQt4 PyQt5 Wxpython: The wxPython GUI toolkit is a Python wrapper around a C++ library called wxWidgets. The initial release of wxPython was in 1998, so wxPython has been around quite a long time. wxPython’s primary difference from other toolkits, such as PyQt or Tkinter, is that wxPython uses the actual widgets on the native platform whenever possible. This makes wxPython applications look native to the operating system that it is running on. How to install: We can install it using pip command: pip install wxpython Simple Example: import wx app = wx.App() frame = wx.Frame(parent=None, title='Hello World') frame.Show() app.MainLoop() Pygame: pygame is a Python wrapper for the SDL library, which stands for Simple DirectMedia Layer. SDL provides cross-platform access to your system’s underlying multimedia hardware components, such as sound, video, mouse, keyboard, and joystick. pygame started life as a replacement for the stalled PySDL project. How to install: We can install it using pip command: pip install pygame Kevy: Kivy - Open source Python library for rapid development of applications that make use of innovative user interfaces, such as multi-touch apps. Features: Cross platform Business Friendly GPU Accelerated Simple kevy example: import kivykivy.require('1.0.6') # replace with your current kivy version ! from kivy.app import App from kivy.uix.label import Label class MyApp(App): def build(self): return Label(text='Hello world') if __name__ == '__main__': MyApp().run() Send your request at contact@codersarts.com and get instant help with an affordable prices,











