<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ashutosh Mohanty</title>
    <description>The latest articles on DEV Community by Ashutosh Mohanty (@ashutoshgeek).</description>
    <link>https://dev.to/ashutoshgeek</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F394174%2Fc37f7a97-bfc6-420a-9727-6345467244e5.jpg</url>
      <title>DEV Community: Ashutosh Mohanty</title>
      <link>https://dev.to/ashutoshgeek</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ashutoshgeek"/>
    <language>en</language>
    <item>
      <title>Getting started with YOLOv4: Real-Time object detection @ 30FPS</title>
      <dc:creator>Ashutosh Mohanty</dc:creator>
      <pubDate>Sun, 02 Aug 2020 13:21:30 +0000</pubDate>
      <link>https://dev.to/spectrumcetb/getting-started-with-yolov4-real-time-object-detection-30fps-2fo1</link>
      <guid>https://dev.to/spectrumcetb/getting-started-with-yolov4-real-time-object-detection-30fps-2fo1</guid>
      <description>&lt;p&gt;Ten years ago, computer vision researchers thought that getting a computer to tell the difference between a cat and a dog would be almost impossible, even with the significant advance in the state of artificial intelligence. But now using image classification computers can not only detect the object but also can categorize thousand different types.&lt;/p&gt;

&lt;p&gt;Object detection is not a new term. It was there from the 1980s but the problem with it was the accuracy and speed.&lt;/p&gt;

&lt;p&gt;The reason being why speed is more important in this field is whenever we detect the object using traditional methods of open-cv and python the entire state of the environment was changed, making the use of that technology in real-world was limited.&lt;/p&gt;

&lt;p&gt;YOLO (You Ony Look Once) changed the entire scenario when it came out in 2017.&lt;/p&gt;

&lt;p&gt;Let's get started with how to detect objects with YOLOv4&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt;&lt;br&gt;
We will use Google colab to run our code. Go to &lt;a href="https://colab.research.google.com/"&gt;colab.research.google.com&lt;/a&gt; and create a new notebook.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt;&lt;br&gt;
Connect google drive to colab to be able to run the detector on our desired picture or video.&lt;/p&gt;

&lt;p&gt;Run the below code in a new cell&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from google.colab import drive
drive.mount('/content/gdrive')
# this creates a symbolic link so that now the path /content/gdrive/My\ Drive/ is equal to /mydrive
!ln -s /content/gdrive/My\ Drive/ /mydrive
!ls /mydrive
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt;&lt;br&gt;
clone darknet repo. Run this in a new cell&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;!git clone https://github.com/AlexeyAB/darknet
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt;&lt;br&gt;
change the makefile to have GPU and OPENCV enabled&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;%cd darknet
!sed -i 's/OPENCV=0/OPENCV=1/' Makefile
!sed -i 's/GPU=0/GPU=1/' Makefile
!sed -i 's/CUDNN=0/CUDNN=1/' Makefile
!sed -i 's/CUDNN_HALF=0/CUDNN_HALF=1/' Makefile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 5:&lt;/strong&gt;(optional)&lt;br&gt;
verify CUDA&lt;br&gt;
&lt;code&gt;!/usr/local/cuda/bin/nvcc --version&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 6:&lt;/strong&gt;&lt;br&gt;
Builds darknet so that you can then use the darknet executable file to run or train object detectors.&lt;br&gt;
&lt;code&gt;!make&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 7:&lt;/strong&gt;&lt;br&gt;
Download yolov4 weight file &lt;br&gt;
&lt;code&gt;!wget https://github.com/AlexeyAB/darknet/releases/download/darknet_yolo_v3_optimal/yolov4.weights&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 8:&lt;/strong&gt;(optional)&lt;br&gt;
These three functions will help to directly upload and download files from your local computer to google colab. This step is only if your not using google drive(step 2).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def imShow(path):
  import cv2
  import matplotlib.pyplot as plt
  %matplotlib inline

  image = cv2.imread(path)
  height, width = image.shape[:2]
  resized_image = cv2.resize(image,(3*width, 3*height), interpolation = cv2.INTER_CUBIC)

  fig = plt.gcf()
  fig.set_size_inches(18, 10)
  plt.axis("off")
  plt.imshow(cv2.cvtColor(resized_image, cv2.COLOR_BGR2RGB))
  plt.show()

# use this to upload files
def upload():
  from google.colab import files
  uploaded = files.upload() 
  for name, data in uploaded.items():
    with open(name, 'wb') as f:
      f.write(data)
      print ('saved file', name)

# use this to download a file  
def download(path):
  from google.colab import files
  files.download(path)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 9:&lt;/strong&gt;&lt;br&gt;
Run Your Detections with Darknet and YOLOv4!&lt;/p&gt;

&lt;p&gt;&lt;code&gt;!./darknet detector test &amp;lt;path to .data file&amp;gt; &amp;lt;path to config&amp;gt; &amp;lt;path to weights&amp;gt; &amp;lt;path to image&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
run darknet detection on test images&lt;br&gt;
&lt;code&gt;!./darknet detector test cfg/coco.data cfg/yolov4.cfg yolov4.weights data/person.jpg&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;For video&lt;br&gt;
&lt;code&gt;!./darknet detector demo cfg/coco.data cfg/yolov4.cfg yolov4.weights -dont_show test.mp4 -i 0 -out_filename results.avi&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Here are some results&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ocIdw6bq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://spectrumcet.com/assets/objectdetection1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ocIdw6bq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://spectrumcet.com/assets/objectdetection1.png" alt="object detected"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--x5vrPoPW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://spectrumcet.com/assets/objectdetection2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--x5vrPoPW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://spectrumcet.com/assets/objectdetection2.png" alt="object detected 2"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/vTQ4foYOAVg"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Thank you!!&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
