<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by chithra prabha on Medium]]></title>
        <description><![CDATA[Stories by chithra prabha on Medium]]></description>
        <link>https://medium.com/@chithraprabhap?source=rss-d4b96e1ae509------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*lkErQ0zGNHNfuBHy</url>
            <title>Stories by chithra prabha on Medium</title>
            <link>https://medium.com/@chithraprabhap?source=rss-d4b96e1ae509------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 22:06:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@chithraprabhap/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Using Gradient Descent in CNN implementation]]></title>
            <link>https://medium.com/analytics-vidhya/using-gradient-descent-in-cnn-implementation-3c94029ffed8?source=rss-d4b96e1ae509------2</link>
            <guid isPermaLink="false">https://medium.com/p/3c94029ffed8</guid>
            <category><![CDATA[cnn-model]]></category>
            <category><![CDATA[gradient-descent]]></category>
            <dc:creator><![CDATA[chithra prabha]]></dc:creator>
            <pubDate>Fri, 29 Mar 2024 12:35:10 GMT</pubDate>
            <atom:updated>2024-04-02T06:00:18.960Z</atom:updated>
            <content:encoded><![CDATA[<p>Gradient descent is an iterative process through which we optimize the parameters of a CNN model,we use gradient for optimization of the loss funtion.The gradient of a continuous function is defined as the vector that contains<strong> </strong>the slopes of traces(<strong> </strong>the partial derivatives<strong>)</strong> computed at that point . The gradient is finite and defined if and only if all partial derivatives are also defined and finite.In the optimization process, gradients allow us to determine how to move the parameters of a model in order to lower the loss.The figure below gives the visualisation of gradients of the loss funtion.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o0DxejZspUU25D0pzWEdyQ.png" /></figure><p>The derivative of a function is defined as the instantaneous rate of change of a function at a specific point.The derivative gives the exact slope along the curve at a specific point</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o1sgblZDaI9Oq68_L1tc7A.png" /></figure><p>CNN implementation layers contain the key parameters I, K, b ,Wf,bF explained in the <a href="https://chithraprabhap.medium.com/cnn-architecture-and-implentation-overview-2a7ebb728b5c"><em>CNN Architecture </em></a>and CNN implemetation figure below ,CNN models regression and classification are done based on these parameter ,we will implement this gradient funtions for these parameters in the mathematical funtion in python to understand their funtion,though this method of implemetation is time consuming and it process complex methods, it will be good to understand how the model works using this optimization method, but in practice there are many libraries like pyTorch, Tensorflow ,etc. which provide us with this optimization process in a efficient way,but for studying the process we will go thorough the mathematical steps in this article using python code with the key blocks of CNN implemetation modules shown in the figure below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E6US2hT6ACz42wNsbRN5Kg.png" /></figure><h3>Feature Extraction Layer</h3><p>Feature layer includes Convolution with filter K on the Input Image I, padding process ,Relu Activation and the Maxpooling layer for Feature Extraction ,the code for this layer is below</p><pre># convolution function<br>def f_conv2d(I,K,p):<br>    fSize = K.shape[0]<br>    I2 = f_padd(I,p)<br>    numRows = I2.shape[0]<br>    numCols = I2.shape[1]<br>    #creates an empty data matrix of size ,reduced by twice the padding size in rows and coloumns<br>    C = np.zeros((numRows-2*p,numCols-2*p))<br>    #matrix multiplication of the filter cell values (flattened into single matrix  K ),<br>    #Image cell values () flattened into single matrix A ),filters centered at each pixcel of image matrix<br>    #and get the summation the products into convolution  matrix C <br>    for i in range(numRows-fSize+1):<br>        for j in range(numCols-fSize+1):<br>            A = I2[i:i+fSize,j:j+fSize]<br>            C[i,j] = (A.flatten()*K.flatten()).sum()<br>    # return convolution  matrix C         <br>    return C<br><br>def f_padd(I,p):<br>    #I is image and p is padding size<br>    #find the number of rows and coloums<br>    numRows = I.shape[0]<br>    numCols = I.shape[1]<br>    <br>    #Padding rows with zeros on top and bottom <br>    #create row of zeros<br>    zeroRows = np.zeros((p,numCols))     <br>    ##Padding zeros on top<br>    I = np.vstack((zeroRows,I))<br>    ##Padding zeros on bottom<br>    I = np.vstack((I,zeroRows))<br>    <br>    ##Padding coloums with zeros on top and bottom <br>    #no. coloums we are adding is the no. of rows + 2 times the padding size <br>    # as 2*p number of rows area lready added<br>    zeroCols = np.zeros((numRows+2*p,p))<br>    I = np.hstack((zeroCols,I))<br>    I = np.hstack((I,zeroCols))<br>    <br>    #return image after padding with zeros<br>    return I<br><br># ReLu Activation function, this function converts the linear layers in to non linear<br>#so that the entire net is not linear with input and out put going in same direction.<br>#ReLu is the simplest form of activation function, which<br>#connects neurons in the layer  that  are greater than 0 and Zeros other values .<br>def f_ReLU(C):<br>    C[C&lt;0] = 0<br>    #return C matrix with ReLu activated values<br>    return C<br><br>#Max Pooling funtion <br>def f_pool(C):<br>    r = C.shape[0]<br>    c = C.shape[1]<br>    S = np.zeros((int(r/2),int(c/2)))<br>    for i in range(0,r,2):<br>        for j in range(0,c,2):<br>            #pool the C matrix with block size 2X2  to find  maximum value in the block<br>            #and copy it to the (i/2,j/2)the element in the S matrix<br>            S[int(i/2),int(j/2)] = C[i:i+2,j:j+2].max()<br>    #return the max pooled matrix S<br>    return S</pre><h3>Classificaiton layer</h3><p>This layer is also called as Fully connected layer ,in this layer we use the flattened output vector image from the Feature Extraction Layer to classify the image according the features that match the samples using output funtion from the <strong>Softmax Funtion </strong>to optain the true lable Y and the predicted lable Y-hat,we compare the Y-hat obtained by applying the gradient descent with the Y until we reach the loss minimum using epochs of back probagation and the forward pass, which will be explained in the below sections.</p><pre>#Softmax sigmoid funtion<br>def f_sigmoid(f,wf,bf):<br>    x = wf.dot(f)+bf<br>    y_hat = 1/(1+np.exp(-x))<br>    #return the predicted y_hat value <br>    return y_hat</pre><h3>Forward Pass Explained in code</h3><pre>#forward pass<br>def f_forwardPass(I,K,b,wf,bf):<br>    #we define the padding size,here we use generic size by taking half the size of K (5X5 matrix) which will become 2 <br>    p = int(K.shape[0]/2)<br>    #Do convolution operation on Image matrix I with K filter <br>    C = f_conv2d(I,K,p)<br>    # Add the bias to the Convolution output<br>    C = C+b<br>    #generate the Final C matrix with the activation funtion<br>    C = f_ReLU(C)<br>    #Apply Pooling layer and generate the S matrix<br>    S = f_pool(C)<br>    #Get the flattened variant of S matrix<br>    f = S.flatten()<br>    #valuate the y_hat putput<br>    y_hat = f_sigmoid(f,wf,bf)<br>    # return the variables requred for Back Probagation<br>    return C,f,y_hat</pre><h3>Derivatives of K ,b,Wf,bF</h3><p>Derivatives of the parameter K filter funtion can be explained with the figure below. K1 being the filter values in first iteration and K2 being the value in the second iteration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eDdJDwnzUICZVaTxGKQ5Sw.png" /></figure><blockquote><strong>K2 = K1 — α Δk1</strong> (Δk is how the value of ŷ changes with the value of k ,α is the learning factor also how loss function L changed with the value k)</blockquote><p>Here we subtract the Δk as we will work with gradient descent, we travel in upward direction and subtract the same value to reach the local minimum in decent direction.</p><p>Above concept is applied for finding the gradient value Δb ,ΔWf ,Δbf to reach the minimum loss .</p><blockquote>b2 = b1 — αΔb1</blockquote><blockquote>Wf2 =Wf1 — αΔWf1</blockquote><blockquote>bf2 =bf1 — αΔbf1</blockquote><pre>#Derivative of Loss funtion with respect to W<br># dL/dW(i) =  (ŷ-y).ŷ(1- ŷ)f(i)      (calculus of sigmoid =  ŷ(1- ŷ))<br>def f_getGradient_w(y_hat,y,f):<br>    Dw = np.squeeze(np.zeros((1,len(f))))<br>    <br>    a = (y_hat-y)*y_hat*(1-y_hat)<br>    for i in range(len(f)):<br>        Dw[i] = a*f[i]<br>    return Dw<br><br>#Derivative of Loss funtion with respect to f (feature selected vector),dL/df =bf.W<br># dL/df(i) =  (ŷ-y).ŷ(1- ŷ)W(i)      (calculus of sigmoid =  ŷ(1- ŷ))<br>def f_getGradient_f(y_hat,y,wf):<br>    # Squeeze the iterations, so the dot products and other process to work well<br>    Df = np.squeeze(np.zeros((1,len(wf))))<br>    a = (y_hat-y)*y_hat*(1-y_hat)<br>    for i in range(len(wf)):<br>        Df[i] = a*wf[i]<br>    return Df<br><br>#Derivative of Loss funtion with respect to parameter bf<br># bf =  (ŷ-y).ŷ(1- ŷ)      (calculus of sigmoid =  ŷ(1- ŷ))<br>def f_getGradient_bf(y_hat,y):<br>    Dbf = (y_hat-y)*y_hat*(1-y_hat)<br>    return Dbf<br><br>#Derivative of Loss Funtion ,here it is the Changed value matrix  with respect to  F <br># Parameter is  the f matrix of size 256X1<br>def f_getGradient_S(Df):<br>    #take square root size of f matrix which is square root of 256 is 16 <br>    n = int(len(Df)**0.5)<br>    # Reshape the flattened matrix f to 16X16 matrix to get S matrix<br>    DS = Df.reshape((n,n))<br>    return DS<br><br>#Derivative of Loss funtion ,here it is Changed value matrix C ,reversed  after max pooling applied<br>#the derived out put will be a matrix of 32X32,paked with the 2X2 martrix block containing zeros in the index with non maxvalue <br>#and max value in the (i,j)th index in each block<br>def f_getGradient_C(DS,C):<br>    r = C.shape[0]<br>    c = C.shape[1]<br>    DC = np.zeros((r,c)) #2X2 Matrix<br>    for i in range(0,r,2):<br>        for j in range(0,c,2):<br>            #pool the C matrix with block size 2X2  to find  maximum value in the block<br>            #and copy it to the (i/2,j/2)the element in the S matrix<br>            C_block = C[i:i+2,j:j+2]<br>            #find the index where the maximum value resides<br>            ind = np.unravel_index(np.argmax(C_block,axis=None),C_block.shape)<br>            #i is the index were we start applying the 2X2 block into C matrix,so add index of max value  to i <br>            DC[i+ind[0],j+ind[1]] = DS[int(i/2),int(j/2)]<br>    return DC     <br><br>def f_getChainRuleGradients(C,DC,I,u,v):<br>    DKuv = 0<br>    for i in range(C.shape[0]):<br>        for j in range(C.shape[1]):<br>            if C[i,j]&gt;0 and i-u&gt;=0 and j-v&gt;=0 and i-u&lt;C.shape[0] and j-v&lt;C.shape[1]:<br>                DKuv = DKuv + (I[i-u,j-v]*DC[i,j])<br>    return DKuv<br><br>def f_getGradient_K(C,I,y_hat,y,wf):<br>    Df = f_getGradient_f(y_hat,y,wf)<br>    DS = f_getGradient_S(Df)<br>    DC = f_getGradient_C(DS,C)<br>    DK = np.zeros((5,5))<br>    for u in range(-2,3):<br>        for v in range(-2,3):<br>            DK[u+2,v+2] = f_getChainRuleGradients(C,DC,I,u,v)<br>    return DK,DC<br><br>def f_getGradient_b(C,DC):<br>    Db = DC[C&gt;0].sum()<br>    return Db</pre><h3>Backward Pass explained in Code</h3><pre>def f_backwardPass(I,C,f,wf,y_hat,y):<br>    Dw = f_getGradient_w(y_hat,y,f)<br>    Dbf = f_getGradient_bf(y_hat,y)<br>    DK,DC = f_getGradient_K(C,I,y_hat,y,wf)<br>    Db = f_getGradient_b(C,DC)<br>    return DK,Db,Dw,Dbf</pre><h3>Running the Epochs</h3><p>By running the forward and backward pass for many iterations, we will be able to obtain the minimum loss point ,by using the below code</p><pre>def f_initParams():<br>    K = 0.01*np.random.randn(5,5)<br>    b = 0.01*np.random.randn()<br>    wf = np.squeeze(0.01*np.random.randn(1,256))<br>    bf = 0.01*np.random.randn()<br>    return K,b,wf,bf</pre><pre>#Run the 50 epochs and check the output value of Y.hat, which is in the range of 0-1<br>I = np.random.randint(1,255,(32,32))<br>y = 0<br>K,b,wf,bf = f_initParams()<br>for i in range(50):<br>    C,f,y_hat = f_forwardPass(I,K,b,wf,bf)<br>    print(y_hat)<br>    DK,Db,Dw,Dbf = f_backwardPass(I,C,f,wf,y_hat,y)<br>    alpha = 0.001<br>    K = K - alpha*DK<br>    b = b - alpha*Db<br>    wf = wf - alpha*Dw<br>    bf = bf - alpha*Dbf</pre><p>So we could understand clearly from the code ,that in the backward pass we are finding the new value for each block based on the output of the previous block in the previous iteration, using this gradient descent optimization method we obtain the parameters, to find the minimal loss in the classification process.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3c94029ffed8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/using-gradient-descent-in-cnn-implementation-3c94029ffed8">Using Gradient Descent in CNN implementation</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Image Processing using SciPy and OpenCV]]></title>
            <link>https://chithraprabhap.medium.com/image-processing-using-scipy-for-convolution-and-filters-from-opencv-f5072246dd7a?source=rss-d4b96e1ae509------2</link>
            <guid isPermaLink="false">https://medium.com/p/f5072246dd7a</guid>
            <dc:creator><![CDATA[chithra prabha]]></dc:creator>
            <pubDate>Fri, 22 Mar 2024 10:51:01 GMT</pubDate>
            <atom:updated>2024-03-22T10:57:08.050Z</atom:updated>
            <content:encoded><![CDATA[<p>The CNN models use convolution process instead of filters to generate images for processing in their layers , in this article simple steps to use the convolution methods from the <strong>SciPy </strong>library are explained<strong> ,SciPy </strong>is a Python-based module built on top of NumPy, gives us wide range of scientific and technical computing functionalities. <strong>Signal processing </strong>in SciPy is a sub-module which provides functions and tools for analyzing, filtering, transforming, and manipulating signals, that are used for tasks like convolution.</p><p>OpenCV the Open Source Computer Vision Library provides us hundreds of computer vision algorithms . It provides Functions and classes that are used to perform various linear or non-linear filtering operations on 2D images. Below is a code sample of how the Image Bluring is done using the OpenCV funtions .We could either use SciPy or OpenCV for the filtering operation,SciPy offers better functions to do covolution operation before applying the filters.</p><p><strong>Code for loading the input image and displaying the Image</strong></p><pre>&quot;&quot;&quot; import the libraries &quot;&quot;&quot;<br>import cv2<br>import numpy as np<br>import matplotlib.pyplot as plt<br>#Convolution library in scipy<br>from scipy import signal<br>#Convolution library from OpenCV<br>import cv2<br>from PIL import Image<br>import urllib<br>import urllib.request<br><br>&quot;&quot;&quot; Read the Image and Load the image data into the array &quot;&quot;&quot;<br><br># create a file-like object from the url<br>url= &quot;http://commondatastorage.googleapis.com/codeskulptor-demos/riceracer_assets/img/car_4.png&quot;<br>try:<br>    url_response = urllib.request.urlopen(url)<br>    img = Image.open(url_response)<br>except urllib.error.HTTPError as e:<br>    print(&#39;Could not read image&#39;)<br>    #Exit the script if  any exception error occurs<br>    exit()  <br>#load the image data in to numpy array<br>im = np.asarray(img)<br>#load the image with three channels <br>imInPut = im[:,:,:3]<br># diplay the  original image image<br>plt.imshow(imInPut)<br>#grey the image and show<br>imGray = cv2.cvtColor(imInPut,cv2.COLOR_RGB2GRAY)<br>plt.imshow(imGray,cmap=&#39;gray&#39;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YobtORCrosTt3Qxax9ryCQ.png" /></figure><pre>&quot;&quot;&quot;<br>create mask of size 19,19 , divide it by 19 square,<br>that is required for an average mask,<br>to get the sum of all mask as  1 <br>&quot;&quot;&quot;<br>mask = np.ones((19,19))/(19**2)<br><br>&quot;&quot;&quot;use signal api to apply blur filter, mode =&quot;same&quot; means ,use the same dimension as the image <br>replicate the boundary with symetric reflecxance&quot;&quot;&quot;<br><br>imBlurred = signal.convolve2d(imGray,mask,boundary=&#39;symm&#39;,mode=&#39;same&#39;)<br><br>#display the input image and the blured output image using matplotlib<br>figPlot,(axis1,axis2) = plt.subplots(1,2,figsize=(10,15))<br>axis1.imshow(imGray,cmap=&#39;gray&#39;)<br>axis2.imshow(imBlurred,cmap=&#39;gray&#39;)<br>figPlot.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IsxPulhmFXVBmPPYfMjd7Q.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f5072246dd7a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CNN Architecture and Implementation Overview]]></title>
            <link>https://chithraprabhap.medium.com/cnn-architecture-and-implentation-overview-2a7ebb728b5c?source=rss-d4b96e1ae509------2</link>
            <guid isPermaLink="false">https://medium.com/p/2a7ebb728b5c</guid>
            <dc:creator><![CDATA[chithra prabha]]></dc:creator>
            <pubDate>Thu, 14 Mar 2024 17:59:50 GMT</pubDate>
            <atom:updated>2024-03-31T04:06:33.624Z</atom:updated>
            <content:encoded><![CDATA[<h3>CNN Architecture</h3><p>Neural networks are specialized in processing data that has a grid-like topology. It includes image data and time-series data which can be thought of as a 2-D grid of pixels, leveraging principles from linear algebra, specifically matrix multiplication, to identify patterns within an image or data file.</p><p>Neural networks consists of many node layers, the layers are categorised as an input layer, one or more hidden layers, and an output layer. Each node is connected to another and has an associated weight(W) and threshold (-b).If the output of any individual node is above the specific threshold value, that node is activated, thus sending data to the next layer of the network. Else, no data is passed along to the next layer of the network.</p><p>There are various types of neural networks used for different use cases and data types. Convolution Neural Networks(CNNs)are more often utilized for image classification and object recognition tasks,used in computer vision applications where as Recurrent neural networks(RNNs) are commonly used for natural language processing and speech recognition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/873/1*NW5_2cLzqKQjQf1-4jmWZQ.png" /></figure><p>In CNNs the layers of interconnected data with lot of information are processed using CONVOLUTION operation,instead of normal the basic matrix-multiplication called image CORRELATION operations that are used in normal image filtering methods,this makes it most effective in Computer vision tasks.In correlation filtering operation , the filter is used directly but in convolution filtering operations , the kernel will be flipped in both<em> </em>dimensions<em>.</em></p><p>There are two main functional modules in CNNs the Feature extraction Modules and the Classifcation Module ,the Feature extraction module identifes and extracts relevant features from raw data ,the extracted data is them made in to a different dataset,which is then used by the classification module to classify the data and identify the patterns.</p><p><strong>CNN Implemetation</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E6US2hT6ACz42wNsbRN5Kg.png" /></figure><p><strong>CNN implementaion figure above gives the overview</strong> <strong>basic parts of feature extraction and classification.</strong></p><p>There are two main layers in CNN implemetation, Feature extraction layer and the Classification layer . The feature extraction layer has three layers, the Convolutional layer is the first layer of a convolutional network. While convolutional layers can be followed by additional Convolutional layers or Pooling layers, then comes the the Fully-connected layer,it is the final Classification Layer. With each layer, the CNN increases in its complexity, identifying greater portions of the image features.</p><h3>Feature Extraction Layer</h3><p>Earlier layer of Feature extraction focus on simple features, such as colors and edges. As the image data progresses through the Convolution layers layers of the CNN, it starts to recognize larger elements or shapes of the object until it finally identifies the intended object.</p><h4>Convolutional layer</h4><p>The convolutional layer is the core building block of a CNN, and it is where the majority of computation occurs. It requires a few components, which are input data, a filter, and a feature map. Let’s assume that the input will be a color image, which is made up of a matrix of pixels in 3D. This means that the input will have three dimensions — a height, width, and depth — which correspond to RGB in an image. We also have a feature detector, also known as a kernel or a filter, which will move across the receptive fields of the image, checking if the feature is present. This process is known as a convolution.</p><p>The feature detector is a two-dimensional (2-D) array of weights, which represents part of the image. While they can vary in size, the filter size is typically a 3x3 matrix; this also determines the size of the receptive field. The filter is then applied to an area of the image, and a dot product is calculated between the input pixels and the filter. This dot product is then fed into an output array. Afterwards, the filter shifts by a stride, repeating the process until the kernel has swept across the entire image. The final output from the series of dot products from the input and the filter is known as a feature map, activation map, or a convolved feature.</p><p>Note that the weights in the feature detector remain fixed as it moves across the image, which is also known as parameter sharing. Some parameters, like the weight values, adjust during training through the process of backpropagation and gradient descent. However, there are three hyperparameters which affect the volume size of the output that need to be set before the training of the neural network begins. These include:</p><p>1. The number of filters affects the depth of the output. For example, three distinct filters would yield three different feature maps, creating a depth of three.</p><p>2. Stride is the distance, or number of pixels, that the kernel moves over the input matrix. While stride values of two or greater is rare, a larger stride yields a smaller output.</p><p>3. Zero-padding is usually used when the filters do not fit the input image. This sets all elements that fall outside of the input matrix to zero, producing a larger or equally sized output.</p><h4>Activation Funciton ReLU</h4><p>After each convolution operation, a CNN applies a Rectified Linear Unit (ReLU) transformation to the feature map, introducing nonlinearity to the model.ReLu activates only for positive values and stays zero for negative numbers.</p><h4>Pooling layer</h4><p>Pooling layers, also known as downsampling, conducts dimensionality reduction, reducing the number of parameters in the input. Similar to the convolutional layer, the pooling operation sweeps a filter across the entire input, but the difference is that this filter does not have any weights. Instead, the kernel applies an aggregation function to the values within the receptive field, populating the output array. There are two main types of pooling:</p><ul><li>Max pooling: As the filter moves across the input, it selects the pixel with the maximum value to send to the output array. As an aside, this approach tends to be used more often compared to average pooling.</li><li>Average pooling: As the filter moves across the input, it calculates the average value within the receptive field to send to the output array.</li></ul><p>While a lot of information is lost in the pooling layer, it also has a number of benefits to the CNN. They help to reduce complexity, improve efficiency, and limit risk of overfitting.</p><h3>Classification Layer or the Fully Connected Layer</h3><h4>Softmax function for Logistic Regression</h4><p>Softmax Regression is a generalization of Logistic Regression that summarizes a ‘k’ dimensional vector of arbitrary values to a ‘k’ dimensional vector of values bounded in the range (0, 1). In Logistic Regression we assume that the labels are binary (0 or 1). However, Softmax Regression allows one to handle classes.The softmax applies the standard <a href="https://en.wikipedia.org/wiki/Exponential_function">exponential function</a> to each element CNN model .Sigmoid is logical regression funtion used for binary classification methods where we only have 2 classes, while SoftMax applies to multiclass problems . In fact, the SoftMax function is an extension of the Sigmoid function. Softmax function gives us the output which is a vector ,in which each value represents the probability of belonging a different class, as explained in this <a href="https://towardsdatascience.com/sigmoid-and-softmax-functions-in-5-minutes-f516c80ea1f9">link</a> .</p><h4>Additional Convolutional layer</h4><p>Ultimately, the convolutional layer converts the image into numerical values y-hat, allowing the neural network to interpret and extract relevant patterns.Once y-hat is obtained we use back probogation algorithm to find the minimum loss values using the chain rule.</p><h4>Backpropagation</h4><p>But what if our model predicted label (y-hat) away from the true label (y) of your data (and of course it’s a normal phenomenon as your model at the first place <em>randomly</em> creates weights for its neurons). here role of loss function will come which calculate the difference between y and y-hat. Then the model now knows how much the difference between them and want to upgrade the weights of each neurons to decrease this difference. here the role of backpropagation will come which calculate how much exactly our weights need to be upgraded which we call it the gradient ( how our loss will change in respect of the weights ) and now it all about calculus but you don’t need to be a genius in math to calculate it as now there are many frameworks that remove this hassle off your shoulder (like TensorFlow and PyTourch).</p><p>Below are the list of parameters that are needed to be evaluated to obtain the Loss funtion.</p><blockquote><em>1.K = W1.I + b (W is the weight, b is the bias)</em></blockquote><blockquote><em>2.C = Relu(k) (relu is the activation function, c output of fist layer)</em></blockquote><blockquote><em>3.S =MaxPool(C)</em></blockquote><blockquote><em>4.F = FeatureMatrix(S)</em></blockquote><blockquote><em>5. Sigma= Wf.F +bf</em></blockquote><blockquote><em>6.y-hat = sigmoid(Sigma) (sigmoid is another activation function for binary classification as in our case)</em></blockquote><blockquote><em>7. Loss (y-hat,y)</em></blockquote><p>So we need to know what is the derivative of loss with respect to the weights ,we can update the weight to improve the loss(decrease it) (dL/dW),this can be done using the chain rule .</p><h4>Chain rule can be explained with the dependencies that are needed to get the derivatives for each parameters that makes the loss function minimum.</h4><p>Chainrule means the derivative of Loss function of one process is obtained from the Product of derivative Loss function with the previous output and the derivative of the current output with the previous process output.The evaluation process is done from the End of obtaining the Loss funtion to Start of image input process,the flow can be represented as mentioned below ,basically how W affect L can be written as how Wi affects ŷ multiplied by how ŷ affects L</p><blockquote>1.dL/dŷ = (ŷ-y)</blockquote><blockquote>2. dL/<strong>σ</strong> = dL/d( ŷ). d( ŷ)/<strong>σ</strong> (calculus of sigmoid equal ŷ(1- ŷ))</blockquote><blockquote>3. dL/dF = dL/σ . <strong>σ</strong>/dF</blockquote><blockquote>4. dL/S = dL/dF . dF/dS</blockquote><blockquote>5. dL/dC = dL/S . S/dC</blockquote><blockquote>6. dL/dK = dL/dC . dC/dK</blockquote><blockquote>7. dL/dW1 = dL/K . K/dW1</blockquote><p>This method of finding the minimum loss point, where the difference between y and yhat is very minimal by changing the parameter values in each iteratoin is called backpropagation,as we letterly back each step in feed forward propagation</p><p>The complete iteration through the entire training image dataset during model training is called an epoch,by enabling the model to update its parameters based on the optimization funtions and loss function in each epoch, with forward pass and backward propagation as explained above ,the loss function can be minimised and be able make the CNN model perform better classification and regressions functions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2a7ebb728b5c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Basics of setup required for using Python Face Recognition library]]></title>
            <link>https://medium.com/analytics-vidhya/basics-of-setup-required-for-using-python-face-recognition-library-ae96bf29acca?source=rss-d4b96e1ae509------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae96bf29acca</guid>
            <dc:creator><![CDATA[chithra prabha]]></dc:creator>
            <pubDate>Sun, 06 Jun 2021 14:58:10 GMT</pubDate>
            <atom:updated>2021-06-11T16:06:03.285Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Quick Guide for setting up environment to program Face Detection and Face Editing Techniques in Python.</strong></p><p>In this blog we will see how to setup the environment to write programs that does Face Recognition,Face Detection and Face Makeup,Age and Gender Recognition. We will be using the python library for Face recognition available at <a href="https://pypi.org/project/face-recognition/">https://pypi.org/project/face-recognition/</a> for this ,we will learn the installation and uses of Tensorflow and Keras Deep learning Libraries in Linux Operating System.</p><h3>Environment setup</h3><p>First we need to get the Anaconda installed ,it contains conda ,Anaconda Navigator, Python,and many scientific packages for Machine Learning. Anaconda Navigator is a GUI that allows you to launch applications like Spyder IDE is used for deep learning programming in best way and also easily manage conda packages.</p><pre>#Prepare build environment with below packages ,<br>sudo apt-get update<br>sudo apt-get install build-essential cmake<br>sudo apt-get install libopenblas-dev liblapack-dev<br>sudo apt-get install libx11-dev libgtk-3-dev’<br>sudo apt-get install python python-dev python-pip<br> <br> <br>#Install the following extended dependencies for Qt required for the GUI packages of Anaconda<br>apt-get install libgl1-mesa-glx libegl1-mesa libxrandr2 libxrandr2 libxss1 libxcursor1 libxcomposite1 libasound2 libxi6 libxtst6<br>#Download Anaconda installer script from the link below,<br>#<a href="https://repo.anaconda.com/archive/Anaconda3-2021.05-Linux-x86_64.sh">https://repo.anaconda.com/archive/Anaconda3-2021.05-Linux-x86_64.sh</a><br>sudo sh ./Anaconda3–2021.05-Linux-x86_64.sh -u<br>#Check the installed version is ok<br>conda info<br>source ~/.bashrc<br>python — version<br>#Try launching Spyder IDE <br>spyder</pre><p>Now we have the IDE ready to program,next lets install the python libraries that are required for writing the face recognition program from the website <a href="https://pypi.org/project/face-recognition/">https://pypi.org/project/face-recognition/</a> ,we could use either the conda command to install the libraries as listed below</p><pre>#create a environment for face recognition project <br>conda create -n env_facerecog python==3.7.9 anaconda<br>conda activate env_facerecog<br>#Install dlib library<br>conda install -c conda-forge dlib<br>#Install opencv library</pre><p>Now we have the IDE ready to program,next lets install the python libraries that are required for writing the face recognition program from the website <a href="https://pypi.org/project/face-recognition/">https://pypi.org/project/face-recognition/</a> ,we could use either the conda command to install the libraries as listed below</p><pre>#create a environment for face recognition project <br>conda create -n env_facerecog python==3.7.9 anaconda<br>conda activate env_facerecog<br>#Install dlib library<br>conda install -c conda-forge dlib<br>#Install opencv library<br>conda install -c conda-forge opencv<br>#Install face_recognition library<br>conda install -c conda-forge face_recognition</pre><p>Now we have required setup open the spyder IDE in from the environment <br>(env_facerecog) chithrarajeev@rklenovo:spyder<br>create a test file test_env.py and try print the versions of the libraries we installed as below</p><pre>(env_facerecog) chithrarajeev@rklenovo:spyder<br>#import the libraries<br>import cv2<br>import dlib<br>import face_recognition<br>#printing the versions of libraries required<br>print(“Version of OpenCV is” ,cv2.__version__)<br>print(“Version of Dlib C++ toolkit for ML is” ,dlib.__version__)<br>print(“Version of face_recognition is” ,face_recognition.__version__)</pre><blockquote>#Out put is as below <br>Version of OpenCV is 4.5.2<br>Version of Dlib C++ toolkit for ML is 19.22.0<br>Version of face_recognition is 1.2.3</blockquote><p>Sometimes the conda installation may give errors below, if you get any of this error below , then try pip installation of the libraries</p><blockquote>ImportError: No module named ‘dlib <br>ImportError: No module named ‘cv2</blockquote><pre>(env_facerecog) chithrarajeev@rklenovo:pip install opencv-contrib-python<br>(env_facerecog) chithrarajeev@rklenovo:pip install dlib<br>(env_facerecog) chithrarajeev@rklenovo:pip install face_recognition</pre><p>If there are issues with pip installation try adding proper channels of the packages which is needed , also try using option ‘-c conda-forge’ for conda reinstallation as below</p><pre>conda create -n env_facerecog python matplotlib opencv scipy anaconda -c conda-forge<br>conda config — set channel_priority false<br>conda activate env_facerecog</pre><p>Using the program shown below we can detect the faces in an image and dispaly them seperately</p><pre>#!/usr/bin/env python3<br>#import libraries<br>import cv2<br>import face_recognition</pre><pre>#load the Input image file<br>image_to_detect = cv2.imread(r&#39;images/shreya/shreya_CCL_match_India.jpg&#39;)<br>#Show the Input image file<br>cv2.imshow(&quot;Input Image &quot;,image_to_detect)<br>#locate theface locations<br>all_face_locations = face_recognition.face_locations(image_to_detect,model=&#39;hog&#39;)<br>#Print the face location details<br>print(&#39;There are {}  faces in this CCL  India match picture of shreya&#39;.format(len(all_face_locations)))</pre><pre>#looping through the face locations and dispaly each of them<br>for index,current_face_location in enumerate(all_face_locations):<br>    #splitting the tuple to get the four position values of current face<br>    top_pos,right_pos,bottom_pos,left_pos = current_face_location<br>    #printing the location of current face<br>    print(&#39;Found face {} at top:{},right:{},bottom:{},left:{}&#39;.format(index+1,top_pos,right_pos,bottom_pos,left_pos))<br>    #slicing the current face from main image<br>    current_face_image = image_to_detect[top_pos:bottom_pos,left_pos:right_pos]<br>    #showing the current face with dynamic title</pre><pre>    cv2.imshow(&quot;Face no &quot;+str(index+1),current_face_image)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hYIf2nFF4ErWX7PRowP31A.png" /></figure><p>In the same way we could recognise the faces in a recorded video or from live stream vidoe using the image frames.</p><p>Having recognised the faces in the image we could use this face data to identify the person in the image, to find the age and gender of the face image and also identify the emotions in the face such as anger,sad,happy,disgust,fear,surprise,neutral,and contempt, using the deep learning algorithms which are available for us in the Tensonflow frame work <a href="https://www.tensorflow.org/tutorials">https://www.tensorflow.org/tutorials</a>, which can be used with the help of wrappers available in the Keras library <a href="https://keras.io/getting_started/intro_to_keras_for_engineers/">https://keras.io/getting_started/intro_to_keras_for_engineers/</a> .Here we will see the steps to install the Tensor flow and Keras Deeplearning libraries.</p><pre>#install tensor flow library<br>(env_facerecog) chithrarajeev@rklenovo:sudo pip install tensorflow</pre><p><em>Note that It takes long time to install tensor flow library with message””” Downloading tensorflow-2.5.0-cp37-cp37m-manylinux2010_x86_64.whl (454.3 MB)”””</em></p><pre>#install keras library<br>(env_facerecog) chithrarajeev@rklenovo:~$ sudo pip install keras</pre><p>Now we have the environment setup to write programs for Face Identification, Face Emotion Detection ,Age and Gender detection using the recognised faces.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ae96bf29acca" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/basics-of-setup-required-for-using-python-face-recognition-library-ae96bf29acca">Basics of setup required for using Python Face Recognition library</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Product Analysis using Web Scrapping Technique in Python]]></title>
            <link>https://chithraprabhap.medium.com/product-analysis-using-web-scrapping-technique-in-python-459a363523e4?source=rss-d4b96e1ae509------2</link>
            <guid isPermaLink="false">https://medium.com/p/459a363523e4</guid>
            <category><![CDATA[python-data-analysis]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[web-scraping]]></category>
            <dc:creator><![CDATA[chithra prabha]]></dc:creator>
            <pubDate>Thu, 07 Jan 2021 01:18:26 GMT</pubDate>
            <atom:updated>2021-01-07T04:51:13.329Z</atom:updated>
            <content:encoded><![CDATA[<h3>Product Analysis using Web Scraping Technique in Python</h3><p>Web Scraping is one of the Data Scraping technique in which data is extracted from the websites for analysis.In this project we will learn the how to analyze the product in an online shop like flipkart, for example we will analyze various brands of Mobile Tablets sold in the flipkart web site and suggest the medium range product in price range.</p><p>Using the web scraping techniques we will be able to get the details prices,specifications, reviews,highlights and ratings for any product in the website.</p><p>We will be using the python modules urlopen(from urllib library) and BeautifulSoup(from bs4 library).</p><blockquote>import bs4 <br>import pandas as pd<br>import numpy as np<br>import seaborn as sns<br>import matplotlib.pyplot as plt<br>from urllib.request import urlopen as uReq <br>from bs4 import BeautifulSoup as soup</blockquote><p>First we need to read the contents of the web page which displays the search results of the product we are going to analyse ,the tablet and parse the html content using the BeautifulSoup module.</p><blockquote>myurl = “<a href="https://www.flipkart.com/tablets/pr?sid=tyy,hry&amp;marketplace=FLIPKART">https://www.flipkart.com/tablets/pr?sid=tyy,hry&amp;marketplace=FLIPKART</a>&quot; <br>uclient = uReq(myurl) <br>page_html = uclient.read() <br>uclient.close()</blockquote><blockquote>psoup = soup(page_html, “html.parser”)</blockquote><p>Below is the screen short of the web page we are going to get the data for analysis,right click on the page and do inspect, it will show the HTML document tags for each element in the page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OJj2aknImzTPLBjM1Nu5_A.png" /></figure><p>Right click on the Page index tab in the page select the inspect option and search for the elements listing and find the class name for that element and use it for getting the href of the link to the search result pages for all the product listed,as show in the picture below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dA3jWvaukbMkdW4_yBVT5A.png" /></figure><p>Now find all the page references and store it in a list,as detailed in the code below</p><blockquote>page_urls = list() <br>for containers in psoup.findAll(‘div’,{‘class’:’_2MImiq’}): <br> a_list = containers.findAll(‘a’,{‘class’:’ge-49M’}) <br> <br> #uncomment and use the below 2 lines to get all the search 10 pages <br> #for a in a_list:<br> # page_urls.append(‘<a href="https://www.flipkart.com&/#39;+">https://www.flipkart.com’+</a> a[‘href’])<br> <br> <br> #use the below 2 lines to get single search page<br> a= a_list[0]<br> page_urls.append(‘<a href="https://www.flipkart.com&/#39;+">https://www.flipkart.com&#39;+</a> a[‘href’])</blockquote><p>Once we get the page url link, we need to inspect each product listed in the page as below</p><blockquote>for url in page_urls:<br> print(url)<br> uclient = uReq(url) <br> page_html = uclient.read() <br> uclient.close() <br> psoup = soup(page_html, “html.parser”)</blockquote><blockquote>prod_urls = list() <br> for containers in psoup.findAll(‘div’,{‘class’:’_13oc-S’}): <br> for a in containers:<br> a_list = a.findAll(‘a’,{‘class’:’_1fQZEK’})<br> #print(a_list[‘href’])<br> #prod_urls.append(‘<a href="https://www.flipkart.com&/#39;+">https://www.flipkart.com’+</a> a_list[‘href’])<br> <br> for a in a_list:<br> prod_urls.append(‘<a href="https://www.flipkart.com&/#39;+">https://www.flipkart.com&#39;+</a> a[‘href’])<br> <br> for p_url in prod_urls:<br> uclient = uReq(p_url)<br> page_html = uclient.read() <br> uclient.close()<br> psoup = soup(page_html, “html.parser”) <br> <br> all_procuct_items = psoup.find(‘div’, attrs={‘class’ : ‘_3k-BhJ’})<br> all_procuct_items = all_procuct_items.findAll(‘tr’, attrs={‘class’ : ‘_1s_Smc row’})<br><br> #container variable contains the html of product title which is stored in div tag and class is “_1AtVbE col-12–12” <br> container= psoup.findAll(“div”,{“class”:”_1AtVbE col-12–12&quot;}) <br> for product_item in container: <br> product_dict = dict()<br> rating_dict= dict()<br> price_dict = dict()<br> brandname_dict = dict()<br> n = product_item.findAll(“span”,{“class”:”B_NuCI”}) <br> p = product_item.findAll(“div”,{“class”:”_30jeq3 _16Jk6d”}) <br> <br> r = product_item.findAll(“div”,{“class”:”_2d4LTz”}) <br> for i in n: <br> product_dict[‘name’] = i.text<br> strtmp = i.text.split(“ “)<br> brandname_dict[‘brandname’] = strtmp[0]<br> brandnames_list.append(strtmp[0])<br> products_list.append(i.text)<br> for j in p: <br> jStr = j.text<br> jStr = jStr.replace(“₹”, “”)<br> jStr = jStr.replace(“,”, “”)<br> price_dict[‘price’] = int( jStr)<br> prices_list.append(int( jStr))<br> for k in r: <br> #print (i.text)<br> rating_dict[‘rating’] = k.text <br> ratings_list.append(k.text)</blockquote><p>We can now export data extracted for the details of the products to the csv file using the code below</p><blockquote>df = pd.DataFrame({‘Brand’:brandnames_list,’Price’:prices_list,’Ratings’:ratings_list,’ProductName’:products_list})<br>df.to_csv (‘export_products_dataframe.csv’)</blockquote><p>We can use the box plot ,cat plot and bar plot available in the seaborn module for visualizing the price range of the product as shown in the pictures below,using the code below</p><blockquote>df[‘Price’] = df[‘Price’].astype(np.float)<br>sns.boxplot(x=df[‘Price’])</blockquote><blockquote>sns.catplot(x = “Price”, # x variable name<br> y = “Brand”, # y variable name<br> hue = “Ratings”, # group variable name<br> data = df, # dataframe to plot<br> kind = “bar”)</blockquote><blockquote>df.groupby(‘Brand’).plot(x=’Brand’, y=’Price’)</blockquote><blockquote>sns.barplot(x = ‘Brand’,<br> y = ‘Price’,<br> data = df)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/1*O_XRw3EslY106UsTrRLDqQ.png" /><figcaption>Product listing based on ratings and prices</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/910/1*1IZrNoXleU_OKxF3ojXp5A.png" /><figcaption>Price Range chart</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/1*6agxCn-cCNmmgzO7NkzyEA.png" /><figcaption>Price range chart for the Brand Samsung</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/1*xaBkEyQBSa1LVEuhvJuq8A.png" /><figcaption>Price range chart for the Brand Apple</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=459a363523e4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Overloading in Python]]></title>
            <link>https://chithraprabhap.medium.com/overloading-in-python-73e8ee51d93d?source=rss-d4b96e1ae509------2</link>
            <guid isPermaLink="false">https://medium.com/p/73e8ee51d93d</guid>
            <category><![CDATA[python-programming]]></category>
            <dc:creator><![CDATA[chithra prabha]]></dc:creator>
            <pubDate>Tue, 01 Sep 2020 08:43:54 GMT</pubDate>
            <atom:updated>2020-09-08T00:31:17.051Z</atom:updated>
            <content:encoded><![CDATA[<p>In Object Oriented programming approach the concept of polymorphism is about having a class objects in many forms. Polymorphism is of two types one is static polymorphism and the other is dynamic polymorphism.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*WAaGvf9bC4J4xB5eQSQu9g.png" /></figure><p>Python do not have compile time polymorphism directly, that is because python programs do not use compilation specific to the machine in which they run ,instead the python programs are compiled to be run on a python virtual machine, and hence compilation is not specific to the machine, which makes python portable across platforms,more easier to learn and machine independent ,the picture below gives an overview of the components used to convert a python language program to a running code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/948/1*kRoAIltJroI8eq6mik-efQ.png" /></figure><p><strong>Operator Overloading</strong></p><p>Operator overloading is about having different parameters on one operator, there are operators for arithmetic ,comparison,assignment and binary operation ,each operator for these operations can take different parameters and operate on it based on what type of parameter it is provided with,to perform this the users do not need to write the code every time, instead they can use the inbuilt methods in python,these methods are called magic methods .A few samples of the magic methods are listed below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/447/1*ZnlvCUxSO2Ki1HNeZbPn9A.png" /></figure><p><strong>Function Overloading</strong></p><p>Function overloading is a feature to allow a class to have methods with same name and different parameters,this feature is mainly used to avoid class duplicates. As python don’t have compile time binding ,overloading cannot be done directly, as in python if the function is defined with same name several times, at compile time only the last definition of the function will be taken into account , so overloading a function to have same name and work on different signature is possible only by defining a function to check for argument types inside the function,to make this easier for the users python provides a module called multimethod to help users to do polymorphism in easy way,this module allows users to use overloading feature by adding a decorator ‘@multimethod’ to the function definition ,hence this way the user will be able to define the function with same name and different signatures ,below is a sample using this module.</p><blockquote><strong>from multimethod import multimethod<br>class SuperMarket:</strong></blockquote><blockquote><strong># Class Variable <br> name = “SmartBuy-State1”<br> location = “India”<br> <br> # Instance variables<br> def __init__(self,rack1Count,rack2Count,rack3Count):<br> self.rack1Count = rack1Count<br> self.rack2Count = rack2Count<br> self.rack3Count = rack3Count<br> <br> # Instance method<br> def totalItems(self):<br> return (self.rack1Count+self.rack2Count+self.rack3Count)<br> <br> # Class method <br> </strong><a href="http://twitter.com/classmethod"><strong>@classmethod</strong></a><strong> # This is a decorator<br> def storename(cls):<br> return cls.name</strong></blockquote><blockquote><a href="http://twitter.com/multimethod"><strong>@multimethod</strong></a><strong><br> def printDiscount(self,x: int):<br> print(“The Customer has a shop card with number“,str(x))<br> answer = 10<br> print(“Discount is “,str(answer))</strong></blockquote><blockquote><a href="http://twitter.com/multimethod"><strong>@multimethod</strong></a><strong><br> def printDiscount(self,x: str):<br> print(“The Customer is first time customer with no card number and name as “,str(x))<br> answer = 5<br> print(“Discount is “,str(answer))<br> <br> <br># Instances of the class <br>Shop1 = SuperMarket(10,12,14)<br>Shop1.printDiscount(‘Customer1’)<br>Shop1.printDiscount(123)</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/833/1*6M4t5cxASZocYQU_crVhpw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=73e8ee51d93d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>