<?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 g meghana reddy on Medium]]></title>
        <description><![CDATA[Stories by g meghana reddy on Medium]]></description>
        <link>https://medium.com/@meghana97g?source=rss-abbb54199dab------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*EG05nBzRPSye8QKQ.jpg</url>
            <title>Stories by g meghana reddy on Medium</title>
            <link>https://medium.com/@meghana97g?source=rss-abbb54199dab------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 21:00:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@meghana97g/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[Classification of Tumor tissue using Deep Learning (Fastai)]]></title>
            <link>https://medium.com/@meghana97g/classification-of-tumor-tissue-using-deep-learning-fastai-77252ae16045?source=rss-abbb54199dab------2</link>
            <guid isPermaLink="false">https://medium.com/p/77252ae16045</guid>
            <category><![CDATA[medical-imaging]]></category>
            <category><![CDATA[healthcare]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[g meghana reddy]]></dc:creator>
            <pubDate>Sun, 18 Nov 2018 17:07:48 GMT</pubDate>
            <atom:updated>2018-11-18T17:07:48.556Z</atom:updated>
            <content:encoded><![CDATA[<p>As part of the <a href="https://www.fast.ai/">fastai [1]</a> course, we worked on a project which involved building a classifier using the fastai library. The problem we focused on involves classification on a pathological dataset with patches of WSI (Whole Slide Image) of tumors.</p><p>The PatchCamelyon (PCam) image classification dataset is extracted from the histopathological scans of lymph node sections. Each image is annotated with a binary label indicating presence of metastatic tissue. PCam dataset is derived from <a href="https://camelyon16.grand-challenge.org/">Camelyon [2]</a> dataset by extracting patches from it. The size of the dataset is greater than CIFAR-10 but also smaller than the likes of ImageNet, etc allowing us to train on a single GPU. The Camelyon dataset is for tumor detection and WSI diagnosis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/453/1*MAAzPX-f5uejYE2e2jsXeA.png" /><figcaption>Annotated Images from PCam dataset</figcaption></figure><p>We plan to augment the input images with various transforms including flipping, rotating, change in contrast, horizontal and vertical shifts. In pathology images along with horizontal flip vertical flip is also important.This is because the slides can also be viewed upside down. Hence, data augmentation is useful. It also helps in providing more data which in turns helps us train deep learning models easily and also help it generalize well.</p><p>Since the dataset is smaller in size, we fine tune an existing model to make it suitable for our classification task. This is called Transfer Learning where we leverage the pre-trained models which already learnt the nuances of the data and tune it for our task. In convolutional neural networks, we essentially make use of the filters in lower layers (close to input) which would be activated for edges, curves, etc. Here we have chosen Resnet-50 [3] as our pre-trained model.</p><p>The first step before training the model is to preprocess the dataset and make it suitable to train the model on. We load the data using <em>ImageDataBunch</em> method. Using the <em>get_transforms</em> method in fastai library we applied transforms on the dataset and we also normalized the dataset using the ImageNet statistics. Normalization involves subtracting the mean (of ImageNet dataset) from the pixel intensity values and dividing the result by standard deviation (of ImageNet dataset).</p><pre>bs = 64 # Batch size<br>data = ImageDataBunch.from_folder(path_img, ds_tfms=get_transforms(flip_vert=True), size=96, bs=bs) \ .normalize(imagenet_stats)</pre><p>There is a function called learning rate finder — <em>lr_find()</em> which helps in deciding the learning rate to be used during training. How does it work? It applies a range of learning rates and calculates the loss which helps us in deciding the learning rate that would yield us low training and validation loses. This was plotted using <em>{learner}.recorder.plot()</em> function which helped us look at the effect of a range of learning rates. We will look at an example in a while.</p><pre>learn.lr_find()<br>learn.recorder.plot()</pre><p>Using the create_cnn method we created a learner. The model is based on Resnet-50 where we remove the final layer and replace it with a output layer predicting whether the input image patch has a tumor tissue or not. Afterwards we used fit_one_cycle method to train the model for 10 epochs with a learning rate of 2e-5.</p><p>How did we choose this learning rate? Learning rate finder has the answer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/395/1*E5i8O5lXO66VY1L2ruW1Fw.png" /><figcaption>Output graph of lr_find showing loss vs learning rate</figcaption></figure><p>We need to observe the point where the loss shoots up and choose a learning rate which is lower than this point and for which the error is low in the region of descent.</p><p>After training for 10 epochs we observed that the validation loss and the training loss decreased along with the error rate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/375/1*oIKG6fGFk5fDXNUBB2SHyw.png" /><figcaption>Plot of training and validation loss vs number of iterations (Number of iterations in an epoch = number of training samples / batch size)</figcaption></figure><p>Now we unfreeze the model which means now if you train you will also affect the weights of Resnet layers. Previously we trained only the output layer, Since the Resnet layers were trained on ImageNet dataset it has the low level information like edges and contours. We don’t want to lose such information since this low level information (and hence the filters) are common for most of the vision data. Hence the learning rate for these layers should be lower whereas for the final layers (layers closer to output), the learning rate should be higher.</p><p>Now after unfreezing when we plot the loss vs learning rate curve we observe that the error shoots up at around 1e-4. Hence as discussed above we need to select a range of learning rates where the initial Resnet layers are trained on a smaller lr and later layers with a higher lr. Normally it’s better to choose a lr which is 10 times lesser than the point where the lr shoots up that is 1e-5. And the upper limit is chosen to be ⅕ th of the earlier lr that is ⅕ th of 2e-5. It is not a hard rule but a practitioner’s observation.</p><pre>lr=2e-2 # From previous graph<br>learn.fit_one_cycle(10,slice(1e-5,lr/5))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/402/1*HG4K_dsX9kmPhdhtirQ3zw.png" /><figcaption>Output of learning rate finder after unfreezing all layers of the model</figcaption></figure><p>After training for 10 more epochs we could see that the training loss is decreasing but validation loss is pretty much the same and the error is fluctuations around 14% error rate. Hence it’s better to stop training otherwise we may overfit.</p><p>After we trained the model for a total of 20 epochs (before and after unfreezing), we saved this model.</p><p>How to calculate the accuracy of the model on PCam?</p><p>We need to run the model for the test data to know the accuracy of the model. The model we trained has an accuracy of 83.64% on the test dataset. The state of the art accuracy is 89.3% which uses <a href="http://arxiv.org/abs/1806.03962">G-CNN dense net architecture ^4.</a></p><p>With just 20 epochs of training and fine-tuning Resnet-50 we achieved 83.64% accuracy on the test dataset.</p><p>References:</p><p>[1] <a href="https://www.fast.ai/">https://www.fast.ai/</a></p><p>[2] <a href="https://camelyon16.grand-challenge.org/">https://camelyon16.grand-challenge.org/</a></p><p>[3] <a href="https://arxiv.org/abs/1512.03385">https://arxiv.org/abs/1512.03385</a></p><p>[4] <a href="http://arxiv.org/abs/1806.03962">http://arxiv.org/abs/1806.03962</a></p><p>Authors:</p><p>Kranthi Kiran GV <a href="https://twitter.com/kranthigv">@KranthiGV</a></p><p>G Meghana Reddy <a href="https://twitter.com/GMeghanaReddy">@GMeghanaReddy</a></p><p>We love building stuff :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=77252ae16045" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>