Sunday, May 10, 2020

Deep Learning 7-Object Detection with YOLO

Learn A-Z Deep Learning in 15 Days


In this Lecture, will learn about Objection Detection with Retinanet


You Only Look Once

YOLO first takes an input image. The framework then divides the input image into grids (say a n X n grid- Each grid predict):


  • Predicts B boundary boxes and each box has one box confidence score Pr(Object) ∗ IOU
  • Detects one object only regardless of the number of boxes B,
  • Predicts C conditional class probabilities (one per class for the likeliness of the object class).
  • The bounding boxes having the class probability above a threshold value is selected and used to locate the object within the image
  • Total loss = classification loss+ localization loss (errors between the predicted boundary box and the ground truth) + confidence loss (the objectness of the box)


Data Preprocessing with Kitti dataset


Categories                    frequency

  Car----------------------28742
Pedestrian----------------4487
  Van------------------------2914
Cyclist-------------------1627
Truck--------------------1094
Misc----------------------973
Tram----------------------511
Person_sitting------------222

  • Total annotation count = 40570
  • Total images = 7481



import pandas as pd

path="kitti/training/label_2/"

df = pd.DataFrame()

# iterate the list of files in the directory 'label_2'
for filename in os.listdir(path): 
    
    filepath= os.path.join(path,filename)
# read file in csv format  
    pdtxtdata=pd.read_csv(filepath, delimiter = ' ', header=None)
    
# create the folder 'updatelabel' in the current folder    
    with open('./updatelabel/'+filename,'a') as f: 
        
# iloc takes the values at 0,4,5,6,7 i,e class_name, xmin, ymin, xmax and ymax.
        for label, xmin, ymin, xmax, ymax in pdtxtdata.iloc[:,[0,4,5,6,7]].values:
# categories 'Pedestrian' and "Person_sitting" are considered
            if label=='Pedestrian' or label=="Person_sitting":
                f.write(str(0)+' '+str(xmin)+' '+str(ymin)+' '+str(xmax)+' '+str(ymax)+'\n')


# Remove the files with 0 size
import os
path="./updatelabel/"
# Iterate the list of files in the directory 'updatelabel'
for filename in os.listdir(path):
    filepath= os.path.join(path,filename)
    if os.path.getsize(filepath)==0:
        os.remove(filepath)

# Copy and change the file name 
import os
import shutil
path="./updatelabel/"
for filename in os.listdir(path):
    shutil.copy("/kitti/training/image_2/"+filename.split('.')[0]+'.png',"./yoloimagelabel/" +filename.split('.')[0]+'.png')

# Convert the kitti to Yolo format i.e (xmin, ymin, xmax ,ymax) to (x, y, w, h) 
import pandas as pd
path="./udatelabel/"
df = pd.DataFrame()
for filename in os.listdir(path):
    filepath= os.path.join(path,filename)
    image= cv2.imread("./image/"+filename.split('.')[0]+'.png')
    image_width= image.shape[1]
    image_height= image.shape[0]
    pdtxtdata=pd.read_csv(filepath, delimiter = ' ', header=None)
    with open('./yoloimagelabel/'+filename,'a') as f:
        for label, xmin, ymin, xmax, ymax in pdtxtdata.iloc[:,[0,1,2,3,4]].values:
            f.write(str(0)+' '+str('%.6f' % float((xmin+xmax)/(2.0*image_width)))+' '+str('%.6f' % float((ymin+ymax)/(2.0*image_height)))+' '+str('%.6f' % float((xmax-xmin)/image_width))+' '+str('%.6f' % float((ymax-ymin)/image_height))+'\n')

Total Images = 1796 & Total Annotation = 4709

# Split the train & test 
# Generate the train.txt and test.txt
import glob, os

current_dir = 'dataset'
# Percentage of images to be used for the test set
percentage_test = 20;
# Create and/or truncate train.txt and test.txt
file_train = open('train.txt', 'w')  
file_test = open('test.txt', 'w')
# Populate train.txt and test.txt
counter = 1  
index_test = round(100 / percentage_test)  
for pathAndFilename in glob.glob(os.path.join(current_dir, "*.*g")):  
if counter == index_test:
counter = 1
file_test.write(current_dir + "/" + os.path.basename(pathAndFilename) + "\n")
else:
file_train.write(current_dir + "/" + os.path.basename(pathAndFilename) + "\n")
counter = counter + 1
file_test.close()
file_train.close()

Run the below code on google colab

!git clone https://github.com/AlexeyAB/darknet.git

cd /content/darknet


Makefile

  • Download the Makefile
  • Change GPU = 1, CUDNN = 1 & OPENCV = 1
  • Upload the Modified Makefile in darknet folder





!make

!./darknet


Train & Test file

  • Upload the train & test file in darknet folder

cd /content/darknet/cfg


Obj.data


  • Create obj.data file ( as show figure)


  1. classes = 1
  2. train = train.txt
  3. valid = test.txt
  4. names = obj.names
  5. backup = backup/


  • Upload the in cfg folder



Obj.names
  • Create obj.data file and
  • write the name of all the categories ( as show figure)
    1. Person
  • Upload the in cfg folder



Yolov3 Network
  • Download the Yolov3.cfg from cfg folder
  • classes and filters params of [yolo] and [convolutional] layers that are just before the [yolo] layers
  • filters=(classes + 5) * 3. For a single class we should set filters= (1+5)*3 = 18
    1. classes = 1
    2. filters = 18
  • Upload the Yolov3.cfg to cfg folder

Download Weight

cd /content/darknet
!wget https://pjreddie.com/media/files/darknet19_448.conv.23

!./darknet detector train cfg/obj.data cfg/yolov3.cfg darknet19_448.conv.23 -dont_show 0



In the next blog, we will cover  Deeping Learning NLP.
https://sngurukuls247.blogspot.com/2018/09/python-ninja-bootcamp-1-course.html

                                                                                                                                                

Follow the link below to access Free Python Lectures-
https://www.youtube.com/sngurukul

Feel free contact me on-
Email - sn.gurukul24.7uk@gmail.com

19 comments:

  1. I am sure this post has touched all the internet visitors, its really really fastidious piece of writing on building up new website.
    pcmover professional torrent
    file viewer plus crack
    quicktime pro registration code
    airparrot torrent
    webcammax full
    Crack Like

    ReplyDelete
  2. With your presentation, you make it appear so simple, but I find this subject to be one that I believe I will never understand.
    It appears to be far too sophisticated and vast for me.
    I'm looking forward to reading your future post,
    I'll make an effort to grasp it!
    avs audio converter crack
    videosolo video converter crack
    manageengine desktop central crack
    idm crack patch serial number crack

    ReplyDelete
  3. With your presentation, you make it appear so simple, but I find this subject to be one that I believe I will never understand.
    It appears to be far too sophisticated and vast for me.
    I'm looking forward to reading your future post,
    I'll make an effort to grasp it!
    psi crack
    bandicut crack
    eset smart security crack
    advanced video compressor crack

    ReplyDelete
  4. . I hope that you continue to embrace your creativity and utilize it in your work for as long as possible.

    wirecast pro crack
    vuescan pro crack
    3d coat crack

    ReplyDelete
  5. Great post, but I wanted to know if you can write
    something else on this topic? I would really appreciate it if you can explain this.
    A bit more. Appreciation
    guitar pro crack
    daemon tools lite crack
    navicat premium crack
    stellar phoenix data recovery pro crack

    ReplyDelete
  6. Hi, I'm intrigued about your site because I have a similar one.
    Is there anything you can do? If this is the case, how can it be stopped?
    Do you have any dietary supplements or other products to suggest to us? Recently, I've received so much.
    It drives me nuts, so any help is greatly appreciated.
    free mp3 cutter and editor crack
    abelssoft win10 privacyfix crack
    windows 10 home crack
    aiseesoft data recovery crack

    ReplyDelete
  7. I'm impressed, to say the least. I've rarely come across a blog that's both educational and entertaining.
    me just say that your performance was flawless
    There are few men and women who are able to speak sensibly about a problem with their heads.
    I couldn't be happier to have discovered myself on this journey.
    There you go.
    roland zenbeats crack
    tenorshare ultdata ios for pc crack
    teracopy pro crack
    sparkocam crack

    ReplyDelete
  8. Excellent article. I really like it and I'm very impressed with your work in this article. Keep it up and keep sharing this kind of useful and useful information with us. Thank you for sharing with us.
    angry birds crack
    spark crack
    free mp3 cutter and editor crack
    videoproc crack

    ReplyDelete
  9. This is a great blog! Your site is loading too fast!
    What type of web server do you use? Can you send me an affiliate link for your web host?
    I hope my site loads as fast as yours.
    isobuster crack
    windows 10 pro crack
    microsoft project 2016 crack
    start menu crack activation code

    ReplyDelete
  10. I am very impressed with your post because this post is very beneficial for me and provide a new knowledge to me. this blog has detailed information, its much more to learn from your blog post.I would like to thank you for the effort you put into writing this page.
    I also hope that you will be able to check the same high-quality content later.Good work with the hard work you have done I appreciate your work thanks for sharing it. It Is very Wounder Full Post.This article is very helpful, I wondered about this amazing article.. This is very informative.
    “you are doing a great job, and give us up to dated information”.
    any-ebook-converter-1-2-0-crack-with-registration-code-free-download-2022/
    advanced-password-recovery-suite-1-3-0-crack-with-license-key-free-download-2022/
    internet-download-accelerator-pro-6-21-1-1675-crack-with-serial-key-free-download-2022/
    blufftitler-ultimate-15-5-0-0-crack-with-serial-key-free-download-2022/
    vovsoft-hide-files-6-9-crack-with-serial-key-free-download-2022/

    ReplyDelete
  11. IDM Crack is to continue your documents the last known point of interest. You can download the documents that are not finished because of PC closure and lost your web association.
    K7 TotalSecurity Activation Keys is one of the most well-known and advanced anti-spyware applications that lets you provide you with an environment that is secure and running.
    SwitchResX Crack is a versatile program that belongs to controls the screen to fix a resolution for the best option at the retina of it. This way is suitable for graphics designing, development to switch the layout for watching online movies and anything.

    ReplyDelete
  12. Your writing skill is outclass. download antivurs and safe your PC from Virus.
    Systweak Antivirus Premium Crack is available for all versions of Microsoft Windows, and even SP1 Plus.
    Through this antivirus, you can easily save yourself from digital malicious threats,
    and online attacks such as Trojan, PUP, and more unwanted applications.
    Systweak Antivirus Premium Crack

    ReplyDelete
  13. Sparkol VideoScribe crack is the creator of whiteboard animation tool. You can create your whiteboard video and compose it quickly. You can make videos with hand-drawn, images, animations and text. it uses a virtual whiteboard for an amazing video effect.
    Sparkol VideoScribe crack

    ReplyDelete
  14. CCleaner Pro Crack maintains the security and stability of your system. Furthermore, it has a very simple and compact user interface layout for performing all the operations for the optimization of your system.
    CCleaner Pro Crack

    ReplyDelete
  15. AVG PC TuneUp Crack
    AVG PC TuneUp Crack is an across-the-board suite that has been intended to keep you and all your family’s PCs running at ideal speed and proficiency.

    ReplyDelete