<?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 Amar Kumar on Medium]]></title>
        <description><![CDATA[Stories by Amar Kumar on Medium]]></description>
        <link>https://medium.com/@amar.bit.jsr?source=rss-1f4f972f4a6b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*5wt9RTeWJ3ezfPa8.</url>
            <title>Stories by Amar Kumar on Medium</title>
            <link>https://medium.com/@amar.bit.jsr?source=rss-1f4f972f4a6b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 18:08:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@amar.bit.jsr/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[Face mask detection and deployment to edge device(Model Optimization)]]></title>
            <link>https://medium.com/@amar.bit.jsr/face-mask-detection-and-deployment-to-edge-device-model-optimization-889dee939198?source=rss-1f4f972f4a6b------2</link>
            <guid isPermaLink="false">https://medium.com/p/889dee939198</guid>
            <dc:creator><![CDATA[Amar Kumar]]></dc:creator>
            <pubDate>Sun, 22 May 2022 10:39:14 GMT</pubDate>
            <atom:updated>2022-05-22T10:39:14.285Z</atom:updated>
            <content:encoded><![CDATA[<p>A person is wearing a mask or not can be detected using computer vision. This is one of the good application of computer vision.</p><p>There are the following constraints to develop deep learning based solution and deploy to device having less compute.</p><ul><li>Data Collection</li><li>Complex Model Training</li><li>Optimized model(quantization, Pruning)</li></ul><p>In this article I am highlighting data collection and complex model training process which will reduce your model development and deployment time. Data collection could be easy if you know the variation of your target objects based on camera position. Why I am stressing on target object size? I explain this by example, if you know your object size is going to very from 20 pixels to 60 pixels then no need to include data which have object size which are not in given range, this will reduced the training time of the models.</p><p>Second point if we know the camera position and its orientation, then only includes those sample that resemble with the actual sites. This will also reduce the training time to get good model.</p><p>Third point is connected to model selection. Most of the people try to use the deeper network which already exists. But based on my experiment results no need to go deeper network if object is near and camera orientation is fixed. For example, surveillance in confined area like ATM. Use shallow networks like few convolutions and maxpooling layers along with activations. This will reduce the model parameters and will increase the throughput.</p><p>I applied all these techniques in my face mask detection, and got only 600KB model which was giving 97% accuracy. Result shown below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*3exY1c5Rsis374sc51R49A.png" /></figure><p>red color bounding box indicating that person is without mask and yellow color bounding box indicating that person is wearing mask. Below is linkedin link which have got attention by multiple computer vision engineers when I posted during covid.</p><p><a href="https://www.linkedin.com/feed/update/urn:li:activity:6661680284314017792/"><strong>Post | Feed | LinkedIn</strong></a></p><p>Once model is ready then we can optimize using quantization and pruning. I will cover more about the quantization and pruning in my next post.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=889dee939198" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setup OpenCV in IDE inside OpenVino Container]]></title>
            <link>https://medium.com/@amar.bit.jsr/setup-opencv-in-ide-inside-openvino-container-538577283ebc?source=rss-1f4f972f4a6b------2</link>
            <guid isPermaLink="false">https://medium.com/p/538577283ebc</guid>
            <dc:creator><![CDATA[Amar Kumar]]></dc:creator>
            <pubDate>Sat, 10 Oct 2020 13:33:48 GMT</pubDate>
            <atom:updated>2020-10-10T13:33:48.138Z</atom:updated>
            <content:encoded><![CDATA[<p>Setup OpenCV in IDE inside OpenVino Container</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vA_EbN0a9aezTQh5HZjACA.png" /></figure><p>Step 1: setup openvino docker using my previous article.</p><p><a href="https://medium.com/@amar.bit.jsr/dockerise-openvino-4d57cd2f4837">Dockerise OpenVino</a></p><p>Step 2: Execute the following commands to export display and run the container using below commands</p><pre>xhost +<br>docker run  -it --rm -v /home/antpc/deep-workspace:/deep-workspace/ -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=$DISPLAY  c792c1e98267</pre><p>End is Image Id that you can check using the command: docker images</p><p>Step 3: Once you login run nsight command then enter. It will popupu UI enter workspace path and click on ok.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mLOrrKMtL85Aiw4t3dWXHg.png" /></figure><p>Step 4: Go to File-&gt;New-&gt;C++ project. It will ask the project name give the name as I given opencvtest select Linux C++ compiler and Click on Finish.</p><p>Step 5: Righ click on opencvtest(project)-&gt;new-&gt;file give the name main.cpp and then click on Finish. Add the below code to test the setup.</p><pre>#include &lt;opencv2/core.hpp&gt;<br>#include &lt;opencv2/imgcodecs.hpp&gt;<br>#include &lt;opencv2/highgui.hpp&gt;<br>#include &lt;iostream&gt;<br>using namespace cv;<br>int main()<br>{<br>    std::string image_path = samples::findFile(&quot;car.png&quot;);<br>    Mat img = imread(image_path, IMREAD_COLOR);<br><br>    if(img.empty())<br>    {<br>        std::cout &lt;&lt; &quot;Could not read the image: &quot; &lt;&lt; image_path &lt;&lt; std::endl;<br>        return 1;<br>    }<br>    imshow(&quot;Display window&quot;, img);<br>    int k = waitKey(0); // Wait for a keystroke in the window<br>    if(k == &#39;s&#39;)<br>    {<br>        imwrite(&quot;starry_night.png&quot;, img);<br>    }<br>    return 0;<br>}</pre><p>Step 6: Configure include and lib file. Right click on opencvtest(project) -&gt; properties. Go to Build tab leftside and select settings. Then select toolsettings -&gt; includes. Click on green icon on top to include the opencv path.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lWEjUFzDcCBSeWA_dwSVoA.png" /></figure><p>Select C++ Linker then click on Libraries. Below select the path of the libraries and on top put the name of the libraries as shown in below figure.Once configuration is done click on ok.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_8QObq43XFtazn1cCqm03A.png" /></figure><p>Now setting is done you may run in debug mode and debug the code.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=538577283ebc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dockerise OpenVino]]></title>
            <link>https://medium.com/@amar.bit.jsr/dockerise-openvino-4d57cd2f4837?source=rss-1f4f972f4a6b------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d57cd2f4837</guid>
            <dc:creator><![CDATA[Amar Kumar]]></dc:creator>
            <pubDate>Sat, 10 Oct 2020 11:59:00 GMT</pubDate>
            <atom:updated>2020-10-10T12:00:53.170Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*hrR7yW6golMT0KGIgoC10A.png" /></figure><p>Step 1: setup the docker using my previous article.</p><p><a href="https://medium.com/@amar.bit.jsr/setup-docker-in-ubuntu-18-04-53c1268adcca">Setup Docker in Ubuntu 18.04</a></p><p>Step 2: Put below code in Dockerfile</p><pre>FROM ubuntu:18.04</pre><pre>ARG PACKAGE=intel-openvino-dev-ubuntu18–2020.3.194</pre><pre>RUN apt-get update &amp;&amp; apt-get -y upgrade<br>RUN apt-get install -y — no-install-recommends \<br> ca-certificates \<br> gnupg \<br> wget \<br> sudo</pre><pre>RUN wget <a href="https://apt.repos.intel.com/openvino/2020/GPG-PUB-KEY-INTEL-OPENVINO-2020">https://apt.repos.intel.com/openvino/2020/GPG-PUB-KEY-INTEL-OPENVINO-2020</a> &amp;&amp; \<br> apt-key add GPG-PUB-KEY-INTEL-OPENVINO-2020</pre><pre>RUN echo “deb <a href="https://apt.repos.intel.com/openvino/2020">https://apt.repos.intel.com/openvino/2020</a> all main” &gt; /etc/apt/sources.list.d/intel-openvino-2020.list</pre><pre>RUN apt-get update &amp;&amp; \<br> apt-get install -y — no-install-recommends \<br> $PACKAGE &amp;&amp; \<br> apt autoremove -y &amp;&amp; \<br> rm -rf /var/lib/apt/lists/*</pre><pre>RUN /bin/bash -c “source /opt/intel/openvino/bin/setupvars.sh”</pre><pre>RUN echo “source /opt/intel/openvino/bin/setupvars.sh” &gt;&gt; /root/.bashrc</pre><pre>RUN /opt/intel/openvino/install_dependencies/install_openvino_dependencies.sh<br>RUN /opt/intel/openvino/deployment_tools/model_optimizer/install_prerequisites/install_prerequisites.sh<br>RUN apt-get install -y nvidia-nsight<br>RUN apt-get install -y gdb<br>CMD [“/bin/bash”]</pre><p>Step 3: open the terminal at same path where you put the Dockerfile. Execute below command</p><pre>docker build --tag openvino_dev:openvino_dev .</pre><p>Step 4: above will create image with name openvino_dev. so we can create container from this image using below command</p><pre>docker images</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/879/1*swbAQmPv1EK_4CEbIdryrA.png" /></figure><pre>docker run  -it --rm -v /home/antpc/deep-workspace:/deep-workspace/ -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=$DISPLAY   c792c1e98267</pre><p>Note: End string is image id that you can check in above image.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d57cd2f4837" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setup Nvidia Deepstream development Environment]]></title>
            <link>https://medium.com/@amar.bit.jsr/setup-nvidia-deepstream-development-environment-8f12f8ed8c94?source=rss-1f4f972f4a6b------2</link>
            <guid isPermaLink="false">https://medium.com/p/8f12f8ed8c94</guid>
            <dc:creator><![CDATA[Amar Kumar]]></dc:creator>
            <pubDate>Sat, 10 Oct 2020 06:35:55 GMT</pubDate>
            <atom:updated>2020-10-10T06:35:55.307Z</atom:updated>
            <content:encoded><![CDATA[<p>When I started to debug deepstream on console it was not easy for me because usually I use IDE. I spent two days to figure out how to setup the development environment and debug the deepstream sample code.</p><p>I decided to write an article so that other people will not face the problem to setup and debug the deepstream code.</p><p>Here I am going to setup Deepstream 5.0 on ubuntu container 18.04.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SZlvIqYIDWpzsB4VgNc1_Q.jpeg" /><figcaption>Deepstream Architecture</figcaption></figure><p>Step 1: Setup the docker in Ubuntu. Those who are not aware they may follow my previous article.</p><p><a href="https://medium.com/@amar.bit.jsr/setup-docker-in-ubuntu-18-04-53c1268adcca">Setup Docker in Ubuntu 18.04</a></p><p>Step 2: Once you setup the docker in host machine. Now next step is setup nvidia tools that will help to access GPUs inside the container. Here I want to mention one point If you are using docker 19.03 CE version or greater than this then no need to go for nvidia-docker2 . You can install packages developed by Nvidia which will allow to expose the GPUs to the container by using below command.</p><pre>sudo apt-get update<br>sudo apt-get install nvidia-container-runtime</pre><p>Step 3: pull the deepstream docker.</p><p>docker pull nvcr.io/nvidia/deepstream:5.0.1–20.07-devel</p><p>Step 4: Once you are done with pulling deepstream docker image then we can start the container. Below are list of commands that will help to check the image name and details.</p><pre>docker images</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*HsImk4QZCEJbdZzvvNd7Kg.png" /></figure><p>Step 4: To login inside the container we can use the below command. But before login we will export the display because we are going to setup the gui environment inside the container. End of the command is the image id that you want to run as container.</p><pre>xhost +<br>docker run --gpus all -it --rm -v /home/amar/deep-workspace:/deep-workspace/ -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=$DISPLAY --security-opt seccomp=unconfined  -w /opt/nvidia/deepstream/deepstream-5.0  f5ed161342f4</pre><p>Step 5: Once you login, you can update the container and install Nvidia-Nsight using below command.</p><pre>sudo apt-get update -y<br>sudo apt-get install -y nvidia-nsight</pre><p>Here I want to mention one point. If you stop the container all new installed packages will remove If you want to keep all you may save the running docker as new image. Below command will help to save new image and then run the new image.</p><p>docker commit &lt;container id&gt; &lt;new name&gt;</p><p>How we can check the running container id? use below command</p><pre>docker ps</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*blCTbSt8JR_pSe1ephIoVg.png" /></figure><p>Now exist from the container and run the new image as container. I saved the new image as deepstream_nsight. Now I run the container using below command.</p><pre>xhost +<br>docker run --gpus all -it --rm -v /home/antpc/deep-workspace:/deep-workspace/ -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=$DISPLAY --security-opt seccomp=unconfined  -w /opt/nvidia/deepstream/deepstream-5.0  deepstream_nsight</pre><p>If you want to check GPU is accessible or not to container. Execute the command.</p><pre>nvidia-smi</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/749/1*hN96WJRSOnU71bQM1eqC4w.png" /></figure><p>Step 6: now start the nvidia Nsight using below command. Type the command inside the login and enter</p><pre>nsight</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/685/1*Pc5wJJj1p-uQtg8vOPmyWw.png" /></figure><p>Enter the path to workspace and click ok.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/694/1*hOWtMOnICaPZkJHF8tobFA.png" /></figure><p>Step 7: Now make a cuda based empy project as I given deeptest. Now copy all src file to this projects from the below path i.e. /opt/nvidia/deepstream/deepstream-5.0/sources/apps/apps-common/src</p><p>Also the application source code that want to test put in this source file as I put the deepstream-app source.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/492/1*2uv6A26ugT2HKV_XlbvqkQ.png" /></figure><p>Step 8: Now setup the include and lib path as shown in below figure. Goto project deeptest -&gt; right click -&gt;properties set the include folders as shown in below figure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tWhy8uuzHsoBzEIPElCkUw.png" /></figure><p>Set lib folder as shown in below figure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uWSCdegQWANmzwyKCCTxAw.png" /></figure><p>All library is not visible in above image so below I list down.</p><pre>gstvideo-1.0<br>nvdsgst_meta<br>X11<br>gio-2.0<br>gobject-2.0<br>nvds_meta<br>nvdsgst_helper<br>json-glib-1.0<br>gstcheck-1.0<br>gstreamer-1.0<br>gstcontroller-1.0<br>glib-2.0<br>gstnet-1.0<br>gstbase-1.0<br>nvdsgst_smartrecord<br>nvds_utils<br>nvds_msgbroker<br>m<br>gstrtspserver-1.0</pre><p>Now you can create break point and debug the projects.</p><p><strong>Note</strong>: you can also create the projects from cmake file which comes with sample code.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8f12f8ed8c94" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setup Docker in Ubuntu 18.04]]></title>
            <link>https://medium.com/@amar.bit.jsr/setup-docker-in-ubuntu-18-04-53c1268adcca?source=rss-1f4f972f4a6b------2</link>
            <guid isPermaLink="false">https://medium.com/p/53c1268adcca</guid>
            <dc:creator><![CDATA[Amar Kumar]]></dc:creator>
            <pubDate>Tue, 06 Oct 2020 14:32:56 GMT</pubDate>
            <atom:updated>2020-10-06T14:32:56.457Z</atom:updated>
            <content:encoded><![CDATA[<p>I know the challenges when people stuck to setup the development environment.To reduce these challenges docker could play a vital role. Docker is one of the tool that can setup the development environment in single command.So today going to cover the installation of docker tool in Linux environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/343/1*R652yNXiiy6AYypGnR7s_g.png" /></figure><p>Step 1: Update existing list of packages.</p><pre>sudo apt update</pre><p>Step 2: Install few prerequisites packages.</p><pre>sudo apt install apt-transport-https ca-certificates curl software-properties-common</pre><p>Step 3: Add GPG key to local system</p><pre>curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -</pre><p>Step 4: Add the docker repository to to APT sources</p><pre>sudo add-apt-repository &quot;deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable&quot;</pre><p>step 5: Update the packages using newly added repository</p><pre>sudo apt update</pre><p>step 6: Install docker(community edition)</p><pre>sudo apt install docker-ce</pre><p>step 7: Now docker is installed in system it will get reflect when system get restart. We can check docker status using below command</p><pre>sudo systemctl status docker</pre><p><strong>Note:</strong> If we run docker command without sudo it will give the error because by default docker command can run the root or docker(group) user.So either user has to root or user of docker group. below command will add user to docker group.</p><pre>sudo usermod -aG docker ${USER}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=53c1268adcca" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Yolov3 Inference Using DNN on Nvidia GPU]]></title>
            <link>https://medium.com/@amar.bit.jsr/yolov3-inference-using-dnn-on-nvidia-gpu-6f7d3a2d22f1?source=rss-1f4f972f4a6b------2</link>
            <guid isPermaLink="false">https://medium.com/p/6f7d3a2d22f1</guid>
            <dc:creator><![CDATA[Amar Kumar]]></dc:creator>
            <pubDate>Tue, 18 Feb 2020 12:59:52 GMT</pubDate>
            <atom:updated>2020-02-18T12:59:52.919Z</atom:updated>
            <content:encoded><![CDATA[<p>In My previous article I had cover the building of DNN module with Cuda support. Given Link below.</p><p><a href="https://medium.com/@amar.bit.jsr/dnn-module-build-with-cuda-support-on-windows-10-3a2f3a736ca">Dnn Module Build with Cuda support on windows 10</a></p><p>Now Today I give you the steps to use this library in visual studio 2015.</p><p>Step 1: After building Install project, it installs the library inside the Install folder which is inside the build folder. Directory structure showing below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*dm1KmUZz-Zinm0hoCALJ6g.png" /></figure><p>Step 2: Mainly we need three folders which includes,bin and lib. Bin and lib folder which you will find inside the x64&gt;vc14&gt;lib/bin. Now we have to configure all these in our application so that we can use the functionality.</p><p>Step 3: Start visual studio and select Nvidia cuda project so that Nvidia related configuration automatically attache to your project.Also provide the details like Name,Location,Solution name and then click on OK.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LQPw86AluKz0J4DXnAHiWw.png" /></figure><p>Step 4: Add C++ file to the current project using the following steps. Right click on project &gt;Add&gt;New Item and click. Select C++ file and provide the name of the source file for example like main.cpp and click on Add.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*oFNwp_LHiOYgIMnMduTdTw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/987/1*jcBFitG1DQ7TrGP0WYf--A.png" /></figure><p>Step 5: Add bin folder to environment variable using the following steps. Type environment in search and click on icon.You will get the system variable window.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/553/1*5IgqcVvhrE_ZPixWJhuHBg.png" /></figure><p>Click on Environment variables. You you get the below window.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*kjFx6e76xkV14nObT0FvLQ.png" /></figure><p>Select Path variable in System variables and click on Edit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/607/1*qMxHfWlRkTvzSRpXIUDzPQ.png" /></figure><p>Click on New and include all bin folder to this. If you see above I included two folders. C:\opencv_4.2\bin and C:\opencv_4.2\x64\vc14\bin. After adding click on OK.</p><p>Step 6: Now select build type in visual studio and platform. I selected Release and x64.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/743/1*YmjljDrm0iT40rcsngYI4w.png" /></figure><p>Step 7: We have to setup the project properties. Right click on Project &gt; click on properties. This will opencv project properties window. Select C/C++ &gt; General &gt; Additional Include Directories and include your opencv include path.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QClmfEwrRsYPKHza7n-qRA.png" /></figure><p>Step 8: Go in Linker &gt;General &gt;Additional Library Directories. Put your opencv library path as shown in figure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PKVzrDlhlx0PFBEKb-rkbQ.png" /></figure><p>Step 9: set linker input. Linker &gt; Input &gt; Additional Dependencies. click you will get additional dependencies window and copy the lib name and paste and click on OK.</p><pre>opencv_aruco420.lib<br>opencv_bgsegm420.lib<br>opencv_bioinspired420.lib<br>opencv_calib3d420.lib<br>opencv_ccalib420.lib<br>opencv_core420.lib<br>opencv_cudaarithm420.lib<br>opencv_cudabgsegm420.lib<br>opencv_cudacodec420.lib<br>opencv_cudafeatures2d420.lib<br>opencv_cudafilters420.lib<br>opencv_cudaimgproc420.lib<br>opencv_cudalegacy420.lib<br>opencv_cudaobjdetect420.lib<br>opencv_cudaoptflow420.lib<br>opencv_cudastereo420.lib<br>opencv_cudawarping420.lib<br>opencv_cudev420.lib<br>opencv_datasets420.lib<br>opencv_dnn420.lib<br>opencv_dnn_objdetect420.lib<br>opencv_dnn_superres420.lib<br>opencv_dpm420.lib<br>opencv_face420.lib<br>opencv_features2d420.lib<br>opencv_flann420.lib<br>opencv_fuzzy420.lib<br>opencv_gapi420.lib<br>opencv_hfs420.lib<br>opencv_highgui420.lib<br>opencv_imgcodecs420.lib<br>opencv_imgproc420.lib<br>opencv_img_hash420.lib<br>opencv_line_descriptor420.lib<br>opencv_ml420.lib<br>opencv_objdetect420.lib<br>opencv_optflow420.lib<br>opencv_phase_unwrapping420.lib<br>opencv_photo420.lib<br>opencv_plot420.lib<br>opencv_quality420.lib<br>opencv_reg420.lib<br>opencv_rgbd420.lib<br>opencv_saliency420.lib<br>opencv_shape420.lib<br>opencv_stereo420.lib<br>opencv_stitching420.lib<br>opencv_structured_light420.lib<br>opencv_superres420.lib<br>opencv_surface_matching420.lib<br>opencv_text420.lib<br>opencv_tracking420.lib<br>opencv_video420.lib<br>opencv_videoio420.lib<br>opencv_videostab420.lib<br>opencv_xfeatures2d420.lib<br>opencv_ximgproc420.lib<br>opencv_xobjdetect420.lib<br>opencv_xphoto420.lib</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h_vqmciNq4H172WUl1LgEg.png" /></figure><p>Step 10: Download darknet yolov3 weight file, class file and configuration file to use in our code from darknet site. Configure the path of the following files: weight file, class file, configuration file and input file as shown and figure and click on run. It will show out put on windows as well as write the output in same directory.</p><pre>#include &lt;fstream&gt;</pre><pre>#include &lt;sstream&gt;</pre><pre>#include &lt;opencv2/dnn.hpp&gt;</pre><pre>#include &lt;opencv2/imgproc.hpp&gt;</pre><pre>#include &lt;opencv2/highgui.hpp&gt;</pre><pre>#include &lt;opencv2/opencv.hpp&gt;</pre><pre>using namespace cv;</pre><pre>using namespace dnn;</pre><pre>float confThreshold, nmsThreshold;<br>std::vector&lt;std::string&gt; classes;<br>void postprocess(Mat&amp; frame, const std::vector&lt;Mat&gt;&amp; out, Net&amp; net);<br>void drawPred(int classId, float conf, int left, int top, int right, int bottom, Mat&amp; frame);</pre><pre>int main(int argc, char** argv)</pre><pre>{</pre><pre>confThreshold = 0.5;</pre><pre>nmsThreshold = 0.4;</pre><pre>float scale = 0.00392;</pre><pre>Scalar mean = { 0,0,0 };</pre><pre>bool swapRB = true;</pre><pre>int inpWidth = 416;<br>int inpHeight = 416;</pre><pre>String modelPath = &quot;D:/test_dnn_module/models/yolov3.weights&quot;;<br>String configPath = &quot;D:/test_dnn_module/models/yolov3.cfg&quot;;<br>String framework = &quot;&quot;;</pre><pre>int backendId = cv::dnn::DNN_BACKEND_CUDA;<br>int targetId = cv::dnn::DNN_TARGET_CUDA;<br>String classesFile = &quot;D:/test_dnn_module/models/coco.txt&quot;;<br>// Open file with classes names.</pre><pre>if (!classesFile.empty()) {</pre><pre>const std::string&amp; file = classesFile;</pre><pre>std::ifstream ifs(file.c_str());</pre><pre>if (!ifs.is_open())</pre><pre>CV_Error(Error::StsError, &quot;File &quot; + file + &quot; not found&quot;);</pre><pre>std::string line;</pre><pre>while (std::getline(ifs, line)) {</pre><pre>classes.push_back(line);</pre><pre>}</pre><pre>}</pre><pre>// Load a model.</pre><pre>Net net = readNet(modelPath, configPath, framework);</pre><pre>net.setPreferableBackend(backendId);</pre><pre>net.setPreferableTarget(targetId);</pre><pre>std::vector&lt;String&gt; outNames = net.getUnconnectedOutLayersNames();</pre><pre>// Create a window</pre><pre>static const std::string Win = &quot;DNN Test&quot;;</pre><pre>// Open a video file or an image file or a camera stream.</pre><pre>VideoCapture cap;</pre><pre>cap.open(&quot;D:/test_dnn_module/models/road2.mp4&quot;);</pre><pre>// Process frames.</pre><pre>Mat frame, blob;</pre><pre>VideoWriter vid_writer(&quot;outcpp.avi&quot;, VideoWriter::fourcc(&#39;X&#39;, &#39;V&#39;, &#39;I&#39;, &#39;D&#39;), 5, Size(1280, 720));</pre><pre>while (waitKey(1) &lt; 0) {</pre><pre>cap &gt;&gt; frame;</pre><pre>if (frame.empty()) {</pre><pre>waitKey();</pre><pre>break;</pre><pre>}</pre><pre>// Create a 4D blob from a frame.</pre><pre>Size inpSize(inpWidth &gt; 0 ? inpWidth : frame.cols,</pre><pre>inpHeight &gt; 0 ? inpHeight : frame.rows);</pre><pre>blobFromImage(frame, blob, scale, inpSize, mean, swapRB, false);</pre><pre>// Run a model.</pre><pre>net.setInput(blob);</pre><pre>if (net.getLayer(0)-&gt;outputNameToIndex(&quot;im_info&quot;) != -1)  // Faster-RCNN or R-FCN</pre><pre>{</pre><pre>resize(frame, frame, inpSize);</pre><pre>Mat imInfo = (Mat_&lt;float&gt;(1, 3) &lt;&lt; inpSize.height, inpSize.width, 1.6f);</pre><pre>net.setInput(imInfo, &quot;im_info&quot;);</pre><pre>}</pre><pre>std::vector&lt;Mat&gt; outs;</pre><pre>net.forward(outs, outNames);</pre><pre>postprocess(frame, outs, net);</pre><pre>// Put efficiency information.</pre><pre>std::vector&lt;double&gt; layersTimes;</pre><pre>double freq = getTickFrequency() / 1000;</pre><pre>double t = net.getPerfProfile(layersTimes) / freq;</pre><pre>std::string label = format(&quot;Inference time: %.2f ms&quot;, t);</pre><pre>putText(frame, label, Point(0, 15), FONT_HERSHEY_SIMPLEX, 0.5, Scalar(0, 255, 0));</pre><pre>vid_writer.write(frame);</pre><pre>imshow(Win, frame);</pre><pre>}</pre><pre>vid_writer.release();</pre><pre>return 0;</pre><pre>}</pre><pre>void postprocess(Mat&amp; frame, const std::vector&lt;Mat&gt;&amp; outs, Net&amp; net)</pre><pre>{</pre><pre>static std::vector&lt;int&gt; outLayers = net.getUnconnectedOutLayers();</pre><pre>static std::string outLayerType = net.getLayer(outLayers[0])-&gt;type;</pre><pre>std::vector&lt;int&gt; classIds;</pre><pre>std::vector&lt;float&gt; confidences;</pre><pre>std::vector&lt;Rect&gt; boxes;</pre><pre>if (net.getLayer(0)-&gt;outputNameToIndex(&quot;im_info&quot;) != -1)  // Faster-RCNN or R-FCN</pre><pre>{</pre><pre>// Network produces output blob with a shape 1x1xNx7 where N is a number of</pre><pre>// detections and an every detection is a vector of values</pre><pre>// [batchId, classId, confidence, left, top, right, bottom]</pre><pre>CV_Assert(outs.size() == 1);</pre><pre>float* data = (float*)outs[0].data;</pre><pre>for (size_t i = 0; i &lt; outs[0].total(); i += 7) {</pre><pre>float confidence = data[i + 2];</pre><pre>if (confidence &gt; confThreshold) {</pre><pre>int left = (int)data[i + 3];</pre><pre>int top = (int)data[i + 4];</pre><pre>int right = (int)data[i + 5];</pre><pre>int bottom = (int)data[i + 6];</pre><pre>int width = right - left + 1;</pre><pre>int height = bottom - top + 1;</pre><pre>classIds.push_back((int)(data[i + 1]) - 1);  // Skip 0th background class id.</pre><pre>boxes.push_back(Rect(left, top, width, height));</pre><pre>confidences.push_back(confidence);</pre><pre>}</pre><pre>}</pre><pre>}</pre><pre>else if (outLayerType == &quot;DetectionOutput&quot;) {</pre><pre>// Network produces output blob with a shape 1x1xNx7 where N is a number of</pre><pre>// detections and an every detection is a vector of values</pre><pre>// [batchId, classId, confidence, left, top, right, bottom]</pre><pre>CV_Assert(outs.size() == 1);</pre><pre>float* data = (float*)outs[0].data;</pre><pre>for (size_t i = 0; i &lt; outs[0].total(); i += 7) {</pre><pre>float confidence = data[i + 2];</pre><pre>if (confidence &gt; confThreshold) {</pre><pre>int left = (int)(data[i + 3] * frame.cols);</pre><pre>int top = (int)(data[i + 4] * frame.rows);</pre><pre>int right = (int)(data[i + 5] * frame.cols);</pre><pre>int bottom = (int)(data[i + 6] * frame.rows);</pre><pre>int width = right - left + 1;</pre><pre>int height = bottom - top + 1;</pre><pre>classIds.push_back((int)(data[i + 1]) - 1);  // Skip 0th background class id.</pre><pre>boxes.push_back(Rect(left, top, width, height));</pre><pre>confidences.push_back(confidence);</pre><pre>}</pre><pre>}</pre><pre>}</pre><pre>else if (outLayerType == &quot;Region&quot;) {</pre><pre>for (size_t i = 0; i &lt; outs.size(); ++i) {</pre><pre>// Network produces output blob with a shape NxC where N is a number of</pre><pre>// detected objects and C is a number of classes + 4 where the first 4</pre><pre>// numbers are [center_x, center_y, width, height]</pre><pre>float* data = (float*)outs[i].data;</pre><pre>for (int j = 0; j &lt; outs[i].rows; ++j, data += outs[i].cols) {</pre><pre>Mat scores = outs[i].row(j).colRange(5, outs[i].cols);</pre><pre>Point classIdPoint;</pre><pre>double confidence;</pre><pre>minMaxLoc(scores, 0, &amp;confidence, 0, &amp;classIdPoint);</pre><pre>if (confidence &gt; confThreshold) {</pre><pre>int centerX = (int)(data[0] * frame.cols);</pre><pre>int centerY = (int)(data[1] * frame.rows);</pre><pre>int width = (int)(data[2] * frame.cols);</pre><pre>int height = (int)(data[3] * frame.rows);</pre><pre>int left = centerX - width / 2;</pre><pre>int top = centerY - height / 2;</pre><pre>classIds.push_back(classIdPoint.x);</pre><pre>confidences.push_back((float)confidence);</pre><pre>boxes.push_back(Rect(left, top, width, height));</pre><pre>}</pre><pre>}</pre><pre>}</pre><pre>}</pre><pre>else</pre><pre>CV_Error(Error::StsNotImplemented, &quot;Unknown output layer type: &quot; + outLayerType);</pre><pre>std::vector&lt;int&gt; indices;</pre><pre>NMSBoxes(boxes, confidences, confThreshold, nmsThreshold, indices);</pre><pre>for (size_t i = 0; i &lt; indices.size(); ++i) {</pre><pre>int idx = indices[i];</pre><pre>Rect box = boxes[idx];</pre><pre>drawPred(classIds[idx], confidences[idx], box.x, box.y,</pre><pre>box.x + box.width, box.y + box.height, frame);</pre><pre>}</pre><pre>}</pre><pre>void drawPred(int classId, float conf, int left, int top, int right, int bottom, Mat&amp; frame)</pre><pre>{</pre><pre>rectangle(frame, Point(left, top), Point(right, bottom), Scalar(0, 255, 0));</pre><pre>std::string label = format(&quot;%.2f&quot;, conf);</pre><pre>if (!classes.empty()) {</pre><pre>CV_Assert(classId &lt; (int)classes.size());</pre><pre>label = classes[classId] + &quot;: &quot; + label;</pre><pre>}</pre><pre>int baseLine;</pre><pre>Size labelSize = getTextSize(label, FONT_HERSHEY_SIMPLEX, 0.5, 1, &amp;baseLine);</pre><pre>top = max(top, labelSize.height);</pre><pre>rectangle(frame, Point(left, top - labelSize.height),</pre><pre>Point(left + labelSize.width, top + baseLine), Scalar::all(255), FILLED);</pre><pre>putText(frame, label, Point(left, top), FONT_HERSHEY_SIMPLEX, 0.5, Scalar());</pre><pre>}</pre><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GUs_zIZvb41Yc73bbYWm8w.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6f7d3a2d22f1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dnn Module Build with Cuda support on windows 10]]></title>
            <link>https://medium.com/@amar.bit.jsr/dnn-module-build-with-cuda-support-on-windows-10-3a2f3a736ca?source=rss-1f4f972f4a6b------2</link>
            <guid isPermaLink="false">https://medium.com/p/3a2f3a736ca</guid>
            <dc:creator><![CDATA[Amar Kumar]]></dc:creator>
            <pubDate>Sat, 15 Feb 2020 10:45:32 GMT</pubDate>
            <atom:updated>2020-02-15T13:56:19.312Z</atom:updated>
            <content:encoded><![CDATA[<p>I am assuming that you had setup the following tools:</p><ol><li>Cuda driver</li><li>visual studio</li><li>cuda toolkit.</li></ol><p>To build dnn I setup the following version of the tools:</p><p>Cuda driver 430</p><p>Visual studio 2015</p><p>cuda toolkit 10.0</p><p>I start the step by step how to build the dnn module on windows 10 with nvidia cuda support.</p><p>Step 1: Go to url: <a href="https://cmake.org/download/">https://cmake.org/download/</a> and dowload Windows win64-x64 Installer and install in system</p><p>Step 2 : Go to url: https:/<a href="https://opencv.org/releases/">/opencv.org/releases/ </a>download opencv 4.2 for windows.</p><p>Step 3: Go to url: <a href="https://github.com/opencv/opencv_contrib/releases">https://github.com/opencv/opencv_contrib/releases</a> and download in same version of the opencv contribe here is 4.2.</p><p>Step 4: Put both the folders in a common place as shown in below picture</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/846/1*eZJ4QxjWyaGot8EwqYHI1Q.png" /><figcaption><strong>Opencv and opencv_contrib in same folder</strong></figcaption></figure><p>Step5: Extract both the folders in same location as shown in below image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*vtTWtFCjY8jOFJ_qpJElJg.png" /><figcaption><strong>Extracted folders</strong></figcaption></figure><p>Step 5: Make a folder build inside the opencv-4.2.0. Then start the cmake. Select source code path and build path as shown in below figure and then click on configure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/671/1*sX3-RpMUO38XWgP-6kb82Q.png" /></figure><p>Step 6: Once you click on configuration button you will get a window where you have to configure visual studio version that you installed in your system and platform as shown below figure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/503/1*wLzFn4dplMMrTLDclPPeGQ.png" /></figure><p>Step 7: Wait for some time until configuration is done. After that we will select some specific configuration for our dnn modules which are very important. OPENCV_EXTRA_MODULES_PATH : &lt;your_path&gt;\opencv_contrib-4.2.0\modules</p><p>WITH_CUDA : Check (by default it unchek )</p><p>OPENCV_DNN_CUDA : check</p><p>BUILD_CUDA_STUBS : check</p><p>click on configuration once again. You will get configuration error shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/1*lvXZeLjk2ZM8Gl9tC5T6UA.png" /></figure><p>Step 8: After that we have to select compute capability for our GPU card. If you don’t know your card compute capability , no worry you can check on nvidia site. I am using GTX 1070 and its compute capability is 6.1, so based on this we have to configure CUDA_ARC_BIN.</p><p>By default value: 3.0 3.5 3.7 5.0 5.2 6.0 6.1 7.0 7.5</p><p>I changed this value to : 6.1 7.0 7.5,</p><p>as shown in below figure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*Jp_dckBPfpXDGdb8fJbDiQ.png" /></figure><p>Once you changed the CUDA_ARCH_BIN , once again click on configuration and wait till configuration is done.Once configuration is done click on Generate.</p><p>It will generate visual studio project file based on configuration.Once creation is successfully done. You will get open project option in same window. Click on it. Project will open in visual studio as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LLiPgSFF5V5YFOPHJ8bmGw.png" /></figure><p>Step 9: Now select the build type Release/Debug and architecture. I selected Release and x64 as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5KlaGBFjj6wSPoxHiU_rww.png" /></figure><p>Step 10: By default ALL_BUILD project is selected so only you have to click on build option. Go in build menu and click on Build solution or press F7 or right click on ALL_BUILD project and select build and wait for an hours because this takes times and build time very system to system.</p><p>Step 11: Build fails due to error in source file as shown in figure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9q-DjTXlJgRFupHL6ZoksA.png" /></figure><p>Open file cudnn.hpp and replace code from line 40 to 42 by below code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AzsknVSarZxdz1T2wbwedA.png" /></figure><p>open file grid_stride_range.hpp and replace code from 15 to 33 by</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1002/1*jDNIB0c7euLstVrPAqUeIA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/893/1*AolLuTaorsfOVUCCZE8U1w.png" /></figure><p>Step 12: Again build the solution after changing the code. Once the solution is build successfully you will get the message below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/921/1*4wVne10nFDe6KfhB7vBhVQ.png" /></figure><p>Note: you can build the install project this will put all the library files in install folder inside the build. My next article will illustrate the use of this library to get inference of yolov3.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3a2f3a736ca" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>