<?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 SHIVPOOJAN SAINI on Medium]]></title>
        <description><![CDATA[Stories by SHIVPOOJAN SAINI on Medium]]></description>
        <link>https://medium.com/@sainishivpoojan1?source=rss-34406622aa4d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*GXMMW0Bzo_BxJ3fl2qLLFg.jpeg</url>
            <title>Stories by SHIVPOOJAN SAINI on Medium</title>
            <link>https://medium.com/@sainishivpoojan1?source=rss-34406622aa4d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 02:32:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sainishivpoojan1/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[Python connector for AWS OCR (Textract)]]></title>
            <link>https://medium.com/@sainishivpoojan1/python-connector-for-aws-ocr-textract-92f538216cc1?source=rss-34406622aa4d------2</link>
            <guid isPermaLink="false">https://medium.com/p/92f538216cc1</guid>
            <category><![CDATA[text-extraction]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[ocr]]></category>
            <category><![CDATA[aws-textract]]></category>
            <category><![CDATA[computer-vision]]></category>
            <dc:creator><![CDATA[SHIVPOOJAN SAINI]]></dc:creator>
            <pubDate>Wed, 28 Jun 2023 12:08:05 GMT</pubDate>
            <atom:updated>2023-06-28T12:08:05.108Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>To connect and interact with the Amazon Textract service using Python, you can use the AWS SDK for Python (Boto3). <a href="https://boto3.amazonaws.com/v1/documentation/api/latest/index.html">Boto3 </a>(for more details visit aws documentation)provides a high-level API to interact with various AWS services, including Textract.</blockquote><figure><img alt="https://www.youtube.com/watch?v=-SpHPW3RTx8" src="https://cdn-images-1.medium.com/max/639/1*NJevYTc1tRz3VEtKm66RrA.jpeg" /><figcaption><strong>AWS services connector through Boto3</strong></figcaption></figure><p>The following blog contains end-to-end Python integration for AWS OCR (Textract) along with S3 file upload operations using the Boto3 Python library. We will explore different methodologies and provide Python code implementations for extracting text from a variety of documents such as PNG, JPEG, TIFF, and PDF.</p><h3><strong>Step1:</strong></h3><p>To get started, make sure you have Boto3 installed. You can install it using pip:</p><pre>pip install boto3</pre><h3>Step2:</h3><p>After the installation of the Python library creates an AWS client object by using boto3 under session.</p><pre>import boto3    <br>try:<br>    session = boto3.Session(<br>        aws_access_key_id=XXXXXXXXXXXXXXXX,<br>        aws_secret_access_key=aXXXXXXXXXXXXX,<br>    )<br>    client = session.client(aws_service_name, region_name=region_name)<br>    return client<br>except Exception as e:<br>    logger.error(f&#39;Unable to create aws client object due to {e}&#39;)<br><br>S3_client= session.client(&#39;s3&#39;, region_name=region_name)<br>textract_client = session.client(&#39;textract&#39;, region_name=region_name)</pre><p>In the above code, we created 2 different objects of 2 AWS services i.e. S3_client (For access to the s3 bucket ) and textract_client (For access to textract service). To <em>get aws_access_key_id</em> and <em>aws_secret_access_key </em>follow the steps mentioned in the following <a href="https://stackoverflow.com/questions/21440709/how-do-i-get-aws-access-key-id-for-amazon"><em>link </em></a><em>.</em></p><h3>Step3:</h3><p>Once the client object is ready we can hit textract API to get a text from image-based documents. There are two ways of using textract i.e with s3 and without using s3 :</p><h4><strong>1-</strong> Documents f<strong>rom local (without s3 bucket):</strong></h4><p>If we just want to extract text from <strong>single-page</strong> documents i.e JPEG, PNG, we can use <strong>DetectDocumentText</strong>is a synchronous operation for more details<br>see the documentation <a href="https://docs.aws.amazon.com/textract/latest/dg/API_DetectDocumentText.html">here</a>.</p><pre>documentName = &quot;sample_text_image.jpg&quot;<br>with open(documentName, &#39;rb&#39;) as document:<br>    imageBytes = bytearray(document.read())<br>response =textract_client.detect_document_text(Document={&#39;Bytes&#39;: imageBytes})</pre><h4>2- Documents form S3 bucket (with s3 bucket):</h4><p>For extracting text from <strong>multipage documents </strong>we need to start the asynchronous detection of text in a document that can analyze text in documents that are in JPEG, PNG, TIFF, and PDF format more details<br>see the documentation <a href="https://docs.aws.amazon.com/textract/latest/dg/API_StartDocumentTextDetection.html">here.</a></p><p>here we can divide this call in two-step <strong>1st </strong>get the job id from <em>start_document_text_detection</em></p><pre>job_id = client.start_document_text_detection(<br>            DocumentLocation={<br>                &#39;S3Object&#39;: {<br>                    &#39;Bucket&#39;: s3_bucket_name,<br>                    &#39;Name&#39;: object_name<br>                }})<br># where s3_bucket_name =name of your s3 bucket<br># object_name = path of document from bucket (including document name )<br></pre><p><strong>2nd</strong> step will be to check when the job SUCCEEDED collect the text response by using <a href="https://docs.aws.amazon.com/textract/latest/dg/API_GetDocumentTextDetection.html"><em>get_document_text_detection</em></a></p><pre>merged_response = {}<br>    # Initialize pagination parameters<br>    next_token = None<br>    finished = False<br>    while not finished:<br>        # Get the job results<br>        if next_token:<br>            response = client.get_document_text_detection(JobId=job_id, NextToken=next_token)<br>        else:<br>            response = client.get_document_text_detection(JobId=job_id)<br>        # Merge the blocks from the response into the merged dictionary<br>        for block in response[&#39;Blocks&#39;]:<br>            block_id = block[&#39;Id&#39;]<br>            merged_response[block_id] = block<br><br>        # Check if there are more token responses<br>        if &#39;NextToken&#39; in response:<br>            next_token = response[&#39;NextToken&#39;]<br>        else:<br>            finished = True</pre><blockquote>It&#39;s not necessary that you get all page&#39;s responses in one call <strong>get_document_text_detection</strong> it will only return the maximum number of results to return per paginated call(i.e. maximum 1000).</blockquote><pre># Request Syntax for get_document_text_detection<br>{<br>   &quot;JobId&quot;: &quot;string&quot;,<br>   &quot;MaxResults&quot;: number,<br>   &quot;NextToken&quot;: &quot;string&quot;<br>}</pre><h3>Step4:</h3><p>Now we can process the response and can restructure it according to our use<em> (Note: Here we only concatenated response[‘Blocks’] in merged_response) </em><strong><em>Output format of aws textract is shown below</em></strong></p><pre>{<br>   &quot;Blocks&quot;: [ <br>      { <br>         &quot;BlockType&quot;: &quot;string&quot;,<br>         &quot;ColumnIndex&quot;: number,<br>         &quot;ColumnSpan&quot;: number,<br>         &quot;Confidence&quot;: number,<br>         &quot;EntityTypes&quot;: [ &quot;string&quot; ],<br>         &quot;Geometry&quot;: { <br>            &quot;BoundingBox&quot;: { <br>               &quot;Height&quot;: number,<br>               &quot;Left&quot;: number,<br>               &quot;Top&quot;: number,<br>               &quot;Width&quot;: number<br>            },<br>            &quot;Polygon&quot;: [ <br>               { <br>                  &quot;X&quot;: number,<br>                  &quot;Y&quot;: number<br>               }<br>            ]<br>         },<br>         &quot;Id&quot;: &quot;string&quot;,<br>         &quot;Page&quot;: number,<br>         &quot;Query&quot;: { <br>            &quot;Alias&quot;: &quot;string&quot;,<br>            &quot;Pages&quot;: [ &quot;string&quot; ],<br>            &quot;Text&quot;: &quot;string&quot;<br>         },<br>         &quot;Relationships&quot;: [ <br>            { <br>               &quot;Ids&quot;: [ &quot;string&quot; ],<br>               &quot;Type&quot;: &quot;string&quot;<br>            }<br>         ],<br>         &quot;RowIndex&quot;: number,<br>         &quot;RowSpan&quot;: number,<br>         &quot;SelectionStatus&quot;: &quot;string&quot;,<br>         &quot;Text&quot;: &quot;string&quot;,<br>         &quot;TextType&quot;: &quot;string&quot;<br>      }<br>   ],<br>   &quot;DetectDocumentTextModelVersion&quot;: &quot;string&quot;,<br>   &quot;DocumentMetadata&quot;: { <br>      &quot;Pages&quot;: number<br>   },<br>   &quot;JobStatus&quot;: &quot;string&quot;,<br>   &quot;NextToken&quot;: &quot;string&quot;,<br>   &quot;StatusMessage&quot;: &quot;string&quot;,<br>   &quot;Warnings&quot;: [ <br>      { <br>         &quot;ErrorCode&quot;: &quot;string&quot;,<br>         &quot;Pages&quot;: [ number ]<br>      }<br>   ]<br></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fa_bNARrmufHs64y.png" /><figcaption>Workflow of Textract service</figcaption></figure><p><strong>Conclusion:</strong> From the above 4 steps, we can detect text of various types of documents like image formats: JPEG, PNG, PDF, or TIFF by using the Python boto3 library even we can do various operations on an s3 bucket like upload, and download, etc. other alternatives of textract we can use UI based provided by AWS.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=92f538216cc1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Documents Image Quality Assessment Part -1]]></title>
            <link>https://medium.com/@sainishivpoojan1/documents-image-quality-assessment-part-1-75c9c4e441b0?source=rss-34406622aa4d------2</link>
            <guid isPermaLink="false">https://medium.com/p/75c9c4e441b0</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[image-processing]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[SHIVPOOJAN SAINI]]></dc:creator>
            <pubDate>Fri, 03 Mar 2023 07:12:53 GMT</pubDate>
            <atom:updated>2023-03-15T13:31:22.502Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://medium.com/u/34406622aa4d">SHIVPOOJAN SAINI</a> | <a href="https://medium.com/u/750f37079ffb">Aditya Mangal</a> | <a href="https://medium.com/u/7e0e2d9a6b8a">Insurance Samadhan</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/897/1*4kAlhw3rBMozsiWCUHTLCQ.gif" /></figure><p>Document images may be degraded at various stages like generation, storage, transfer, etc for example, degradations may result in a significant drop in the performance of Optical Character Recognition (OCR), as well as affect the performance of document image retrieval, layout analysis, logo detection, and other document analysis tasks. In general, degradations decrease document readability resulting in unrecoverable information loss. Document image quality studies are also necessary ingredients in developing restoration and enhancement algorithms. It is important to understand the various types of degradations that may affect document images and develop reliable methods for estimating levels of degradations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*PujR_EIvRNhbT58kVgmKmA.gif" /></figure><p>IQA (Image quality Assessment) may be done by a subjective method or an objective way. Objective image optical quality evaluation may be categorized as first category, <strong>no-reference (NR);</strong> second category, <strong>reduced reference (RR)</strong>; third category <strong>full-reference (FR);</strong> depending on the presence of an original image. At FR measure, the quality of an exam image is matrices by matching it with a reference (original) image. RR<br>approaches have limited information from the original image. However, NR approaches go to evaluate the quality of an image lacking the original image. The benefit of an objective quality valuation study is been offer quality measures that may guess image quality mechanically. A wonderful review paper on image quality assessment by <em>Iman Hussein AL-Qinani </em>can be found <a href="https://www.researchgate.net/publication/338595523_A_Review_Paper_on_Image_Quality_Assessment_Techniques"><strong>here</strong></a><strong>.</strong></p><blockquote>A wonderfull collection of various algorithms and architectures in PyTorch for image quality assessment <a href="https://github.com/chaofengc/IQA-PyTorch"><em>IQA-PyTorch</em></a> thanks to all contributors for such a wonderful projects.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5YB5I-BdVxBbMN5N.gif" /><figcaption>PyIQA sample code</figcaption></figure><p>There are several modules required for recognizing information from the document through OCR technologies and they required sufficient cost resources along with time so it will be great if we have prior knowledge of image quality with respect to OCR score that can help with only the required pre-processing steps. We implemented IQA as <strong>Classification</strong> and <strong>Regression </strong>problems that explain below, both methods have their own benefits and limitations, and implementation is explained in the following steps:-</p><p><strong>Dataset Preparation:</strong></p><p>We prepared two major categories of dataset one is word level and the next is patch level and apply image augmentation by adding various effects like gaussian, warping, blurring, pixelation, etc so that we can cover a major variety of real-world noises and their corresponding OCR scores by using opensource OCR :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/226/1*6HxxDNB62kkJup3GDukZew.png" /><figcaption>patch level with ocr_score: 0.97</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*Y5zzewiYbDaE76ShYHw9gA.jpeg" /><figcaption>word level with ocr_score:0.81</figcaption></figure><p><strong>Classification Algorithm:</strong></p><p>We created classes on the basis of score e.g class 0 to data with a score less than 0.2 and so on. In this way, we have n classes (n depends on the dataset) now above IQA problem converted to a standard classification problem for such problems there are several pre-defined CNN (Convolution Neural Network )transfer learning architectures there like <em>VGG, ResNet, DenseNet</em> and so many, or we can design a new architecture of CNN that work best with above problem statements, even can add our extra layers like add dropout layer to avoid overfitting, new loss function depending on data and also optimizer like <em>adam, SGD,</em> etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*lew1GThMZ3JNhXpfjUPtuA.png" /><figcaption>DenseNet 121 where training accuracy is about 1 and validation is near 80–85% and validation loss is also under the 0.2 range</figcaption></figure><p>we trained several architectures we reached an accuracy band of 80–90% one of the models with DenseNet (<a href="https://www.tensorflow.org/api_docs/python/tf/keras/applications/densenet/DenseNet121"><em>TensorFlow link</em></a>) as the backbone network with dropout layers accuracy and loss graph is shown above:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/272/1*9XMPj43e7XwtTRQw7HK80A.gif" /><figcaption>Classification results</figcaption></figure><p><strong>Regression Algorithm:</strong></p><p>As we have seen above we can’t touch accuracy near 95% so we decided to convert the above problem as a Regression problem where we will try to predict a score for each data which will be near the score as OCR and will apply regression loss such as MeanAbsoluteError(MAE), Mean Square Error(MSE), etc, a good survey over loss function can be found <a href="https://faculty.ist.psu.edu/vhonavar/Courses/ds310/lossfunc.pdf"><em>here</em></a><em> </em>one of regression network error loss graph shown below :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*X7Q8Ne3iCd_DWWg7" /><figcaption>VGG 16 (trainable layers = True) with RMSE</figcaption></figure><p>In the regression model, we reached good accuracy (in terms of distance between predicted and real score ) with an error band of 20% (i.e -0.1 to 0.1), which means if the real score is 0.5 then we can accept a score between 0.4–0.6.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/1*WDEsoa_G9l2XC-xLEI9Tpw.gif" /><figcaption>Regression Results</figcaption></figure><p>After conducting tests by regression and classification we come to the conclusion by a small number of text-based data i.e patch and word level, accuracy beyond 90% is quite difficult one of the major reasons may be CNN is not getting that much enough features for segregation. So we will go for research with CNN+RNN-based such as CRNN architecture which can extract more fine-grade features similar to OCR recognition architecture as future work.</p><blockquote>Part 2 CRNN(Convolution Recurrent Neural Network) based methods will come soon the link can be found <a href="https://adityamangal98.medium.com/documents-image-quality-assessment-part-2-f15563d2dea">here</a>.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=75c9c4e441b0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>