How YOLOV5 solved an ambiguity encountered by YOLOv3 | Towards Data Science

To the ones who not might be knowing, a new version of YOLO (You Only Look Once) is here, namely YOLO v5. Many thanks to Ultralytics for putting this repository together.
You only look once (YOLO) is a state-of-the-art, real-time object detection system. On a Pascal Titan X it processes images at 30 FPS and has a mAP of 57.9% on COCO test-dev.
YOLOv3 is extremely fast and accurate. In mAP measured at .5 IOU YOLOv3 is on par with Focal Loss but about 4x faster. Moreover, you can easily tradeoff between speed and accuracy simply by changing the size of the model, no retraining required!
YOLOv3 has a problem though, despite being so accurate, it is biased. The bias is towards the size of the object in the image. If encountered with bigger objects while training, it cannot detect the same object of a smaller scale perfectly.
YOLOv3 detects features in images and learn how to recognize objects with this information. Layers near the start detecting really simple features like edges and layers that are deeper can detect more complex features like eyes, noses, or an entire face. It then uses all of these features which it has learned, to make a final prediction. Herein lies the flaws of this system — there is no spatial that is used anywhere in a CNN and the pooling function that is used to connect layers is rendered inefficient.
YOLOv5
YOLOv5 consists of three parts :
Model BackboneModel headModel neck
Model Backbone
Model head
Model neck
The model head helps in the process of feature extraction. The model backbone consists of CSP Nets which help extract essential features from tensor passed through the model head. CSPNets enable quicker inference as well. The tensor from the model backbone is passed through the model neck which has feature pyramids, which try to eliminate bias with respect to size of objects.
To know more about feature pyramids, check this out
arxiv.org
To know more about YOLOv5, check this out.
blog.roboflow.ai
Check out the YOLO v5 repository at
github.com
For our use case, I have created a similar repository at
github.com
git clone https://github.com/sid0312/anpr_yolov5cd anpr_yolov5
To detect a license plate in the car image, save it in the sample_cars folder of the directory. Name it as example.jpg
python detect.py --source sample_cars/example.jpg  --weights weights/best.pt --conf 0.4
Get the final image in the inference/output directory . To get an intuition of the detection process, check out the following notebook
!git clone https://github.com/sid0312/anpr_yolov5

Cloning into 'anpr_yolov5'...
remote: Enumerating objects: 42, done.
remote: Counting objects: 100% (42/42), done.
remote: Compressing objects: 100% (39/39), done.
remote: Total 611 (delta 19), reused 15 (delta 3), pack-reused 569
Receiving objects: 100% (611/611), 63.42 MiB | 25.97 MiB/s, done.
Resolving deltas: 100% (46/46), done.

%cd anpr_yolov5/

/content/anpr_yolov5

!python detect.py --source sample_cars/  --weights weights/last.pt --conf 0.4

Namespace(agnostic_nms=False, augment=False, classes=None, conf_thres=0.4, device='', fourcc='mp4v', img_size=640, iou_thres=0.5, output='inference/output', save_txt=False, source='sample_cars/', view_img=False, weights='weights/last.pt')
Using CUDA device0 _CudaDeviceProperties(name='Tesla K80', total_memory=11441MB)

image 1/5 sample_cars/car_0.jpg: 448x640 1 license_plates, Done. (0.056s)
image 2/5 sample_cars/car_1.jpg: 384x640 Done. (0.025s)
image 3/5 sample_cars/car_2.jpg: 512x640 1 license_plates, Done. (0.028s)
image 4/5 sample_cars/car_3.jpg: 448x640 1 license_plates, Done. (0.027s)
image 5/5 sample_cars/car_4.jpg: 512x640 2 license_plates, Done. (0.028s)
Results saved to /content/anpr_yolov5/inference/output
Done. (0.785s)

import os
print(os.listdir('/content/anpr_yolov5/inference/output'))

['car_0.jpg', 'car_1.jpg', 'car_3.jpg', 'car_2.jpg', 'car_4.jpg']

from google.colab import files

for img in os.listdir('/content/anpr_yolov5/inference/output'):
  path = os.path.join('/content/anpr_yolov5/inference/output',img)
  files.download(path)

 

Here are some results
This repository included the following changes to the original utlralytics repository
Created data/license_plate.yaml
Data Preparation
Step 1- Download the starter dataset in JSON format from
www.kaggle.com
This serves as our starting dataset. Upload the JSON file to your Google Drive
Step 2- Conversion of the JSON starter dataset to YOLO format
from google.colab import drive
drive.mount('/content/drive')

Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount("/content/drive", force_remount=True).

import pandas as pd
import numpy as np
import urllib
import matplotlib.pyplot as plt
import cv2
import glob,os,time
from PIL import Image

json_path = '/content/drive/My Drive/Indian_Number_plates.json'

data = pd.read_json(json_path,lines=True)

data.head()

os.mkdir('License Plates')

data['annotation'][0]

[{'imageHeight': 466,
  'imageWidth': 806,
  'label': ['number_plate'],
  'notes': '',
  'points': [{'x': 0.722084367245657, 'y': 0.5879828326180251},
   {'x': 0.8684863523573201, 'y': 0.688841201716738}]}]
print(len(data))

237

dataset = {}
vals = ['name','height','width','top_x','top_y','bottom_x','bottom_y']
for i in vals:
  dataset[i] = list()
count = 0
for idx,row in data.iterrows():
  img = urllib.request.urlopen(row["content"])
  img = Image.open(img)
  img = img.convert('RGB')
  img.save("/content/License Plates/car_{}.jpeg".format(count),'JPEG')
  dataset['name'].append('car_{}'.format(count))
  annotation = row['annotation']
  dataset['height'].append(annotation[0]['imageHeight'])
  dataset['width'].append(annotation[0]['imageWidth'])
  dataset['top_x'].append(annotation[0]['points'][0]['x'])
  dataset['top_y'].append(annotation[0]['points'][0]['y'])
  dataset['bottom_x'].append(annotation[0]['points'][1]['x'])
  dataset['bottom_y'].append(annotation[0]['points'][1]['y']) 
  count =count+1
  if count%10==0:
    print('Downloaded.. {}/{}'.format(count,len(data)))  
  if count%len(data)==0:
    print('Loading last image.. {}/{}'.format(count,len(data)))  
print('{} images downloaded'.format(count))                                              

Downloaded.. 10/237
Downloaded.. 20/237
Downloaded.. 30/237
Downloaded.. 40/237
Downloaded.. 50/237
Downloaded.. 60/237
Downloaded.. 70/237
Downloaded.. 80/237
Downloaded.. 90/237
Downloaded.. 100/237
Downloaded.. 110/237
Downloaded.. 120/237
Downloaded.. 130/237
Downloaded.. 140/237
Downloaded.. 150/237
Downloaded.. 160/237
Downloaded.. 170/237
Downloaded.. 180/237
Downloaded.. 190/237
Downloaded.. 200/237
Downloaded.. 210/237
Downloaded.. 220/237
Downloaded.. 230/237
Loading last image.. 237/237
237 images downloaded

df = pd.DataFrame(dataset)

df.head()

df.to_csv('license_plates.csv',index=False)

csv_path = '/content/license_plates.csv'

licenses = pd.read_csv(csv_path)
licenses.tail()

licenses['name'] = licenses['name'] + '.jpeg'

licenses.head()

licenses.drop(columns=['height','width'],inplace=True)

licenses.head()

widths,heights =[],[]
center_x,center_y=[],[]
for i in range(len(licenses)):
  widths.append(licenses['bottom_x'][i]- licenses['top_x'][i])
  heights.append(licenses['bottom_y'][i]- licenses['top_y'][i])
  center_x.append((licenses['bottom_x'][i] + licenses['top_x'][i])/2)
  center_y.append((licenses['bottom_y'][i] + licenses['top_y'][i])/2)
lic = pd.DataFrame(columns=['x','y','w','h'])
lic['w'] = widths
lic['h'] = heights
lic['x'] = center_x
lic['y'] = center_y

lic.head()

for i in range(len(lic)):
  f = open('/content/License Plates/car_{}.txt'.format(i),'w+')
  f.write('{} {} {} {} {}'.format(0,lic['x'][i],lic['y'][i],lic['w'][i],lic['h'][i]))
  f.close()

 

!zip -r /content/file.zip /content/License\ Plates
from google.colab import files
files.download("/content/file.zip")

  adding: content/License Plates/ (stored 0%)
  adding: content/License Plates/car_86.jpeg (deflated 1%)
  adding: content/License Plates/car_83.txt (deflated 27%)
  adding: content/License Plates/car_64.txt (deflated 28%)
  adding: content/License Plates/car_154.jpeg (deflated 1%)
  adding: content/License Plates/car_21.jpeg (deflated 1%)
  adding: content/License Plates/car_209.jpeg (deflated 1%)
  adding: content/License Plates/car_217.txt (deflated 37%)
  adding: content/License Plates/car_190.jpeg (deflated 2%)
  adding: content/License Plates/car_91.jpeg (deflated 1%)
  adding: content/License Plates/car_23.jpeg (deflated 0%)
  adding: content/License Plates/car_102.txt (deflated 29%)
  adding: content/License Plates/car_228.jpeg (deflated 1%)
  adding: content/License Plates/car_231.jpeg (deflated 2%)
  adding: content/License Plates/car_46.txt (deflated 27%)
  adding: content/License Plates/car_199.jpeg (deflated 0%)
  adding: content/License Plates/car_163.jpeg (deflated 1%)
  adding: content/License Plates/car_40.jpeg (deflated 0%)
  adding: content/License Plates/car_43.txt (deflated 29%)
  adding: content/License Plates/car_38.jpeg (deflated 1%)
  adding: content/License Plates/car_93.jpeg (deflated 1%)
  adding: content/License Plates/car_227.jpeg (deflated 1%)
  adding: content/License Plates/car_204.txt (deflated 38%)
  adding: content/License Plates/car_106.jpeg (deflated 1%)
  adding: content/License Plates/car_152.txt (deflated 32%)
  adding: content/License Plates/car_221.jpeg (deflated 0%)
  adding: content/License Plates/car_212.txt (deflated 37%)
  adding: content/License Plates/car_60.jpeg (deflated 1%)
  adding: content/License Plates/car_39.txt (deflated 56%)
  adding: content/License Plates/car_126.jpeg (deflated 0%)
  adding: content/License Plates/car_213.txt (deflated 30%)
  adding: content/License Plates/car_181.txt (deflated 34%)
  adding: content/License Plates/car_198.txt (deflated 36%)
  adding: content/License Plates/car_156.jpeg (deflated 0%)
  adding: content/License Plates/car_178.txt (deflated 30%)
  adding: content/License Plates/car_68.txt (deflated 32%)
  adding: content/License Plates/car_82.jpeg (deflated 1%)
  adding: content/License Plates/car_217.jpeg (deflated 1%)
  adding: content/License Plates/car_224.jpeg (deflated 3%)
  adding: content/License Plates/car_216.jpeg (deflated 0%)
  adding: content/License Plates/car_141.txt (deflated 33%)
  adding: content/License Plates/car_101.txt (deflated 32%)
  adding: content/License Plates/car_174.txt (deflated 47%)
  adding: content/License Plates/car_2.txt (deflated 29%)
  adding: content/License Plates/car_39.jpeg (deflated 2%)
  adding: content/License Plates/car_220.jpeg (deflated 1%)
  adding: content/License Plates/car_26.jpeg (deflated 2%)
  adding: content/License Plates/car_200.txt (deflated 30%)
  adding: content/License Plates/car_129.txt (deflated 45%)
  adding: content/License Plates/car_202.txt (deflated 52%)
  adding: content/License Plates/car_186.jpeg (deflated 1%)
  adding: content/License Plates/car_27.jpeg (deflated 1%)
  adding: content/License Plates/car_19.txt (deflated 27%)
  adding: content/License Plates/car_110.txt (deflated 53%)
  adding: content/License Plates/car_196.txt (deflated 22%)
  adding: content/License Plates/car_20.jpeg (deflated 1%)
  adding: content/License Plates/car_145.txt (deflated 45%)
  adding: content/License Plates/car_164.jpeg (deflated 0%)
  adding: content/License Plates/car_14.jpeg (deflated 1%)
  adding: content/License Plates/car_142.jpeg (deflated 1%)
  adding: content/License Plates/car_86.txt (deflated 31%)
  adding: content/License Plates/car_190.txt (deflated 32%)
  adding: content/License Plates/car_146.jpeg (deflated 1%)
  adding: content/License Plates/car_139.jpeg (deflated 1%)
  adding: content/License Plates/car_91.txt (deflated 36%)
  adding: content/License Plates/car_59.jpeg (deflated 2%)
  adding: content/License Plates/car_155.txt (deflated 42%)
  adding: content/License Plates/car_116.jpeg (deflated 1%)
  adding: content/License Plates/car_192.txt (deflated 27%)
  adding: content/License Plates/car_34.jpeg (deflated 0%)
  adding: content/License Plates/car_36.txt (deflated 47%)
  adding: content/License Plates/car_31.jpeg (deflated 2%)
  adding: content/License Plates/car_122.jpeg (deflated 2%)
  adding: content/License Plates/car_120.txt (deflated 33%)
  adding: content/License Plates/car_59.txt (deflated 29%)
  adding: content/License Plates/car_150.txt (deflated 28%)
  adding: content/License Plates/car_69.txt (deflated 32%)
  adding: content/License Plates/car_51.jpeg (deflated 0%)
  adding: content/License Plates/car_90.jpeg (deflated 1%)
  adding: content/License Plates/car_44.jpeg (deflated 1%)
  adding: content/License Plates/car_128.txt (deflated 28%)
  adding: content/License Plates/car_199.txt (deflated 47%)
  adding: content/License Plates/car_87.txt (deflated 29%)
  adding: content/License Plates/car_186.txt (deflated 38%)
  adding: content/License Plates/car_99.txt (deflated 27%)
  adding: content/License Plates/car_97.jpeg (deflated 2%)
  adding: content/License Plates/car_37.jpeg (deflated 1%)
  adding: content/License Plates/car_193.txt (deflated 46%)
  adding: content/License Plates/car_117.txt (deflated 56%)
  adding: content/License Plates/car_124.jpeg (deflated 1%)
  adding: content/License Plates/car_73.txt (deflated 29%)
  adding: content/License Plates/car_121.txt (deflated 28%)
  adding: content/License Plates/car_33.jpeg (deflated 0%)
  adding: content/License Plates/car_100.txt (deflated 27%)
  adding: content/License Plates/car_109.txt (deflated 28%)
  adding: content/License Plates/car_90.txt (deflated 33%)
  adding: content/License Plates/car_157.txt (deflated 28%)
  adding: content/License Plates/car_65.jpeg (deflated 2%)
  adding: content/License Plates/car_111.jpeg (deflated 0%)
  adding: content/License Plates/car_211.txt (deflated 13%)
  adding: content/License Plates/car_134.jpeg (deflated 1%)
  adding: content/License Plates/car_20.txt (deflated 35%)
  adding: content/License Plates/car_197.txt (deflated 49%)
  adding: content/License Plates/car_25.jpeg (deflated 0%)
  adding: content/License Plates/car_219.jpeg (deflated 1%)
  adding: content/License Plates/car_29.txt (deflated 34%)
  adding: content/License Plates/car_152.jpeg (deflated 1%)
  adding: content/License Plates/car_167.jpeg (deflated 0%)
  adding: content/License Plates/car_89.txt (deflated 29%)
  adding: content/License Plates/car_62.jpeg (deflated 2%)
  adding: content/License Plates/car_58.txt (deflated 34%)
  adding: content/License Plates/car_0.txt (deflated 30%)
  adding: content/License Plates/car_105.txt (deflated 38%)
  adding: content/License Plates/car_60.txt (deflated 29%)
  adding: content/License Plates/car_235.jpeg (deflated 0%)
  adding: content/License Plates/car_177.jpeg (deflated 1%)
  adding: content/License Plates/car_2.jpeg (deflated 1%)
  adding: content/License Plates/car_131.jpeg (deflated 1%)
  adding: content/License Plates/car_15.txt (deflated 29%)
  adding: content/License Plates/car_70.jpeg (deflated 1%)
  adding: content/License Plates/car_97.txt (deflated 40%)
  adding: content/License Plates/car_95.txt (deflated 28%)
  adding: content/License Plates/car_146.txt (deflated 35%)
  adding: content/License Plates/car_8.txt (deflated 29%)
  adding: content/License Plates/car_173.jpeg (deflated 1%)
  adding: content/License Plates/car_42.txt (deflated 38%)
  adding: content/License Plates/car_175.jpeg (deflated 6%)
  adding: content/License Plates/car_114.jpeg (deflated 4%)
  adding: content/License Plates/car_77.txt (deflated 28%)
  adding: content/License Plates/car_140.txt (deflated 31%)
  adding: content/License Plates/car_11.jpeg (deflated 0%)
  adding: content/License Plates/car_10.jpeg (deflated 0%)
  adding: content/License Plates/car_123.jpeg (deflated 0%)
  adding: content/License Plates/car_28.jpeg (deflated 0%)
  adding: content/License Plates/car_115.txt (deflated 53%)
  adding: content/License Plates/car_183.txt (deflated 37%)
  adding: content/License Plates/car_114.txt (deflated 34%)
  adding: content/License Plates/car_168.jpeg (deflated 1%)
  adding: content/License Plates/car_7.jpeg (deflated 0%)
  adding: content/License Plates/car_10.txt (deflated 37%)
  adding: content/License Plates/car_167.txt (deflated 38%)
  adding: content/License Plates/car_76.jpeg (deflated 0%)
  adding: content/License Plates/car_185.txt (deflated 30%)
  adding: content/License Plates/car_57.txt (deflated 30%)
  adding: content/License Plates/car_179.jpeg (deflated 1%)
  adding: content/License Plates/car_76.txt (deflated 43%)
  adding: content/License Plates/car_180.jpeg (deflated 1%)
  adding: content/License Plates/car_209.txt (deflated 29%)
  adding: content/License Plates/car_192.jpeg (deflated 1%)
  adding: content/License Plates/car_107.txt (deflated 31%)
  adding: content/License Plates/car_22.jpeg (deflated 0%)
  adding: content/License Plates/car_206.txt (deflated 27%)
  adding: content/License Plates/car_131.txt (deflated 42%)
  adding: content/License Plates/car_14.txt (deflated 16%)
  adding: content/License Plates/car_129.jpeg (deflated 1%)
  adding: content/License Plates/car_66.jpeg (deflated 1%)
  adding: content/License Plates/car_117.jpeg (deflated 0%)
  adding: content/License Plates/car_188.jpeg (deflated 1%)
  adding: content/License Plates/car_211.jpeg (deflated 1%)
  adding: content/License Plates/car_48.txt (deflated 28%)
  adding: content/License Plates/car_234.jpeg (deflated 0%)
  adding: content/License Plates/car_162.jpeg (deflated 3%)
  adding: content/License Plates/car_230.txt (deflated 29%)
  adding: content/License Plates/car_105.jpeg (deflated 2%)
  adding: content/License Plates/car_118.txt (deflated 43%)
  adding: content/License Plates/car_34.txt (deflated 28%)
  adding: content/License Plates/car_127.txt (deflated 29%)
  adding: content/License Plates/car_33.txt (deflated 30%)
  adding: content/License Plates/car_172.txt (deflated 24%)
  adding: content/License Plates/car_71.txt (deflated 28%)
  adding: content/License Plates/car_132.jpeg (deflated 1%)
  adding: content/License Plates/car_25.txt (deflated 40%)
  adding: content/License Plates/car_77.jpeg (deflated 1%)
  adding: content/License Plates/car_84.jpeg (deflated 1%)
  adding: content/License Plates/car_38.txt (deflated 33%)
  adding: content/License Plates/car_103.txt (deflated 29%)
  adding: content/License Plates/car_180.txt (deflated 29%)
  adding: content/License Plates/car_66.txt (deflated 29%)
  adding: content/License Plates/car_193.jpeg (deflated 1%)
  adding: content/License Plates/car_126.txt (deflated 39%)
  adding: content/License Plates/car_123.txt (deflated 38%)
  adding: content/License Plates/car_24.txt (deflated 34%)
  adding: content/License Plates/car_181.jpeg (deflated 0%)
  adding: content/License Plates/car_161.jpeg (deflated 0%)
  adding: content/License Plates/car_15.jpeg (deflated 1%)
  adding: content/License Plates/car_48.jpeg (deflated 1%)
  adding: content/License Plates/car_32.jpeg (deflated 0%)
  adding: content/License Plates/car_158.jpeg (deflated 1%)
  adding: content/License Plates/car_26.txt (deflated 39%)
  adding: content/License Plates/car_195.txt (deflated 29%)
  adding: content/License Plates/car_41.txt (deflated 37%)
  adding: content/License Plates/car_173.txt (deflated 16%)
  adding: content/License Plates/car_89.jpeg (deflated 1%)
  adding: content/License Plates/car_74.jpeg (deflated 1%)
  adding: content/License Plates/car_16.jpeg (deflated 0%)
  adding: content/License Plates/car_113.jpeg (deflated 1%)
  adding: content/License Plates/car_84.txt (deflated 33%)
  adding: content/License Plates/car_45.jpeg (deflated 1%)
  adding: content/License Plates/car_140.jpeg (deflated 1%)
  adding: content/License Plates/car_116.txt (deflated 60%)
  adding: content/License Plates/car_145.jpeg (deflated 0%)
  adding: content/License Plates/car_168.txt (deflated 32%)
  adding: content/License Plates/car_177.txt (deflated 49%)
  adding: content/License Plates/car_175.txt (deflated 39%)
  adding: content/License Plates/car_159.txt (deflated 29%)
  adding: content/License Plates/car_174.jpeg (deflated 1%)
  adding: content/License Plates/car_41.jpeg (deflated 1%)
  adding: content/License Plates/car_72.jpeg (deflated 2%)
  adding: content/License Plates/car_232.jpeg (deflated 1%)
  adding: content/License Plates/car_234.txt (deflated 28%)
  adding: content/License Plates/car_69.jpeg (deflated 1%)
  adding: content/License Plates/car_205.txt (deflated 28%)
  adding: content/License Plates/car_235.txt (deflated 29%)
  adding: content/License Plates/car_13.jpeg (deflated 0%)
  adding: content/License Plates/car_125.txt (deflated 53%)
  adding: content/License Plates/car_9.txt (deflated 22%)
  adding: content/License Plates/car_5.txt (deflated 29%)
  adding: content/License Plates/car_169.txt (deflated 43%)
  adding: content/License Plates/car_187.jpeg (deflated 1%)
  adding: content/License Plates/car_137.txt (deflated 38%)
  adding: content/License Plates/car_6.txt (deflated 31%)
  adding: content/License Plates/car_122.txt (deflated 15%)
  adding: content/License Plates/car_75.txt (deflated 36%)
  adding: content/License Plates/car_18.txt (deflated 32%)
  adding: content/License Plates/car_17.txt (deflated 29%)
  adding: content/License Plates/car_148.jpeg (deflated 1%)
  adding: content/License Plates/car_83.jpeg (deflated 1%)
  adding: content/License Plates/car_207.txt (deflated 28%)
  adding: content/License Plates/car_31.txt (deflated 28%)
  adding: content/License Plates/car_119.jpeg (deflated 3%)
  adding: content/License Plates/car_54.txt (deflated 16%)
  adding: content/License Plates/car_171.jpeg (deflated 3%)
  adding: content/License Plates/car_80.jpeg (deflated 1%)
  adding: content/License Plates/car_191.txt (deflated 42%)
  adding: content/License Plates/car_103.jpeg (deflated 6%)
  adding: content/License Plates/car_118.jpeg (deflated 8%)
  adding: content/License Plates/car_160.txt (deflated 28%)
  adding: content/License Plates/car_12.txt (deflated 33%)
  adding: content/License Plates/car_187.txt (deflated 52%)
  adding: content/License Plates/car_183.jpeg (deflated 0%)
  adding: content/License Plates/car_191.jpeg (deflated 0%)
  adding: content/License Plates/car_143.jpeg (deflated 1%)
  adding: content/License Plates/car_7.txt (deflated 36%)
  adding: content/License Plates/car_11.txt (deflated 23%)
  adding: content/License Plates/car_149.jpeg (deflated 1%)
  adding: content/License Plates/car_158.txt (deflated 14%)
  adding: content/License Plates/car_138.jpeg (deflated 1%)
  adding: content/License Plates/car_92.jpeg (deflated 1%)
  adding: content/License Plates/car_13.txt (deflated 37%)
  adding: content/License Plates/car_47.jpeg (deflated 0%)
  adding: content/License Plates/car_35.jpeg (deflated 0%)
  adding: content/License Plates/car_94.txt (deflated 36%)
  adding: content/License Plates/car_135.jpeg (deflated 0%)
  adding: content/License Plates/car_223.jpeg (deflated 1%)
  adding: content/License Plates/car_137.jpeg (deflated 0%)
  adding: content/License Plates/car_214.jpeg (deflated 1%)
  adding: content/License Plates/car_63.jpeg (deflated 1%)
  adding: content/License Plates/car_87.jpeg (deflated 1%)
  adding: content/License Plates/car_57.jpeg (deflated 0%)
  adding: content/License Plates/car_220.txt (deflated 37%)
  adding: content/License Plates/car_6.jpeg (deflated 1%)
  adding: content/License Plates/car_144.jpeg (deflated 1%)
  adding: content/License Plates/car_156.txt (deflated 30%)
  adding: content/License Plates/car_82.txt (deflated 29%)
  adding: content/License Plates/car_229.txt (deflated 35%)
  adding: content/License Plates/car_204.jpeg (deflated 2%)
  adding: content/License Plates/car_176.txt (deflated 53%)
  adding: content/License Plates/car_43.jpeg (deflated 2%)
  adding: content/License Plates/car_3.jpeg (deflated 0%)
  adding: content/License Plates/car_228.txt (deflated 29%)
  adding: content/License Plates/car_73.jpeg (deflated 1%)
  adding: content/License Plates/car_100.jpeg (deflated 3%)
  adding: content/License Plates/car_148.txt (deflated 38%)
  adding: content/License Plates/car_225.txt (deflated 16%)
  adding: content/License Plates/car_81.jpeg (deflated 1%)
  adding: content/License Plates/car_94.jpeg (deflated 1%)
  adding: content/License Plates/car_112.jpeg (deflated 1%)
  adding: content/License Plates/car_157.jpeg (deflated 1%)
  adding: content/License Plates/car_74.txt (deflated 25%)
  adding: content/License Plates/car_143.txt (deflated 32%)
  adding: content/License Plates/car_80.txt (deflated 29%)
  adding: content/License Plates/car_207.jpeg (deflated 2%)
  adding: content/License Plates/car_95.jpeg (deflated 1%)
  adding: content/License Plates/car_18.jpeg (deflated 1%)
  adding: content/License Plates/car_50.txt (deflated 42%)
  adding: content/License Plates/car_218.txt (deflated 19%)
  adding: content/License Plates/car_201.jpeg (deflated 1%)
  adding: content/License Plates/car_216.txt (deflated 47%)
  adding: content/License Plates/car_111.txt (deflated 48%)
  adding: content/License Plates/car_49.jpeg (deflated 1%)
  adding: content/License Plates/car_144.txt (deflated 38%)
  adding: content/License Plates/car_134.txt (deflated 28%)
  adding: content/License Plates/car_232.txt (deflated 36%)
  adding: content/License Plates/car_130.jpeg (deflated 8%)
  adding: content/License Plates/car_96.jpeg (deflated 12%)
  adding: content/License Plates/car_222.txt (deflated 59%)
  adding: content/License Plates/car_22.txt (deflated 28%)
  adding: content/License Plates/car_159.jpeg (deflated 0%)
  adding: content/License Plates/car_30.txt (deflated 29%)
  adding: content/License Plates/car_55.jpeg (deflated 1%)
  adding: content/License Plates/car_182.txt (deflated 29%)
  adding: content/License Plates/car_160.jpeg (deflated 0%)
  adding: content/License Plates/car_9.jpeg (deflated 0%)
  adding: content/License Plates/car_170.txt (deflated 34%)
  adding: content/License Plates/car_1.txt (deflated 28%)
  adding: content/License Plates/car_213.jpeg (deflated 2%)
  adding: content/License Plates/car_112.txt (deflated 35%)
  adding: content/License Plates/car_98.txt (deflated 28%)
  adding: content/License Plates/car_210.jpeg (deflated 1%)
  adding: content/License Plates/car_230.jpeg (deflated 1%)
  adding: content/License Plates/car_128.jpeg (deflated 1%)
  adding: content/License Plates/car_233.jpeg (deflated 1%)
  adding: content/License Plates/car_61.txt (deflated 37%)
  adding: content/License Plates/car_21.txt (deflated 32%)
  adding: content/License Plates/car_166.txt (deflated 48%)
  adding: content/License Plates/car_104.jpeg (deflated 1%)
  adding: content/License Plates/car_16.txt (deflated 31%)
  adding: content/License Plates/car_4.txt (deflated 29%)
  adding: content/License Plates/car_37.txt (deflated 32%)
  adding: content/License Plates/car_210.txt (deflated 28%)
  adding: content/License Plates/car_102.jpeg (deflated 1%)
  adding: content/License Plates/car_61.jpeg (deflated 1%)
  adding: content/License Plates/car_227.txt (deflated 30%)
  adding: content/License Plates/car_50.jpeg (deflated 0%)
  adding: content/License Plates/car_0.jpeg (deflated 0%)
  adding: content/License Plates/car_224.txt (deflated 34%)
  adding: content/License Plates/car_219.txt (deflated 30%)
  adding: content/License Plates/car_182.jpeg (deflated 0%)
  adding: content/License Plates/car_45.txt (deflated 31%)
  adding: content/License Plates/car_51.txt (deflated 27%)
  adding: content/License Plates/car_153.txt (deflated 30%)
  adding: content/License Plates/car_56.jpeg (deflated 1%)
  adding: content/License Plates/car_108.txt (deflated 33%)
  adding: content/License Plates/car_147.txt (deflated 14%)
  adding: content/License Plates/car_189.jpeg (deflated 10%)
  adding: content/License Plates/car_104.txt (deflated 37%)
  adding: content/License Plates/car_154.txt (deflated 29%)
  adding: content/License Plates/car_55.txt (deflated 27%)
  adding: content/License Plates/car_223.txt (deflated 38%)
  adding: content/License Plates/car_19.jpeg (deflated 3%)
  adding: content/License Plates/car_231.txt (deflated 30%)
  adding: content/License Plates/car_1.jpeg (deflated 1%)
  adding: content/License Plates/car_172.jpeg (deflated 2%)
  adding: content/License Plates/car_233.txt (deflated 42%)
  adding: content/License Plates/car_135.txt (deflated 35%)
  adding: content/License Plates/car_47.txt (deflated 30%)
  adding: content/License Plates/car_62.txt (deflated 14%)
  adding: content/License Plates/car_203.jpeg (deflated 0%)
  adding: content/License Plates/car_70.txt (deflated 32%)
  adding: content/License Plates/car_162.txt (deflated 49%)
  adding: content/License Plates/car_147.jpeg (deflated 1%)
  adding: content/License Plates/car_46.jpeg (deflated 1%)
  adding: content/License Plates/car_205.jpeg (deflated 1%)
  adding: content/License Plates/car_29.jpeg (deflated 8%)
  adding: content/License Plates/car_165.jpeg (deflated 1%)
  adding: content/License Plates/car_53.jpeg (deflated 1%)
  adding: content/License Plates/car_215.jpeg (deflated 1%)
  adding: content/License Plates/car_40.txt (deflated 30%)
  adding: content/License Plates/car_138.txt (deflated 37%)
  adding: content/License Plates/car_24.jpeg (deflated 1%)
  adding: content/License Plates/car_127.jpeg (deflated 1%)
  adding: content/License Plates/car_178.jpeg (deflated 0%)
  adding: content/License Plates/car_151.jpeg (deflated 2%)
  adding: content/License Plates/car_58.jpeg (deflated 0%)
  adding: content/License Plates/car_109.jpeg (deflated 2%)
  adding: content/License Plates/car_208.jpeg (deflated 1%)
  adding: content/License Plates/car_8.jpeg (deflated 0%)
  adding: content/License Plates/car_42.jpeg (deflated 1%)
  adding: content/License Plates/car_52.txt (deflated 29%)
  adding: content/License Plates/car_215.txt (deflated 29%)
  adding: content/License Plates/car_214.txt (deflated 27%)
  adding: content/License Plates/car_165.txt (deflated 44%)
  adding: content/License Plates/car_85.txt (deflated 16%)
  adding: content/License Plates/car_81.txt (deflated 44%)
  adding: content/License Plates/car_5.jpeg (deflated 1%)
  adding: content/License Plates/car_194.txt (deflated 53%)
  adding: content/License Plates/car_169.jpeg (deflated 1%)
  adding: content/License Plates/car_113.txt (deflated 25%)
  adding: content/License Plates/car_44.txt (deflated 45%)
  adding: content/License Plates/car_188.txt (deflated 29%)
  adding: content/License Plates/car_164.txt (deflated 32%)
  adding: content/License Plates/car_75.jpeg (deflated 1%)
  adding: content/License Plates/car_206.jpeg (deflated 0%)
  adding: content/License Plates/car_141.jpeg (deflated 1%)
  adding: content/License Plates/car_32.txt (deflated 28%)
  adding: content/License Plates/car_49.txt (deflated 24%)
  adding: content/License Plates/car_125.jpeg (deflated 1%)
  adding: content/License Plates/car_71.jpeg (deflated 1%)
  adding: content/License Plates/car_65.txt (deflated 13%)
  adding: content/License Plates/car_56.txt (deflated 22%)
  adding: content/License Plates/car_106.txt (deflated 49%)
  adding: content/License Plates/car_236.jpeg (deflated 2%)
  adding: content/License Plates/car_52.jpeg (deflated 0%)
  adding: content/License Plates/car_170.jpeg (deflated 0%)
  adding: content/License Plates/car_236.txt (deflated 29%)
  adding: content/License Plates/car_36.jpeg (deflated 1%)
  adding: content/License Plates/car_185.jpeg (deflated 0%)
  adding: content/License Plates/car_119.txt (deflated 50%)
  adding: content/License Plates/car_35.txt (deflated 32%)
  adding: content/License Plates/car_27.txt (deflated 12%)
  adding: content/License Plates/car_132.txt (deflated 35%)
  adding: content/License Plates/car_226.txt (deflated 28%)
  adding: content/License Plates/car_161.txt (deflated 34%)
  adding: content/License Plates/car_23.txt (deflated 26%)
  adding: content/License Plates/car_78.txt (deflated 33%)
  adding: content/License Plates/car_149.txt (deflated 34%)
  adding: content/License Plates/car_163.txt (deflated 35%)
  adding: content/License Plates/car_221.txt (deflated 46%)
  adding: content/License Plates/car_79.txt (deflated 20%)
  adding: content/License Plates/car_179.txt (deflated 30%)
  adding: content/License Plates/car_96.txt (deflated 47%)
  adding: content/License Plates/car_12.jpeg (deflated 1%)
  adding: content/License Plates/car_195.jpeg (deflated 2%)
  adding: content/License Plates/car_68.jpeg (deflated 1%)
  adding: content/License Plates/car_30.jpeg (deflated 1%)
  adding: content/License Plates/car_88.jpeg (deflated 1%)
  adding: content/License Plates/car_189.txt (deflated 28%)
  adding: content/License Plates/car_198.jpeg (deflated 0%)
  adding: content/License Plates/car_155.jpeg (deflated 1%)
  adding: content/License Plates/car_67.txt (deflated 26%)
  adding: content/License Plates/car_107.jpeg (deflated 24%)
  adding: content/License Plates/car_184.jpeg (deflated 1%)
  adding: content/License Plates/car_28.txt (deflated 29%)
  adding: content/License Plates/car_136.txt (deflated 25%)
  adding: content/License Plates/car_153.jpeg (deflated 1%)
  adding: content/License Plates/car_98.jpeg (deflated 4%)
  adding: content/License Plates/car_63.txt (deflated 50%)
  adding: content/License Plates/car_88.txt (deflated 30%)
  adding: content/License Plates/car_222.jpeg (deflated 1%)
  adding: content/License Plates/car_218.jpeg (deflated 1%)
  adding: content/License Plates/car_171.txt (deflated 29%)
  adding: content/License Plates/car_200.jpeg (deflated 0%)
  adding: content/License Plates/car_85.jpeg (deflated 1%)
  adding: content/License Plates/car_133.jpeg (deflated 0%)
  adding: content/License Plates/car_93.txt (deflated 32%)
  adding: content/License Plates/car_67.jpeg (deflated 3%)
  adding: content/License Plates/car_17.jpeg (deflated 1%)
  adding: content/License Plates/car_225.jpeg (deflated 2%)
  adding: content/License Plates/car_115.jpeg (deflated 0%)
  adding: content/License Plates/car_54.jpeg (deflated 1%)
  adding: content/License Plates/car_184.txt (deflated 39%)
  adding: content/License Plates/car_92.txt (deflated 31%)
  adding: content/License Plates/car_226.jpeg (deflated 1%)
  adding: content/License Plates/car_150.jpeg (deflated 1%)
  adding: content/License Plates/car_139.txt (deflated 31%)
  adding: content/License Plates/car_4.jpeg (deflated 1%)
  adding: content/License Plates/car_121.jpeg (deflated 1%)
  adding: content/License Plates/car_108.jpeg (deflated 5%)
  adding: content/License Plates/car_110.jpeg (deflated 0%)
  adding: content/License Plates/car_79.jpeg (deflated 1%)
  adding: content/License Plates/car_53.txt (deflated 35%)
  adding: content/License Plates/car_124.txt (deflated 47%)
  adding: content/License Plates/car_78.jpeg (deflated 1%)
  adding: content/License Plates/car_201.txt (deflated 31%)
  adding: content/License Plates/car_176.jpeg (deflated 2%)
  adding: content/License Plates/car_101.jpeg (deflated 3%)
  adding: content/License Plates/car_208.txt (deflated 15%)
  adding: content/License Plates/car_64.jpeg (deflated 1%)
  adding: content/License Plates/car_196.jpeg (deflated 0%)
  adding: content/License Plates/car_202.jpeg (deflated 2%)
  adding: content/License Plates/car_133.txt (deflated 26%)
  adding: content/License Plates/car_151.txt (deflated 38%)
  adding: content/License Plates/car_194.jpeg (deflated 1%)
  adding: content/License Plates/car_212.jpeg (deflated 1%)
  adding: content/License Plates/car_203.txt (deflated 40%)
  adding: content/License Plates/car_130.txt (deflated 16%)
  adding: content/License Plates/car_120.jpeg (deflated 1%)
  adding: content/License Plates/car_166.jpeg (deflated 2%)
  adding: content/License Plates/car_99.jpeg (deflated 0%)
  adding: content/License Plates/car_72.txt (deflated 37%)
  adding: content/License Plates/car_229.jpeg (deflated 1%)
  adding: content/License Plates/car_142.txt (deflated 32%)
  adding: content/License Plates/car_136.jpeg (deflated 1%)
  adding: content/License Plates/car_197.jpeg (deflated 1%)
  adding: content/License Plates/car_3.txt (deflated 16%)

os.getcwd()

'/root/darknet'
cd ~

/root

cd /content

/content

import random

x = list(licenses['name'])

random.shuffle(x)
f = open('./train.txt','w+')
y = open('./val.txt','w+')

for i in range(len(x)):
  if i % 10 ==0:
    y.write('/darknet/data/obj/'+x[i]+'\n')
  else:
    f.write('/darknet/data/obj/'+x[i]+'\n')
y.close()
f.close()

files.download('./train.txt')
files.download('./val.txt')

 

The following repository is an end to end detection and recognition of Indian license plates using YOLO v3 Darknet and Pytesseract. It serves as a precursor for our project. This is a fun individual project on its own!
Creating folder structure
In the data/images folder ,create two folder namely, train and valid
The train folder consists of 201 images obtained from Step 2. These are to be used for training
The valid folder consists of 36 images obtained from Step 2, which are to be used for validation
Only images won’t do for detection as we need labels for bounding boxes and classes for each image.
The YOLO format for a single class bounding box label is as follows:
class_number x y width height
The labels are already obtained from Step 2.
The labels folder consists of a train and valid folder consisting of labels for training and validation images respectively.
A sample label
Next, we create the data/train.txt file
To get the contents of this file, simply write the following in command prompt or terminal. Make sure you are in the anpr_yolov5 directory
D:>git clone https://github.com/sid0312/anpr_yolov5cd anpr_yolov5python>>import os>>for image in os.list('data/images/train'):     path = 'D:/anpr_yolov5/data/images/train'     print(path+'/'+image)
You will get the following output
Copy the output to a file data/train.txt
Do the same for valid.txt
If you intend to train Yolo v5 on Google Colab, commit the repository in its present state without copying the contents above. Commit and push the current state of your repository to GitHub.
git add . git commit -m"some msg"git push
Now follow the following notebook and copy the contents of the print logs to the files data/train.txt and data/val.txt respectively
Change the nc parameter in yolov5s.yaml to 1
Repeat the git add,commit,push process again
Check out the following notebook for the training process
github.com
Note: You can use yolo5s.pt weights too. I have used randomly initialized weights and trained the model for 100 epochs.
After running for 100 epochs, we get
Precision as 0.659
Recall as 0.972
map@0.5 as 0.978
map@0.5 with 95% confidence as 0.471
https://blog.roboflow.ai
https://github.com/ultralyitcs/yolov5
In case, you have skipped the training part and jumped right to the conclusion, I have something more for you. After finding the region of interest of the license plate, we can use it for character recognition using pytesseract
I have done it for a previous project. You can check it out at:
github.com
If you’re into reading more about Object Detection Algorithms and Libraries, I highly recommend this blog by neptune.ai
neptune.ai
If you’re into my articles, check these out!
towardsdatascience.com
towardsdatascience.com
towardsdatascience.com
If you wish to connect with me on Linkedin, here’s my profile
www.linkedin.com
Happy Computer Vision and Happy Deep Learning ❤.