<?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 Vagdevi Kommineni on Medium]]></title>
        <description><![CDATA[Stories by Vagdevi Kommineni on Medium]]></description>
        <link>https://medium.com/@vagdevi.k15?source=rss-aa3dd60153ab------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*wmR-ceoAAaCEgd0t.</url>
            <title>Stories by Vagdevi Kommineni on Medium</title>
            <link>https://medium.com/@vagdevi.k15?source=rss-aa3dd60153ab------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 12:06:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vagdevi.k15/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[How to use transfer learning for sign language recognition]]></title>
            <link>https://medium.com/free-code-camp/asl-recognition-using-transfer-learning-918ba054c004?source=rss-aa3dd60153ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/918ba054c004</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[american-sing-language]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Vagdevi Kommineni]]></dc:creator>
            <pubDate>Sun, 10 Mar 2019 18:13:51 GMT</pubDate>
            <atom:updated>2019-04-20T15:38:25.619Z</atom:updated>
            <content:encoded><![CDATA[<p>As a continuation of my previous post on <a href="https://medium.com/@vagdevi.k15/asl-using-alexnet-training-from-scratch-cfec9a8acf84">ASL Recognition using AlexNet — training from scratch</a>, let us now consider how to solve this problem using the transfer learning technique.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*tmh4aAYfP-1SGqpqAaim3w.png" /></figure><p>Transfer learning has become so handy for computer vision geeks.</p><p>It’s basically a mechanism where the knowledge acquired by training a model for achieving a task is efficiently modified or optimized in order to accomplish the second related task.</p><blockquote>One of the powerful tasks of deep learning is that, sometimes we can take the knowlewdge the neural network has learnt from one task (task A) and apply that knowledge in another task (task B). This is called transfer learning.<br> — Andrew Ng</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/259/1*d3lHCtCkbfVambYFrYIfqQ.jpeg" /></figure><p>For example, a neural network trained on object recognition can be used to read x-ray scans. This is achieved by freezing the weights until the initial or mid-layers are learned on the data for task A, removing the last layer or a few of the last layers, and adding new layers and training those parameters using the data for task B.</p><p>Transfer learning makes sense when the data in training for task A is quite large and that of task B is relatively smaller. By getting trained on such vast amounts of data and showing excellent performance on its test data, this implies that the neural network has a good knowledge of extracting useful features from the input images. This is essential and powerful for achieving a task.</p><p>Now that we have such powerful features from these layers (whose weights from task A are frozen), we just need to make use of these extracted features to achieve task B. So, these features from frozen layers are fed to the new layers and the parameters for these layers are trained on the data of task B.</p><p>So basically, we store the knowledge from the previous task in the form of the weights of the frozen layers (called pre-training). Then we make the neural network task B-specific by training (called fine-tuning) the latter layers on the new data. For more information about transfer learning, please visit <a href="https://www.youtube.com/watch?v=yofjFQddwHE">here</a>.</p><p>This technique is really useful because:</p><ul><li>we can bring up a model which performs elegantly for task B, though we have less data available for task B,</li><li>there are fewer parameters to be trained (only last layer/layers) and thus less training time,</li><li>there is less demand for heavy computational resources like GPU, TPU (but still depends on the data available for task B).</li></ul><p>Since this post is the continuation of the previous post about <a href="https://medium.com/@vagdevi.k15/asl-using-alexnet-training-from-scratch-cfec9a8acf84">ASL Recognition using AlexNet — training from scratch</a>, please refer to that post for preprocessing details and the code (preprocess.py).</p><p>The data used for both the posts is this <a href="https://www.kaggle.com/grassknoted/asl-alphabet">Kaggle data for ASL</a>. The dataset consists of images of hand gestures for each letter in the English alphabet. The images of a single class are of different variants, as in zoomed versions, dim and bright light conditions, etc. For each class, there are as many as 3000 images. Here are links for the full code of <a href="https://github.com/vagdevik/American-Sign-Language-Recognition-System/blob/master/4_VGG16_BCVWL/asl_full.py">preprocessing &amp; training </a>and <a href="https://github.com/vagdevik/American-Sign-Language-Recognition-System/blob/master/4_VGG16_BCVWL/predict.py">testing</a>.</p><p>For transfer learning, I have used the VGG16 pre-trained model trained on the ImageNet Dataset. The weights are readily available in keras. We shall first import all the necessary modules as follows:</p><pre>import keras<br>from keras.optimizers import SGD       <br>from keras.models import Sequential <br>from keras.applications import VGG16   <em>#VGG16 pretrained weights</em>    <br>from keras.preprocessing import image<br>from keras.layers.normalization import BatchNormalization<br>from keras.layers import Dense, Activation, Dropout, Flatten,Conv2D, MaxPooling2D</pre><pre>print(&quot;Imported Network Essentials&quot;)</pre><p>Let us now initiate the model to be a sequential one and first add the pre-trained VGG16 network to our model. Note that we need to remove the last layers (called top layers) and freeze the weights of all the previous layers. That’s done by include_top=False . weights=&#39;imagenet’ takes the weights of the VGG16 network trained on the ImageNet Dataset.</p><pre><em>#</em> <em>to fix the input image size</em><br>image_size=224</pre><pre><em># Load the VGG model</em><br>vgg_base = VGG16(weights=&#39;imagenet&#39;,include_top=False,<br>                 input_shape=(image_size,image_size,3))<br>vgg_base.trainable = False</pre><p>Now, the part of VGG16 we want is stored in vgg_base. Setting vgg_base.trainable = False ensures that the layers from the VGG16 are frozen to have the same parameters as learned on the ImageNet database. Thus the knowledge of extracting the powerful features from the images to sufficiently distinguish between the different classes is obtained by using those frozen weights, which is called transfer of knowledge or transfer learning. We shall also add the other layers like dense layers and dropout layers on top of vgg_baseto use the above-obtained knowledge and exclusively learn how to achieve the desired goal of hand gesture classification. Here we basically aim to make use of the prior knowledge of the pre-trained weights of the imported VGG16 network to extract the powerful features and customize the network to learn how to perform well on our target dataset by adding other layers on the top of the imported VGG16 network. Thus the full architecture of the neural network we use shall be:</p><pre>#initiate a model<br>model = Sequential() #Add the VGG base model<br>model.add(vgg_base) #Add new layers<br>model.add(Flatten()) <br>model.add(Dense(8192,activation=&#39;relu&#39;))<br>model.add(Dropout(0.8))<br>model.add(Dense(4096,activation=&#39;relu&#39;))<br>model.add(Dropout(0.5))<br>model.add(Dense(5, activation=&#39;softmax&#39;))</pre><p>We shall next define our optimizer as SGD and set the learning rate lr value. Since this is a categorical classification, we use categorical_crossentropy as the loss function in model.compile. Using checkpoints is the best way to store the weights we got until the point of interruption, so that we may use them later. The first parameter is to set the place to store: save it as weights.{epoch:02d}-{val_loss:.2f}.hdf5 in the Checkpoints folder. We then go for training by using model.fit.</p><pre># Compile <br>sgd = SGD(lr=0.001)<br>model.compile(loss=&#39;categorical_crossentropy&#39;, optimizer=sgd,    metrics=[&#39;accuracy&#39;])<br>checkpoint = keras.callbacks.ModelCheckpoint(&quot;Weights/weights.{epoch:02d}-{val_loss:.2f}.hdf5&quot;, monitor=&#39;val_loss&#39;, verbose=0, save_best_only=False, save_weights_only=False, mode=&#39;auto&#39;, period=1)</pre><pre># Train<br>model.fit(X_train/255.0, Y_train, batch_size=32, epochs=15, verbose=1,validation_data=(X_test/255.0,Y_test/255.0), shuffle=True,callbacks=[checkpoint])</pre><p>We can save the model and weights as follows:</p><pre># serialize model to JSON<br>model_json = model.to_json()<br>with open(&quot;Model/model.json&quot;, &quot;w&quot;) as json_file:<br>    json_file.write(model_json)</pre><pre># serialize weights to HDF5model.save_weights(&quot;Model/model_weights.h5&quot;)print(&quot;Saved model to disk&quot;)</pre><p>Let’s have a look at the whole code for training here:</p><pre><em># train.py</em></pre><pre>import keras<br>from keras.optimizers import SGD       <br>from keras.models import Sequential <br>from keras.applications import VGG16   <em>#VGG16 pretrained weights</em>    <br>from keras.preprocessing import image<br>from keras.layers.normalization import BatchNormalization<br>from keras.layers import Dense, Activation, Dropout, Flatten,Conv2D, MaxPooling2D<br>print(&quot;Imported Network Essentials&quot;)</pre><pre><em>#</em> <em>to fix the input image size</em><br>image_size=224</pre><pre><em># Load the VGG model</em><br>vgg_base = VGG16(weights=&#39;imagenet&#39;,include_top=False,<br>                 input_shape=(image_size,image_size,3))</pre><pre>#initiate a model<br>model = Sequential() #Add the VGG base model<br>model.add(vgg_base) #Add new layers<br>model.add(Flatten()) <br>model.add(Dense(8192,activation=&#39;relu&#39;))<br>model.add(Dropout(0.8))<br>model.add(Dense(4096,activation=&#39;relu&#39;))<br>model.add(Dropout(0.5))<br>model.add(Dense(5, activation=&#39;softmax&#39;))</pre><pre># Compile <br>sgd = SGD(lr=0.001)<br>model.compile(loss=&#39;categorical_crossentropy&#39;, optimizer=sgd,    metrics=[&#39;accuracy&#39;])<br>checkpoint = keras.callbacks.ModelCheckpoint(&quot;Weights/weights.{epoch:02d}-{val_loss:.2f}.hdf5&quot;, monitor=&#39;val_loss&#39;, verbose=0, save_best_only=False, save_weights_only=False, mode=&#39;auto&#39;, period=1)</pre><pre># Train<br>model.fit(X_train/255.0, Y_train, batch_size=32, epochs=15, verbose=1,validation_data=(X_test/255.0,Y_test/255.0), shuffle=True,callbacks=[checkpoint])</pre><pre># serialize model to JSON<br>model_json = model.to_json()<br>with open(&quot;Model/model.json&quot;, &quot;w&quot;) as json_file:<br>    json_file.write(model_json)</pre><pre># serialize weights to HDF5model.save_weights(&quot;Model/model_weights.h5&quot;)print(&quot;Saved model to disk&quot;)</pre><p>Now it’s time for testing! Here’s the way to load the model and trained weights from the stored JSON files and use the evaluation metric accuracy_score from sklearn.metrics .</p><pre><em># test.py</em></pre><pre>import numpy as np<br>from keras.models import model_from_json<br>from sklearn.metrics import accuracy_score </pre><pre><em># dimensions of our images<br></em>image_size = 224 <br>with open(&#39;Model/model.json&#39;, &#39;r&#39;) as f:<br>    model = model_from_json(f.read())  <br>    model.summary()<br>model.load_weights(&#39;Model/model_weights.h5&#39;)</pre><pre><em># loading the numpy test images (feel free to look at preprocessing)</em><br>X_test=np.load(&quot;Numpy/test_set.npy&quot;)<br>Y_test=np.load(&quot;Numpy/test_classes.npy&quot;) </pre><pre><em># getting predictions and getting the maximum of predictions<br># since predictions are of form [0.01, 0.99, 0, 0] in Y_predict and <br># are of the form [0,1,0,0] in Y_test<br></em>Y_predict = model.predict(X_test) <br>Y_predict = [np.argmax(r) for r in Y_predict]<br>Y_test = [np.argmax(r) for r in Y_test] </pre><pre>print(&quot;##################&quot;)<br>acc_score = accuracy_score(Y_test, Y_predict)<br>print(&quot;Accuracy: &quot;+str(acc_score))<br>print(&quot;##################&quot;)</pre><p>I got an accuracy of 97%. You may follow certain steps to improve accuracy like:</p><ul><li>hyperparameter tuning.</li><li>using a different pretrained model like ResNet, VGG19, etc instead of VGG16.</li></ul><p>The full code can be found <a href="https://github.com/vagdevik/American-Sign-Language-Recognition-System/tree/master/3_VGG16_newData">here</a>. I would love to hear your results in the comments section below.</p><p>Happy learning!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=918ba054c004" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/asl-recognition-using-transfer-learning-918ba054c004">How to use transfer learning for sign language recognition</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to build a convolutional neural network that recognizes sign language gestures]]></title>
            <link>https://medium.com/free-code-camp/asl-using-alexnet-training-from-scratch-cfec9a8acf84?source=rss-aa3dd60153ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/cfec9a8acf84</guid>
            <category><![CDATA[alexnet]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[american-sign-language]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[tech]]></category>
            <dc:creator><![CDATA[Vagdevi Kommineni]]></dc:creator>
            <pubDate>Thu, 31 Jan 2019 14:45:22 GMT</pubDate>
            <atom:updated>2019-03-13T16:05:59.461Z</atom:updated>
            <content:encoded><![CDATA[<p>Sign language has been a major boon for people who are hearing- and speech-impaired. But it can serve its purpose only when the other person can understand sign language. Thus it would be really nice to have a system which could convert the hand gesture image to the corresponding English letter. And so the aim of this post is to build such an American Sign Language Recognition System.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*vrcZTOV9qoL_pmjAXC-WsQ.png" /></figure><p>Wikipedia has defined ASL as the following:</p><blockquote><strong>American Sign Language</strong> (<strong>ASL</strong>) is a <a href="https://en.wikipedia.org/wiki/Natural_language">natural language</a> that serves as the predominant <a href="https://en.wikipedia.org/wiki/Sign_language">sign language</a> of <a href="https://en.wikipedia.org/wiki/Deaf_communities">Deaf communities</a> in the United States and most of Anglophone Canada.</blockquote><p>First, the data: it is really important to remember the diversity of image classes with respect to influential factors like lighting conditions, zooming conditions etc. <a href="https://www.kaggle.com/grassknoted/asl-alphabet">Kaggle data on ASL</a> has all such different variants. Training on such data makes sure our model has pretty good knowledge of each class. So, let&#39;s work on the K<a href="https://www.kaggle.com/grassknoted/asl-alphabet">aggle data</a>.</p><p>The dataset consists of the images of hand gestures for each letter in the English alphabet. The images of a single class are of different variants — that is, zoomed versions, dim and bright light conditions, etc. For each class, there are as many as 3000 images. Let us consider classifying “A”, “B” and “C” images in our work for simplicity. Here are links for the full code for <a href="https://github.com/vagdevik/American-Sign-Language-Recognition-System/blob/master/2_AlexNet/asl_full.py">training</a> and <a href="https://github.com/vagdevik/American-Sign-Language-Recognition-System/blob/master/2_AlexNet/predict_full.py">testing</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/265/1*6yZIJcj3P4bmMo-4c2MnJQ.png" /><figcaption>An image for the letter ‘A’ from the dataset</figcaption></figure><p>We are going to build an <a href="https://www.learnopencv.com/understanding-alexnet/">AlexNet</a> to achieve this classification task. Since we are training the CNN, make sure that there is the support of computational resources like GPU.</p><p>We start by importing the necessary modules.</p><pre>import warnings<br>warnings.filterwarnings(&quot;ignore&quot;, category=DeprecationWarning) </pre><pre>import os<br>import cv2<br>import random<br>import numpy as np<br>import keras<br>from random import shuffle<br>from keras.utils import np_utils<br>from shutil import unpack_archive</pre><pre>print(&quot;Imported Modules...&quot;)</pre><p>Download the data zip file from K<a href="https://www.kaggle.com/grassknoted/asl-alphabet">aggle data</a>. Now, let us select the gesture images for A, B, and C and split the obtained data into training data, validation data, and test data.</p><pre><em># data folder path</em><br>data_folder_path = &quot;asl_data/new&quot; <br>files = os.listdir(data_folder_path) </pre><pre><em># shuffling the images in the folder</em><br>for i in range(10): <br>  shuffle(files)</pre><pre>print(&quot;Shuffled Data Files&quot;)</pre><pre><em># dictionary to maintain numerical labels</em><br>class_dic = {&quot;A&quot;:0,&quot;B&quot;:1,&quot;C&quot;:2}</pre><pre><em># dictionary to maintain counts</em><br>class_count = {&#39;A&#39;:0,&#39;B&#39;:0,&#39;C&#39;:0}</pre><pre><em># training lists</em><br>X = []<br>Y = []</pre><pre><em># validation lists</em><br>X_val = []<br>Y_val = []</pre><pre><em># testing lists</em><br>X_test = []<br>Y_test = []</pre><pre>for file_name in files:<br>  label = file_name[0]<br>  if label in class_dict:<br>    path = data_folder_path+&#39;/&#39;+file_name<br>    image = cv2.imread(path)<br>    resized_image = cv2.resize(image,(224,224))<br>    if class_count[label]&lt;2000:<br>      class_count[label]+=1<br>      X.append(resized_image)<br>      Y.append(class_dic[label])<br>    elif class_count[label]&gt;=2000 and class_count[label]&lt;2750:<br>      class_count[label]+=1<br>      X_val.append(resized_image)<br>      Y_val.append(class_dic[label])<br>    else:<br>      X_test.append(resized_image)<br>      Y_test.append(class_dic[label])</pre><p>Each image in the dataset is named according to a naming convention. The 34th image of class A is named as “A_34.jpg”. Hence, we consider only the first element of the name of the file string and check if it is of the desired class.</p><p>Also, we are splitting the images based on counts and storing those images in the X and Y lists — X for image, and Y for the corresponding classes. Here, counts refer to the number of images we wish to put in the training, validation, and test sets respectively. So here, out of 3000 images for each class, I have put 2000 images in the training set, 750 images in the validation set, and the remaining in the test set.</p><p>Some people also prefer to split based on the total dataset (not for each class as we did here), but this doesn’t promise that all classes are learned properly. The images are read and are stored in the form of Numpy arrays in the lists.</p><p>Now the label lists (the Y’s) are encoded to form numerical one-hot vectors. This is done by the np_utils.to_categorical.</p><pre><em># one-hot encodings of the classes<br></em>Y = np_utils.to_categorical(Y)<br>Y_val = np_utils.to_categorical(Y_val)<br>Y_test = np_utils.to_categorical(Y_test)</pre><p>Now, let us store these images in the form of .npy files. Basically, we create separate .npy files to store the images belonging to each set.</p><pre>if not os.path.exists(&#39;Numpy_folder&#39;):<br>    os.makedirs(&#39;Numpy_folder&#39;)</pre><pre>np.save(npy_data_path+&#39;/train_set.npy&#39;,X)<br>np.save(npy_data_path+&#39;/train_classes.npy&#39;,Y)</pre><pre>np.save(npy_data_path+&#39;/validation_set.npy&#39;,X_val)<br>np.save(npy_data_path+&#39;/validation_classes.npy&#39;,Y_val)</pre><pre>np.save(npy_data_path+&#39;/test_set.npy&#39;,X_test)<br>np.save(npy_data_path+&#39;/test_classes.npy&#39;,Y_test)</pre><pre>print(&quot;Data pre-processing Success!&quot;)</pre><p>Now that we have completed the data preprocessing part, let us take a look at the full data preprocessing code here:</p><pre><em># preprocess.py</em></pre><pre>import warnings<br>warnings.filterwarnings(&quot;ignore&quot;, category=DeprecationWarning)</pre><pre>import os<br>import cv2<br>import random<br>import numpy as np<br>import keras<br>from random import shuffle<br>from keras.utils import np_utils<br>from shutil import unpack_archive</pre><pre>print(&quot;Imported Modules...&quot;)</pre><pre><em># data folder path</em><br>data_folder_path = &quot;asl_data/new&quot; <br>files = os.listdir(data_folder_path)</pre><pre><em># shuffling the images in the folder</em><br>for i in range(10): <br>  shuffle(files)</pre><pre>print(&quot;Shuffled Data Files&quot;)</pre><pre><em># dictionary to maintain numerical labels</em><br>class_dic = {&quot;A&quot;:0,&quot;B&quot;:1,&quot;C&quot;:2}</pre><pre><em># dictionary to maintain counts</em><br>class_count = {&#39;A&#39;:0,&#39;B&#39;:0,&#39;C&#39;:0}</pre><pre><em># training lists</em><br>X = []<br>Y = []</pre><pre><em># validation lists</em><br>X_val = []<br>Y_val = []</pre><pre><em># testing lists</em><br>X_test = []<br>Y_test = []</pre><pre>for file_name in files:<br>  label = file_name[0]<br>  if label in class_dict:<br>    path = data_folder_path+&#39;/&#39;+file_name<br>    image = cv2.imread(path)<br>    resized_image = cv2.resize(image,(224,224))<br>    if class_count[label]&lt;2000:<br>      class_count[label]+=1<br>      X.append(resized_image)<br>      Y.append(class_dic[label])<br>    elif class_count[label]&gt;=2000 and class_count[label]&lt;2750:<br>      class_count[label]+=1<br>      X_val.append(resized_image)<br>      Y_val.append(class_dic[label])<br>    else:<br>      X_test.append(resized_image)<br>      Y_test.append(class_dic[label])</pre><pre><em># one-hot encodings of the classes<br></em>Y = np_utils.to_categorical(Y)<br>Y_val = np_utils.to_categorical(Y_val)<br>Y_test = np_utils.to_categorical(Y_test)</pre><pre>if not os.path.exists(&#39;Numpy_folder&#39;):<br>    os.makedirs(&#39;Numpy_folder&#39;)</pre><pre>np.save(npy_data_path+&#39;/train_set.npy&#39;,X)<br>np.save(npy_data_path+&#39;/train_classes.npy&#39;,Y)</pre><pre>np.save(npy_data_path+&#39;/validation_set.npy&#39;,X_val)<br>np.save(npy_data_path+&#39;/validation_classes.npy&#39;,Y_val)</pre><pre>np.save(npy_data_path+&#39;/test_set.npy&#39;,X_test)<br>np.save(npy_data_path+&#39;/test_classes.npy&#39;,Y_test)</pre><pre>print(&quot;Data pre-processing Success!&quot;)</pre><p>Now comes the training part! Let us start by importing the essential modules so we can construct and train the CNN AlexNet. Here it is primarily done using Keras.</p><pre><em># importing </em><br>from keras.optimizers import SGD<br>from keras.models import Sequential<br>from keras.preprocessing import image<br>from keras.layers.normalization import BatchNormalization<br>from keras.layers import Dense, Activation, Dropout, Flatten,Conv2D, MaxPooling2D</pre><pre>print(&quot;Imported Network Essentials&quot;)</pre><p>We next go for loading the images stored in the form of .npy:</p><pre>X_train=np.load(npy_data_path+&quot;/train_set.npy&quot;)<br>Y_train=np.load(npy_data_path+&quot;/train_classes.npy&quot;)</pre><pre>X_valid=np.load(npy_data_path+&quot;/validation_set.npy&quot;)<br>Y_valid=np.load(npy_data_path+&quot;/validation_classes.npy&quot;)</pre><pre>X_test=np.load(npy_data_path+&quot;/test_set.npy&quot;)<br>Y_test=np.load(npy_data_path+&quot;/test_classes.npy&quot;)</pre><p>We then head towards defining the structure of our CNN. Assuming prior knowledge of the <a href="https://www.learnopencv.com/understanding-alexnet/">AlexNet</a> architecture, here is the Keras code for that.</p><pre>model = Sequential()</pre><pre># 1st Convolutional Layer<br>model.add(Conv2D(filters=96, input_shape=(224,224,3), kernel_size=(11,11),strides=(4,4), padding=&#39;valid&#39;))<br>model.add(Activation(&#39;relu&#39;))</pre><pre># Max Pooling <br>model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding=&#39;valid&#39;))</pre><pre># Batch Normalisation before passing it to the next layer<br>model.add(BatchNormalization())</pre><pre># 2nd Convolutional Layer<br>model.add(Conv2D(filters=256, kernel_size=(11,11), strides=(1,1), padding=&#39;valid&#39;))<br>model.add(Activation(&#39;relu&#39;))</pre><pre># Max Pooling<br>model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding=&#39;valid&#39;))</pre><pre># Batch Normalisation<br>model.add(BatchNormalization())</pre><pre># 3rd Convolutional Layer<br>model.add(Conv2D(filters=384, kernel_size=(3,3), strides=(1,1), padding=&#39;valid&#39;))<br>model.add(Activation(&#39;relu&#39;))</pre><pre># Batch Normalisation<br>model.add(BatchNormalization())</pre><pre># 4th Convolutional Layer<br>model.add(Conv2D(filters=384, kernel_size=(3,3), strides=(1,1), padding=&#39;valid&#39;))<br>model.add(Activation(&#39;relu&#39;))</pre><pre># Batch Normalisation<br>model.add(BatchNormalization())</pre><pre># 5th Convolutional Layer<br>model.add(Conv2D(filters=256, kernel_size=(3,3), strides=(1,1), padding=&#39;valid&#39;))<br>model.add(Activation(&#39;relu&#39;))</pre><pre># Max Pooling<br>model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding=&#39;valid&#39;))</pre><pre># Batch Normalisation<br>model.add(BatchNormalization())</pre><pre># Passing it to a dense layer<br>model.add(Flatten())</pre><pre># 1st Dense Layer<br>model.add(Dense(4096, input_shape=(224*224*3,)))<br>model.add(Activation(&#39;relu&#39;))</pre><pre># Add Dropout to prevent overfitting<br>model.add(Dropout(0.4))</pre><pre># Batch Normalisation<br>model.add(BatchNormalization())</pre><pre># 2nd Dense Layer<br>model.add(Dense(4096))<br>model.add(Activation(&#39;relu&#39;))</pre><pre># Add Dropout<br>model.add(Dropout(0.6))</pre><pre># Batch Normalisation<br>model.add(BatchNormalization())</pre><pre># 3rd Dense Layer<br>model.add(Dense(1000))<br>model.add(Activation(&#39;relu&#39;))</pre><pre># Add Dropout<br>model.add(Dropout(0.5))</pre><pre># Batch Normalisation<br>model.add(BatchNormalization())</pre><pre># Output Layer<br>model.add(Dense(24))<br>model.add(Activation(&#39;softmax&#39;))</pre><pre>model.summary()</pre><p>The Sequential model is a linear stack of layers. We add the convolutional layers (applying filters), activation layers (for non-linearity), max-pooling layers (for computational efficiency) and batch normalization layers (to standardize the input values from the previous layer to the next layer) and the pattern is repeated five times.</p><p>The Batch Normalization layer was introduced in 2014 by Ioffe and Szegedy. It addresses the vanishing gradient problem by standardizing the output of the previous layer, it speeds up the training by reducing the number of required iterations, and it enables the training of deeper neural networks.</p><p>At last, 3 fully-connected dense layers along with dropouts (to avoid over-fitting) are added.</p><p>To get the summarized description of the model, use model.summary().</p><p>The following is the code for the compilation part of the model. We define the optimization method to follow as SGD and set the parameters.</p><pre># Compile <br>sgd = SGD(lr=0.001)</pre><pre>model.compile(loss=&#39;categorical_crossentropy&#39;, optimizer=sgd, metrics=[&#39;accuracy&#39;])</pre><pre>checkpoint = keras.callbacks.ModelCheckpoint(&quot;Checkpoint/weights.{epoch:02d}-{val_loss:.2f}.hdf5&quot;, monitor=&#39;val_loss&#39;, verbose=0, </pre><pre>save_best_only=False, save_weights_only=False, mode=&#39;auto&#39;, period=1)</pre><p>lr in SGD is the learning rate. Since this is a categorical classification, we use categorical_crossentropy as the loss function in model.compile. We set the optimizer to be sgd<em>, </em>the SGD object we have defined and set the evaluation metric to be accuracy.</p><p>While using GPU, sometimes it may happen to interrupt its running. Using checkpoints is the best way to store the weights we had gotten up to the point of interruption, so that we may use them later. The first parameter is to set the place to store: save it as weights.{epoch:02d}-{val_loss:.2f}.hdf5 in the Checkpoints folder.</p><p>Finally, we save the model in the json format and weights in .h5 format. These are thus saved locally in the specified folders.</p><pre># serialize model to JSON<br>model_json = model.to_json()<br>with open(&quot;Weights_Full/model.json&quot;, &quot;w&quot;) as json_file:<br>    json_file.write(model_json)</pre><pre># serialize weights to HDF5<br>model.save_weights(&quot;Weights_Full/model_weights.h5&quot;)<br>print(&quot;Saved model to disk&quot;)</pre><p>Let’s look at the whole code of defining and training the network. Consider this as a separate file ‘training.py’.</p><pre>#<em> training.py</em></pre><pre>from keras.optimizers import SGD<br>from keras.models import Sequential<br>from keras.preprocessing import image<br>from keras.layers.normalization import BatchNormalization<br>from keras.layers import Dense, Activation, Dropout, Flatten,Conv2D, MaxPooling2D</pre><pre>print(&quot;Imported Network Essentials&quot;)</pre><pre><em># loading .npy dataset</em><br>X_train=np.load(npy_data_path+&quot;/train_set.npy&quot;)<br>Y_train=np.load(npy_data_path+&quot;/train_classes.npy&quot;)</pre><pre>X_valid=np.load(npy_data_path+&quot;/validation_set.npy&quot;)<br>Y_valid=np.load(npy_data_path+&quot;/validation_classes.npy&quot;)</pre><pre>X_test=np.load(npy_data_path+&quot;/test_set.npy&quot;)<br>Y_test=np.load(npy_data_path+&quot;/test_classes.npy&quot;)</pre><pre>X_test.shape</pre><pre><br>model = Sequential()<br># 1st Convolutional Layer<br>model.add(Conv2D(filters=96, input_shape=(224,224,3), kernel_size=(11,11),strides=(4,4), padding=&#39;valid&#39;))<br>model.add(Activation(&#39;relu&#39;))<br># Pooling <br>model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding=&#39;valid&#39;))<br># Batch Normalisation before passing it to the next layer<br>model.add(BatchNormalization())</pre><pre># 2nd Convolutional Layer<br>model.add(Conv2D(filters=256, kernel_size=(11,11), strides=(1,1), padding=&#39;valid&#39;))<br>model.add(Activation(&#39;relu&#39;))<br># Pooling<br>model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding=&#39;valid&#39;))<br># Batch Normalisation<br>model.add(BatchNormalization())</pre><pre># 3rd Convolutional Layer<br>model.add(Conv2D(filters=384, kernel_size=(3,3), strides=(1,1), padding=&#39;valid&#39;))<br>model.add(Activation(&#39;relu&#39;))<br># Batch Normalisation<br>model.add(BatchNormalization())</pre><pre># 4th Convolutional Layer<br>model.add(Conv2D(filters=384, kernel_size=(3,3), strides=(1,1), padding=&#39;valid&#39;))<br>model.add(Activation(&#39;relu&#39;))<br># Batch Normalisation<br>model.add(BatchNormalization())</pre><pre># 5th Convolutional Layer<br>model.add(Conv2D(filters=256, kernel_size=(3,3), strides=(1,1), padding=&#39;valid&#39;))<br>model.add(Activation(&#39;relu&#39;))<br># Pooling<br>model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding=&#39;valid&#39;))<br># Batch Normalisation<br>model.add(BatchNormalization())</pre><pre># Passing it to a dense layer<br>model.add(Flatten())<br># 1st Dense Layer<br>model.add(Dense(4096, input_shape=(224*224*3,)))<br>model.add(Activation(&#39;relu&#39;))<br># Add Dropout to prevent overfitting<br>model.add(Dropout(0.4))<br># Batch Normalisation<br>model.add(BatchNormalization())</pre><pre># 2nd Dense Layer<br>model.add(Dense(4096))<br>model.add(Activation(&#39;relu&#39;))<br># Add Dropout<br>model.add(Dropout(0.6))<br># Batch Normalisation<br>model.add(BatchNormalization())</pre><pre># 3rd Dense Layer<br>model.add(Dense(1000))<br>model.add(Activation(&#39;relu&#39;))<br># Add Dropout<br>model.add(Dropout(0.5))<br># Batch Normalisation<br>model.add(BatchNormalization())</pre><pre># Output Layer<br>model.add(Dense(24))<br>model.add(Activation(&#39;softmax&#39;))</pre><pre>model.summary()</pre><pre># (4) Compile <br>sgd = SGD(lr=0.001)<br>model.compile(loss=&#39;categorical_crossentropy&#39;, optimizer=sgd, metrics=[&#39;accuracy&#39;])<br>checkpoint = keras.callbacks.ModelCheckpoint(&quot;Checkpoint/weights.{epoch:02d}-{val_loss:.2f}.hdf5&quot;, monitor=&#39;val_loss&#39;, verbose=0, save_best_only=False, save_weights_only=False, mode=&#39;auto&#39;, period=1)<br># (5) Train<br>model.fit(X_train/255.0, Y_train, batch_size=32, epochs=50, verbose=1,validation_data=(X_valid/255.0,Y_valid/255.0), shuffle=True,callbacks=[checkpoint])</pre><pre># serialize model to JSON<br>model_json = model.to_json()<br>with open(&quot;Weights_Full/model.json&quot;, &quot;w&quot;) as json_file:<br>    json_file.write(model_json)<br># serialize weights to HDF5<br>model.save_weights(&quot;Weights_Full/model_weights.h5&quot;)<br>print(&quot;Saved model to disk&quot;)</pre><p>When we run the training.py file, we get to see something as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*suIEGgP4_A3lDrG07nSI3Q.png" /></figure><p>For example, considering the first epoch of 12(Epoch 1/12):</p><ul><li>it took 1852s to complete that epoch</li><li>the training loss was 0.2441</li><li>accuracy was 0.9098 on the validation data</li><li>0.0069 was the validation loss, and</li><li>0.9969 was the validation accuracy.</li></ul><p>So based on these values, we know the parameters of which epochs are performing better, where to stop training, and how to tune the hyperparameter values.</p><p>Now it’s time for testing!</p><pre><em># test.py</em></pre><pre>import warnings<br>warnings.filterwarnings(&quot;ignore&quot;, category=DeprecationWarning) <br>from keras.preprocessing import image<br>import numpy as np<br>from keras.models import model_from_json<br>from sklearn.metrics import accuracy_score </pre><pre># dimensions of our images<br>image_size = 224 </pre><pre># <em>load the model in json format</em><br>with open(&#39;Model/model.json&#39;, &#39;r&#39;) as f:<br>    model = model_from_json(f.read())<br>    model.summary()<br>model.load_weights(&#39;Model/model_weights.h5&#39;)<br>model.load_weights(&#39;Weights/weights.250-0.00.hdf5&#39;) </pre><pre>X_test=np.load(&quot;Numpy/test_set.npy&quot;)<br>Y_test=np.load(&quot;Numpy/test_classes.npy&quot;)</pre><pre>Y_predict = model.predict(X_test)<br>Y_predict = [np.argmax(r) for r in Y_predict]</pre><pre>Y_test = [np.argmax(r) for r in Y_test] </pre><pre>print(&quot;##################&quot;)<br>acc_score = accuracy_score(Y_test, Y_predict)<br>print(&quot;Accuracy: &quot; + str(acc_score))<br>print(&quot;##################&quot;)</pre><p>From the above code, we load the saved model architecture and the best weights. Also, we load the .npy files (the Numpy form of the test set) and go for the prediction of these test set of images. In short, we just load the saved model architecture and assign it the learned weights.</p><p>Now the approximator function along with the learned coefficients (weights) is ready. We just need to test it by feeding the model with the test set images and evaluating its performance on this test set. One of the famous evaluation metrics is accuracy. The accuracy is given by <em>accuracy_score </em>of sklearn.metrics.</p><p>Thank you for reading! Happy learning! :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cfec9a8acf84" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/asl-using-alexnet-training-from-scratch-cfec9a8acf84">How to build a convolutional neural network that recognizes sign language gestures</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to TensorFlow]]></title>
            <link>https://medium.com/@vagdevi.k15/introduction-to-tensorflow-f300127ee789?source=rss-aa3dd60153ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/f300127ee789</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[tensorflow]]></category>
            <dc:creator><![CDATA[Vagdevi Kommineni]]></dc:creator>
            <pubDate>Wed, 28 Nov 2018 17:08:36 GMT</pubDate>
            <atom:updated>2018-11-29T06:56:42.301Z</atom:updated>
            <content:encoded><![CDATA[<p>If you were involved in any data science or especially machine learning discussions, many a time, “Tensorflow” must have buzzed so much in your years. Here is a small introduction to that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ockRxLunwRDQI89eiiNlUA.png" /></figure><p>Machine learning and deep learning algorithms are quite fascinating. To simplify coding such algorithms, particularly that of the neural networks, the team of Google Brain has come up with this brilliant framework. It is simply a machine learning framework for everyone. The official tensorflow <a href="https://www.tensorflow.org/">website</a> says,</p><p>“TensorFlow™ is an open source software library for high-performance numerical computation. Its flexible architecture allows easy deployment of computation across a variety of platforms (CPUs, GPUs, TPUs), and from desktops to clusters of servers to mobile and edge devices. Originally developed by researchers and engineers from the Google Brain team within Google’s AI organization, it comes with strong support for machine learning and deep learning and the flexible numerical computation core is used across many other scientific domains.”</p><p>Thus tensorflow is an open source library to make it easier for the developers to design, develop and train deep learning models or neural networks.</p><p>Now, let us dive into more technical details. In tensorflow, a tensor is a data structure used to represent all the data. Tensors are multi-dimensional arrays. A tensor of 0 dimensions is a scalar value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*viOuTtb-44YxxhhPxItEWQ.png" /><figcaption>n-dimensional tensors</figcaption></figure><p>In tensorflow system, tensors are described by a unit of dimensionality known as rank.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/905/1*qFQj3jcEVNlZRxa7YMCAmw.png" /><figcaption>Examples of rank of tensors</figcaption></figure><p>Tensors also have different datatypes along with dimensionality. We can assign any of these datatypes to a tensor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/895/1*irF6rTfibWiy5M5EV7ap6A.png" /><figcaption>Datatypes in tensorflow</figcaption></figure><p>We don’t need to explicitly mention the datatypes we are assigning. But if we know about the datatype beforehand, we can readily assign the datatype by mentioning it as shown before and thus can save memory in that way.</p><p>Tensorflow works by</p><ol><li>first defining and describing our model in abstract</li><li>then we calculate in reality running the graph in a session.</li></ol><p>This description of the model is known as a computational graph in tensorflow. A computational graph is a series of tensorflow operations arranged into a graph of nodes. Only tensors may be passed between the nodes in the computation graph. It works by the flow of tensors in the computational graph, hence the name tensorflow.</p><p>When we just define the abstract model and run the code, the operations are created. Calculations are done only when we run the session(tf.Session()).</p><p>Session places the graph operations onto devices such as CPUs or GPUs and provides methods to execute them.</p><p>This is a small introduction to tensorflow just to understand the working. <a href="https://github.com/vagdevik/TensorFlow-NoteBook/blob/master/TensorFlow.ipynb">This </a>is the link to the hands-on tutorial on the basic-level implementation of tensorflow.</p><p>Thank you! Have a happy learning!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f300127ee789" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CORRELATION VS CAUSATION]]></title>
            <link>https://medium.com/free-code-camp/correlation-vs-causation-c0ff010cd077?source=rss-aa3dd60153ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0ff010cd077</guid>
            <category><![CDATA[correlation]]></category>
            <category><![CDATA[correlation-vs-causation]]></category>
            <category><![CDATA[causation]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[statistics]]></category>
            <dc:creator><![CDATA[Vagdevi Kommineni]]></dc:creator>
            <pubDate>Mon, 15 Oct 2018 20:42:39 GMT</pubDate>
            <atom:updated>2019-03-15T06:20:30.986Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*lIzqF0thjtNwLGbXF9ZkCQ.jpeg" /></figure><p>We commonly come across these two terms in almost all walks of our lives related to statistics. There is also a misconception about their implication. Let’s look at what they are:</p><p><strong>Correlation</strong> is a statistical measure, indicating the size and direction of a relationship between two variables.</p><p><strong>Causation</strong> indicates that the occurrence of one event is the result of the occurrence of another event; implying the causal relationship between the two variables.</p><p>It is worth noting that <strong>correlation does not imply causation</strong>.</p><p>For example, sales of ice-creams and sales of sun-screen lotions would be in correlation. They both are relatively higher during summers than in any other seasons. Though they exhibit high correlation, it is really common sense to think that neither of them is the cause of the occurrence of the others. The cause of the both is the summer being very hot. Consider more examples below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/290/0*kwSnf6NV1ofgbOTi" /><figcaption>An intuition of Correlation and Causation</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/305/0*VTFT_jIhjm2GzfRk" /><figcaption>Example</figcaption></figure><p>Correlation is generally denoted by ‘r’ and its value lies in [-1,1].</p><p>If the correlation coefficient of the two variables is 1, they are positively correlated, meaning that both of their values increase or decrease simultaneously.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*TXPPu4JOd0lbmksb0xKDDw.jpeg" /></figure><p>If the correlation coefficient of the two variables is -1, they are negatively correlated, meaning that one of their values increases while that of the other’s decreases simultaneously.</p><p>If the coefficient of the two variables is 0, then there is no relation between the two variables.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0ff010cd077" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/correlation-vs-causation-c0ff010cd077">CORRELATION VS CAUSATION</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Image Stitching Using OpenCV]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/data-science/image-stitching-using-opencv-817779c86a83?source=rss-aa3dd60153ab------2"><img src="https://cdn-images-1.medium.com/max/1583/1*GHulYZ91NWfYNA2cC-QtYA.jpeg" width="1583"></a></p><p class="medium-feed-snippet">As you know, the Google photos app has stunning automatic features like video making, panorama stitching, collage making, sorting out pic&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/data-science/image-stitching-using-opencv-817779c86a83?source=rss-aa3dd60153ab------2">Continue reading on TDS Archive »</a></p></div>]]></description>
            <link>https://medium.com/data-science/image-stitching-using-opencv-817779c86a83?source=rss-aa3dd60153ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/817779c86a83</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[image-stitching]]></category>
            <category><![CDATA[opencv]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[computer-vision]]></category>
            <dc:creator><![CDATA[Vagdevi Kommineni]]></dc:creator>
            <pubDate>Thu, 11 Oct 2018 19:55:17 GMT</pubDate>
            <atom:updated>2020-11-14T11:29:53.871Z</atom:updated>
        </item>
    </channel>
</rss>