<?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 Vijay Prakash Dwivedi on Medium]]></title>
        <description><![CDATA[Stories by Vijay Prakash Dwivedi on Medium]]></description>
        <link>https://medium.com/@vijay_16266?source=rss-d19a629e87b2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*6cn0W4tTyqSLYBnW.jpg</url>
            <title>Stories by Vijay Prakash Dwivedi on Medium</title>
            <link>https://medium.com/@vijay_16266?source=rss-d19a629e87b2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 04:31:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vijay_16266/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[Object Detection with Mask RCNN on TensorFlow]]></title>
            <link>https://blog.francium.tech/object-detection-on-documents-with-mask-rcnn-on-tensorflow-c7556654c167?source=rss-d19a629e87b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/c7556654c167</guid>
            <category><![CDATA[object-detection]]></category>
            <category><![CDATA[tensorflow]]></category>
            <category><![CDATA[instance-segmentation]]></category>
            <category><![CDATA[boundaries]]></category>
            <category><![CDATA[computer-vision]]></category>
            <dc:creator><![CDATA[Vijay Prakash Dwivedi]]></dc:creator>
            <pubDate>Fri, 28 Dec 2018 11:32:09 GMT</pubDate>
            <atom:updated>2018-12-28T11:34:01.278Z</atom:updated>
            <content:encoded><![CDATA[<p>Detecting objects is one of the elementary problems in the Computer vision world. This is very crucial and often falls under the initial layers determining the Quality of data.</p><p>We developed a <strong>Machine Learning tool</strong> to <strong>detect stamps</strong> in attested documents. And by “detect”, we not only mean identifying the presence of a stamp in a document or just drawing bounding box (rectangle) around it. We were able to locate and detect a stamp to the exact shape it was present in a document.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/536/1*-wVdGq8PdpehzopPTn4neA.png" /><figcaption>Sample from the Stamp Detection. Original Image was taken from publicly available Google Images Search.</figcaption></figure><blockquote>In Machine Learning, this task is precisely termed as <strong>Instance Segmentation</strong>, a sub task and perhaps the most important one in Object Detection. We achieved this using the <strong>Mask-RCNN algorithm</strong> on TensorFlow Object Detection API.</blockquote><h4>Motivation</h4><p>The main motivation behind this work was to come up with a solution which can find exact masks of any target object a user wants to detect in an image. <br>If you want to find potholes on roadways, we can do it. If you want to detect damages in your home appliances, it&#39;s the same solution. If you want to recognize wine glasses in images, or any other domain-specific target you would want to detect, we can port the same tool for numerous other problems of similar nature.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*vasbP5EUs4XsP8vgRWwENw.jpeg" /><figcaption>Detecting wine glasses (red masks). Original Image Source: GettyImages</figcaption></figure><p>To begin with, we thought of using Mask RCNN to detect wine glasses in an image and apply a red mask on each. For this, we used a pre-trained mask_rcnn_inception_v2_coco model from the <a href="https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo.md"><strong>TensorFlow Object Detection Model Zoo</strong></a> and used <strong>OpenCV</strong>’s <strong>DNN module </strong>to run the frozen graph file with the weights trained on the <a href="http://mscoco.org/">COCO dataset</a>.</p><pre><em># Load text graph and weight files for the model<br></em>text_graph = &#39;./mask_rcnn_inception_v2_coco_2018_01_28.pbtxt&#39;<br>model_weights = &#39;./mask_rcnn_inception_v2_coco_2018_01_28/frozen_inference_graph.pb&#39;</pre><pre><em># Load network<br></em>net = cv.dnn.readNetFromTensorflow(model_weights, text_graph)<br>net.setPreferableBackend(cv.dnn.DNN_BACKEND_OPENCV)<br>net.setPreferableTarget(cv.dnn.DNN_TARGET_CPU)</pre><p>The Image is computed with this net object to detect the instances of wine glasses. We pass the image path as an arg --image while running this Python file.</p><pre>cap = cv.VideoCapture(args.image)<br>has_frame, frame = cap.read()</pre><pre><em># create a 4D blob from  a frame<br></em>blob = cv.dnn.blobFromImage(frame, swapRB=True, crop=False)</pre><pre># set input to the network<br>net.setInput(blob)</pre><pre>boxes, masks = net.forward([&#39;detection_out_final&#39;, &#39;detection_masks&#39;])</pre><pre><em># Draw masks for each of the detected objects<br></em>postprocess(boxes, masks)</pre><p>The postprocess() is a custom defined function which draws the boxes and masks on the detection that was given by the net.forward() computation. <em>It is significant to note that </em><strong><em>OpenCV’s DNN </em></strong><em>module only does forward computations which means we cannot retrain it for a new domain of images.</em></p><h4><strong>Training the Mask RCNN</strong></h4><p>Then came the interesting part — Training the Mask RCNN to detect targets of our own choice, stamps on attested documents.</p><p>We use the same pre-trained model downloaded from the Detection Model Zoo, and use it with the TensorFlow Object Detection API (<em>trainer functions</em>) to train on a document with stamps.</p><h4>Data Collection and Preparation</h4><p>We collect publicly available images (~70) from various sources on the Google Image Search and annotate the masks on red stamps using the <a href="https://github.com/abreheret/PixelAnnotationTool/releases"><strong>PixelAnnotationTool</strong></a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/965/1*aMdWyaETXhTNOPR55_XO5A.png" /><figcaption>Snapshot showing the collected images and corresponding masks created using the PixelAnnotationTool.</figcaption></figure><p>We downloaded the TensorFlow Models code base and used the trainer functionality available in /models/research/legacy/train.py file. After training only for a few hours on a small GPU machine, we got decent results.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/597/1*JwrBVwZVs_wE4WCkixELvA.png" /><figcaption>Snapshot showing test results on 4 sample test images.</figcaption></figure><p>This is a nice addition because the presence of these stamps could well overlap with our actual areas of interest. In such cases, we do not want to remove the stamp using its bounding box (rectangular area). We might be removing information we don’t want if we do so. Often, this might not be the case, however, once you start diving into detecting (or removing) objects with the highest quality, this becomes very important.</p><p><a href="https://francium.tech/"><em>Francium Tech</em></a><em> is a technology company laser focussed on delivering top quality software of scale at extreme speeds. Numbers and Size of the data don’t scare us. If you have any requirements or want a free health check of your systems or architecture, feel free to shoot an email to </em><a href="http://contact@francium.tech/"><em>contact@francium.tech</em></a><em>, we will get in touch with you!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c7556654c167" width="1" height="1" alt=""><hr><p><a href="https://blog.francium.tech/object-detection-on-documents-with-mask-rcnn-on-tensorflow-c7556654c167">Object Detection with Mask RCNN on TensorFlow</a> was originally published in <a href="https://blog.francium.tech/">Francium Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>