<?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: SachaDee</title>
    <description>The latest articles on DEV Community by SachaDee (@sachadee).</description>
    <link>https://dev.to/sachadee</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%2F217812%2F6fcbae07-87b7-47e5-a950-0f7e124770b8.jpg</url>
      <title>DEV Community: SachaDee</title>
      <link>https://dev.to/sachadee</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sachadee"/>
    <language>en</language>
    <item>
      <title>Encrypt/Decrypt Data between Python 3 and JavaScript (AES algorithm)</title>
      <dc:creator>SachaDee</dc:creator>
      <pubDate>Sun, 21 Apr 2024 06:18:20 +0000</pubDate>
      <link>https://dev.to/sachadee/encryptdecrypt-data-between-python-3-and-javascript-aes-algorithm-1di0</link>
      <guid>https://dev.to/sachadee/encryptdecrypt-data-between-python-3-and-javascript-aes-algorithm-1di0</guid>
      <description>&lt;p&gt;This storie was referenced in a work of the University of Barcelona : “Wordle Crypto: Una aplicacicio Web3” by Jordi Bonet Valiente. You can check the paper:&lt;/p&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;a href="https://diposit.ub.edu/dspace/bitstream/2445/191104/3/tfg_bonet_valiente_jordi.pdf" rel="noopener noreferrer"&gt;
      diposit.ub.edu
    &lt;/a&gt;
&lt;/div&gt;


&lt;h2&gt;
  
  
  Python part of encrypting/decrypting
&lt;/h2&gt;

&lt;p&gt;First of all choosing a Python encryption library&lt;br&gt;
There is various encryption library for python. You can check it &lt;a href="https://pypi.org/search/?q=encryption&amp;amp;page=1"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I choose &lt;strong&gt;PyCryptodome&lt;/strong&gt; which is well documented and supports Python 2.7, Python 3.5 and newer, and &lt;strong&gt;PyPy&lt;/strong&gt;. Just for information &lt;strong&gt;PyCrypto&lt;/strong&gt; is no more maintened, so would not recommend using it.&lt;/p&gt;

&lt;p&gt;Installing &lt;strong&gt;PyCryptodome&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install pycryptodome

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After that we can test an encryption to check if everything is OK!&lt;/p&gt;

&lt;p&gt;Importing the necessary libraries in our &lt;em&gt;test.py&lt;/em&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import base64 
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad,unpad
from Crypto.Random import get_random_bytes #only for AES CBC mode
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In our case we gonna work with this 2 modes: AES ECB and CBC mode. The first one ECB mode is interessant for som case use where you cannot send the intialization Vector(IV) to the JavaScript code (even if its possible to put it in the header of a post HTTP request) I do not recommend using AES ECB for production. Over the net use CBC. But that not the purpose of this post if you want to learn more about cryptografy there a lot of good text on the web.&lt;/p&gt;

&lt;p&gt;we gonna make an AES128 encryption. 128-bit keys are sufficient to ensure a good security, but is up to you to choose an AES192 or AES256.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;AES ECB MODE&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
Encryption and decryption AES128 ECB mode in Python&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import base64 
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad,unpad

#AES ECB mode without IV

data = 'I love Medium'
key = 'AAAAAAAAAAAAAAAA' #Must Be 16 char for AES128

def encrypt(raw):
        raw = pad(raw.encode(),16)
        cipher = AES.new(key.encode('utf-8'), AES.MODE_ECB)
        return base64.b64encode(cipher.encrypt(raw))

def decrypt(enc):
        enc = base64.b64decode(enc)
        cipher = AES.new(key.encode('utf-8'), AES.MODE_ECB)
        return unpad(cipher.decrypt(enc),16)

encrypted = encrypt(data)
print('encrypted ECB Base64:',encrypted.decode("utf-8", "ignore"))

decrypted = decrypt(encrypted)
print('data: ',decrypted.decode("utf-8", "ignore"))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python test.py
&amp;gt;&amp;gt;encrypted ECB Base64: gfp6wzvTH3lN5TO2B37yWQ==
&amp;gt;&amp;gt;data:  I love Medium
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We have now a base 64 string that can be passed to JavaScript&lt;/p&gt;

&lt;p&gt;For the AES CBC mode we just have one diference the IV ( Initialization Vector) which should be 128 bits pr 16 char too. We can use a fix IV or random IV. That’s up to you the random is more secure both should be passed to the Javascript for decryption.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;AES CBC MODE&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
Encryption and decryption AES128 CBC mode in Python with Fix IV&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import base64 
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad,unpad

#CBC with Fix IV

data = 'I love Medium'
key = 'AAAAAAAAAAAAAAAA' #16 char for AES128

#FIX IV
iv =  'BBBBBBBBBBBBBBBB'.encode('utf-8') #16 char for AES128

def encrypt(data,key,iv):
        data= pad(data.encode(),16)
        cipher = AES.new(key.encode('utf-8'),AES.MODE_CBC,iv)
        return base64.b64encode(cipher.encrypt(data))

def decrypt(enc,key,iv):
        enc = base64.b64decode(enc)
        cipher = AES.new(key.encode('utf-8'), AES.MODE_CBC, iv)
        return unpad(cipher.decrypt(enc),16)

encrypted = encrypt(data,key,iv)
print('encrypted CBC base64 : ',encrypted.decode("utf-8", "ignore"))

decrypted = decrypt(encrypted,key,iv)
print('data: ', decrypted.decode("utf-8", "ignore"))

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python test.py
&amp;gt;&amp;gt;encrypted CBC base64 :  VEX7Eequ5TM9+jlgrwnkNw==
&amp;gt;&amp;gt;data:  I love Medium
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Encryption and decryption AES128 CBC mode in Python with random IV&lt;/p&gt;

&lt;p&gt;for this one we gonna import &lt;em&gt;get_random_bytes&lt;/em&gt; from Crypto to generate the 128 bits IV.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import base64
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad,unpad
from Crypto.Random import get_random_bytes

#CBC mode with random IV

data = 'I love Medium'
key = 'AAAAAAAAAAAAAAAA' #16 char for AES128

#Random IV more secure
iv =  get_random_bytes(16) #16 char for AES128

def encrypt(data,key,iv):
        data = pad(data.encode(),16)
        cipher = AES.new(key.encode('utf-8'),AES.MODE_CBC,iv)
        print('random IV : ' , base64.b64encode(cipher.iv).decode('utf-8'))
        return base64.b64encode(cipher.encrypt(data)),base64.b64encode(cipher.iv).decode('utf-8')

def decrypt(enc,key,iv):
        enc = base64.b64decode(enc)
        cipher = AES.new(key.encode('utf-8'), AES.MODE_CBC, base64.b64decode(iv))
        return unpad(cipher.decrypt(enc),16)

encrypted, iv = encrypt(data,key,iv)
print('encrypted CBC base64 : ',encrypted.decode("utf-8", "ignore"))

decrypted = decrypt(encrypted,key,iv)
print('data: ', decrypted.decode("utf-8", "ignore"))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python test.py
&amp;gt;&amp;gt;random IV :  HlR8EJsTuXi9hFx8GINO5A==
&amp;gt;&amp;gt;encrypted CBC base64 :  CyL3j8VSHrGPBcujlo4b4Q==
&amp;gt;&amp;gt;data:  I love Medium
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OK everything fine with Python!!!&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;. . .&lt;br&gt;
*&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  JavaScript part of encrypting/decrypting
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;JavaScript encryption library&lt;br&gt;
lets decode it in javascript!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I used crypto-js true CDN in our .html file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js"&amp;gt;&amp;lt;/script&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From python we got various &lt;strong&gt;_base64 string _&lt;/strong&gt;for all of our 3 cases:&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;For the ECB encryption we get :&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gfp6wzvTH3lN5TO2B37yWQ==

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script&amp;gt;
 var encrypted ='gfp6wzvTH3lN5TO2B37yWQ=='; //python is base64 ECB
 var key ='AAAAAAAAAAAAAAAA'//key used in Python
 key = CryptoJS.enc.Utf8.parse(key); 
 var decrypted =  CryptoJS.AES.decrypt(encrypted, key, {mode:CryptoJS.mode.ECB});
 console.log(decrypted.toString(CryptoJS.enc.Utf8));
&amp;lt;/script&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output in the developper console:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;test.html
&amp;gt;&amp;gt;I love Medium
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For the CBC encryption we get :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;random IV :  l5I5Toqn5RoX0JfTLQB9Pw==
encrypted CBC base64 :  uJrS9Zp1R5WjOEUkSK9clQ==
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//PYTHON FIX IV ENCRYPTION AND PYTHON FIX IV
var Base64CBC ='VEX7Eequ5TM9+jlgrwnkNw==';
var iv = CryptoJS.enc.Utf8.parse('BBBBBBBBBBBBBBBB');
//PYTHON RANDOM IV ENCRYPTION AND PYTHON RANDOM IV
//var Base64CBC ='uJrS9Zp1R5WjOEUkSK9clQ==';
//var iv = CryptoJS.enc.Base64.parse('l5I5Toqn5RoX0JfTLQB9Pw==');
var key ='AAAAAAAAAAAAAAAA'//key used in Python
 key = CryptoJS.enc.Utf8.parse(key);
    var decrypted =  CryptoJS.AES.decrypt(Base64CBC, key, { iv: iv, mode: CryptoJS.mode.CBC});
    decrypted = decrypted.toString(CryptoJS.enc.Utf8);
    console.log(decrypted);
 alert(decrypted);
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output in the developper console:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;test.html
&amp;gt;&amp;gt;I love Medium
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Just comment the PYTHON FIX IV ENCRYPTION AND PYTHON FIX IV and uncomment the //PYTHON RANDOM IV ENCRYPTION AND PYTHON RANDOM IV to test the random solution :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//PYTHON FIX IV ENCRYPTION AND PYTHON FIX IV
//var Base64CBC ='VEX7Eequ5TM9+jlgrwnkNw==';
//var iv = CryptoJS.enc.Utf8.parse('BBBBBBBBBBBBBBBB');
//PYTHON RANDOM IV ENCRYPTION AND PYTHON RANDOM IV
var Base64CBC ='uJrS9Zp1R5WjOEUkSK9clQ==';
var iv = CryptoJS.enc.Base64.parse('l5I5Toqn5RoX0JfTLQB9Pw==');

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;*&lt;em&gt;To encrypt in Javascript:&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script&amp;gt;
//JS FIX IV ENCRYPTION CBC
var message = 'I love Medium';
var key ='AAAAAAAAAAAAAAAA'//key used in Python
key = CryptoJS.enc.Utf8.parse(key);
var iv = CryptoJS.enc.Utf8.parse('BBBBBBBBBBBBBBBB')
var encrypted = CryptoJS.AES.encrypt(message, key, { iv: iv, mode: CryptoJS.mode.CBC});
encrypted =encrypted.toString();
console.log('encrypted',encrypted );
alert(encrypted)

//JS RANDOM IV ENCRYPTION CBC
var iv = CryptoJS.enc.Hex.parse("101112131415161718191a1b1c1d1e1f");
var encrypted = CryptoJS.AES.encrypt(message, key, { iv: iv, mode: CryptoJS.mode.CBC});
encrypted =encrypted.toString();
console.log('encrypted',encrypted );
alert(encrypted)

//JS ENCRYPTION ECB
var encrypted = CryptoJS.AES.encrypt(message, key, {mode: CryptoJS.mode.ECB});
encrypted =encrypted.toString();
console.log('encrypted',encrypted );
alert(encrypted)
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;output :&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;VEX7Eequ5TM9+jlgrwnkNw== same output as our python CBC with fix iv
Txi+ue8bqPCHrcVORbiSrg== not the same. We generate random iV in JS
gfp6wzvTH3lN5TO2B37yWQ== same output as our python ECB
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;*&lt;em&gt;Thats it!!!&lt;br&gt;
*&lt;/em&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>python</category>
      <category>aes</category>
      <category>encrypt</category>
    </item>
    <item>
      <title>YOLO8 The basic functions for beginner!</title>
      <dc:creator>SachaDee</dc:creator>
      <pubDate>Sat, 20 Apr 2024 02:58:32 +0000</pubDate>
      <link>https://dev.to/sachadee/yolo8-the-basic-functions-for-beginner-1k9</link>
      <guid>https://dev.to/sachadee/yolo8-the-basic-functions-for-beginner-1k9</guid>
      <description>&lt;p&gt;&lt;strong&gt;When you start using YOLO8 you loose a lot of time to find the basics codes to get the bounding boxes, the confidence , the classes or to run a yolo model with onnx runtime!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We will work with the pre-trained COCO object detection. This models have 80 classes:&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;class&lt;/strong&gt; is just a type of object which will be detected, like a “cat” or a “person”.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Classes names:

0: person 1: bicycle 2: car 3: motorcycle 4: airplane 5: bus 
6: train 7: truck 8: boat 9: traffic light 10: fire hydrant 
11: stop sign 12: parking meter 13: bench 14: bird 15: cat 16: dog 17: horse 18: sheep 19: cow 20: elephant 21: bear 22: zebra 
23: giraffe 24: backpack 25: umbrella 26: handbag 27: tie 
28: suitcase 29: frisbee 30: skis 31: snowboard 32: sports ball 33: kite 34: baseball bat 35: baseball glove 36: skateboard 
37: surfboard 38: tennis racket 39: bottle 40: wine glass 41: cup 42: fork 43: knife 44: spoon 45: bowl 46: banana 47: apple 
48: sandwich 49: orange 50: broccoli 51: carrot 52: hot dog 
53: pizza 54: donut 55: cake 56: chair 57: couch 58: potted plant 59: bed 60: dining table 61: toilet 62: tv 63: laptop 64: mouse 65: remote 66: keyboard 67: cell phone 68: microwave 69: oven 
70: toaster 71: sink 72: refrigerator 73: book 74: clock 75: vase 
76: scissors 77: teddy bear 78: hair drier 79: toothbrush
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;*&lt;em&gt;We have then various Models to detect this classes :&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; Name        Size

 yolov8n.pt  Nano
 yolov8s.pt  small
 yolov8m.pt  Medium
 yolov8l.pt  Large
 yolov8x.pt  Huge
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;They all do the same but resumed: bigger is the model better is the prediction.&lt;/p&gt;

&lt;p&gt;All these model are trained with an image size of 640.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You don’t have to resize the image to make a prediction this will be done automatically!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this story we gonna use the smallest one yolov8n.pt.&lt;/p&gt;

&lt;p&gt;Let’s Start with Python I recommend ≥ 3.9, the console command will be detailled at the end for the BAT lovers!&lt;/p&gt;

&lt;p&gt;first install Ultralytics:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python -m pip install ultralytics

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Create a folder Yolo8 and a file &lt;strong&gt;&lt;em&gt;myYoloTests.py&lt;/em&gt;&lt;/strong&gt; or whathever you want in it, and copy this code in it!&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from ultralytics import YOLO

#Loading the nano model

model = YOLO('yolov8n.pt')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The model will be &lt;strong&gt;downloaded automatically&lt;/strong&gt; in the first run!&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; python myYoloTests.py

Downloading https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n.pt to 'yolov8n.pt'...

  0%|          | 0.00/6.23M [00:00&amp;lt;?, ?B/s]
  6%|6         | 384k/6.23M [00:00&amp;lt;00:01, 3.60MB/s]
 18%|#7        | 1.09M/6.23M [00:00&amp;lt;00:00, 5.53MB/s]
 26%|##6       | 1.62M/6.23M [00:00&amp;lt;00:00, 5.33MB/s]
 35%|###5      | 2.19M/6.23M [00:00&amp;lt;00:00, 5.36MB/s]
 46%|####5     | 2.86M/6.23M [00:00&amp;lt;00:00, 5.75MB/s]
 55%|#####4    | 3.41M/6.23M [00:00&amp;lt;00:00, 5.34MB/s]
 64%|######4   | 4.00M/6.23M [00:00&amp;lt;00:00, 5.43MB/s]
 73%|#######2  | 4.55M/6.23M [00:00&amp;lt;00:00, 5.37MB/s]
 81%|########1 | 5.06M/6.23M [00:01&amp;lt;00:00, 4.82MB/s]
 89%|########9 | 5.56M/6.23M [00:01&amp;lt;00:00, 4.81MB/s]
 97%|#########6| 6.03M/6.23M [00:01&amp;lt;00:00, 3.90MB/s]
100%|##########| 6.23M/6.23M [00:01&amp;lt;00:00, 4.75MB/s]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;You know have the pre-trained model &lt;strong&gt;&lt;em&gt;yolov8n.pt&lt;/em&gt;&lt;/strong&gt; in your folder!&lt;/p&gt;

&lt;p&gt;Now let’s start with the basic function to detect an object on this image:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffsd4sqjklpzzp9wh0wpv.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffsd4sqjklpzzp9wh0wpv.jpg" alt="Dog.jpg" width="640" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can download it as &lt;strong&gt;&lt;em&gt;dog.jpg&lt;/em&gt;&lt;/strong&gt; and modify your &lt;strong&gt;&lt;em&gt;myYoloTests.py&lt;/em&gt;&lt;/strong&gt; like this:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from ultralytics import YOLO

#Loading the nano model
model = YOLO('yolov8n.pt',task='detect')

#Defining the image to test
image = 'dog.jpg'

#Running an inference on the image
model(image)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;*&lt;em&gt;Run it:&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; python myYoloTests.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;You will get as result :&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;image 1/1 C:\Users\Quasar\Desktop\yolo8medium\dog.jpg: 480x640 1 dog, 546.9ms
Speed: 15.6ms preprocess, 546.9ms inference, 31.2ms postprocess per image at shape (1, 3, 480, 640)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;You get as result that a dog was detected and the inference time!&lt;/p&gt;

&lt;p&gt;Yhat’s a good start! &lt;strong&gt;But I want an image with bounding boxes on it displayed at the run!!!!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Modify your &lt;strong&gt;&lt;em&gt;myYoloTests.py&lt;/em&gt;&lt;/strong&gt; this way:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from ultralytics import YOLO
import cv2

#Loading the nano model

model = YOLO('yolov8n.pt',task='detect')

image = 'dog.jpg'

model(image,show=True)

cv2.waitKey(0)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;And the image with the dog detected insight bounding box will be displayed!!&lt;/p&gt;

&lt;p&gt;If you want that YOLO save that all automatically for you just add:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from ultralytics import YOLO
import cv2

#Loading the nano model

model = YOLO('yolov8n.pt',task='detect')

image = 'dog.jpg'

model(image,show=True,save=True,save_crop=True)

cv2.waitKey(0)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;image 1/1 C:\Users\Quasar\Desktop\yolo8medium\dog.jpg: 480x640 1 dog, 484.4ms
Speed: 15.6ms preprocess, 484.4ms inference, 31.2ms postprocess per image at shape (1, 3, 480, 640)
Results saved to runs\detect\predict
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;YOLO have created the folders &lt;strong&gt;runs\detect\predict&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;predict&lt;/strong&gt; folder you will have a folder &lt;strong&gt;crops\dog&lt;/strong&gt; (the detected class). In this &lt;strong&gt;dog&lt;/strong&gt; folder you have the image &lt;strong&gt;&lt;em&gt;dog.jpg&lt;/em&gt;&lt;/strong&gt; cropped:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3kvnz93gz32r7znx45qt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3kvnz93gz32r7znx45qt.png" alt="Dog.jpg" width="551" height="383"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;on the folder &lt;strong&gt;\predict** you have the original image **&lt;em&gt;dog.jpg&lt;/em&gt;&lt;/strong&gt; with the bounding box:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6np4rs6e4fkznqb34vy7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6np4rs6e4fkznqb34vy7.png" alt="dog.jpg" width="640" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And in &lt;strong&gt;predict\labels&lt;/strong&gt; you have the file &lt;strong&gt;&lt;em&gt;dog.txt&lt;/em&gt;&lt;/strong&gt; containing:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;16 0.493492 0.420779 0.828031 0.76239
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;16 is the class number for a dog (you can check it at the begining of the story) and the for last float number are the bounding box coordinate in &lt;strong&gt;YOLO format in relation of the input image!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;How to transform this &lt;strong&gt;YOLO format&lt;/strong&gt; in an understandable format? This is here just as information for someone who maybe will use it, but you will see later that yolo give other informations and you normally will never use this function!&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import math
import cv2

def yolo2xywh(im):
 img = cv2.imread(im)
 shape = img.shape
 y,x = shape[:2]
 yoloFile = open('.\\runs\\detect\\predict\\labels\\dog.txt','r')
 yoloArray = yoloFile.read().split()
 yoloFile.close()
 yoloArray = [float(z) for z in yoloArray]
 x1 = math.ceil((yoloArray[1]-yoloArray[3]/2)*x)
 w = math.ceil((yoloArray[1]+yoloArray[3]/2)*x)
 y1 = math.ceil((yoloArray[2]-yoloArray[4]/2)*y)
 h = math.ceil((yoloArray[2]+yoloArray[4]/2)*y)
 return x1,y1,w,h

x,y,w,h = yolo2xywh('dog.jpg')
print("x:",x,"y:",y,"width:",w,"height:",h)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Which return:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x: 51 y: 20 width: 581 height: 385
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;.  .  .&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;OK now we want to get the full control to crop image get the class and the confidence and optimize the speed process!!!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Yolo will give you all the information of a prediction in a variable:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from ultralytics import YOLO
import cv2

#Loading the nano model

model = YOLO('yolov8n.pt',task='detect')

image = 'dog.jpg'

results = model(image)

print(results[0])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;You will get a complete structure of your inference :&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ultralytics.engine.results.Results object with attributes:

boxes: ultralytics.engine.results.Boxes object
keypoints: None
keys: ['boxes']
masks: None
names: {0: 'person', 1: 'bicycle', 2: 'car', 3: 'motorcycle', 4: 'airplane', 5: 'bus', 6: 'train', 7: 'truck', 8: 'boat', 9: 'traffic light', 10: 'fire hydrant', 11: 'stop sign', 12: 'parking meter', 13: 'bench', 14: 'bird', 15: 'cat', 16: 'dog', 17: 'horse', 18: 'sheep', 19: 'cow', 20: 'elephant', 21: 'bear', 22: 'zebra', 23: 'giraffe', 24: 'backpack', 25: 'umbrella', 26: 'handbag', 27: 'tie', 28: 'suitcase', 29: 'frisbee', 30: 'skis', 31: 'snowboard', 32: 'sports ball', 33: 'kite', 34: 'baseball bat', 35: 'baseball glove', 36: 'skateboard', 37: 'surfboard', 38: 'tennis racket', 39: 'bottle', 40: 'wine glass', 41: 'cup', 42: 'fork', 43: 'knife', 44: 'spoon', 45: 'bowl', 46: 'banana', 47: 'apple', 48: 'sandwich', 49: 'orange', 50: 'broccoli', 51: 'carrot', 52: 'hot dog', 53: 'pizza', 54: 'donut', 55: 'cake', 56: 'chair', 57: 'couch', 58: 'potted plant', 59: 'bed', 60: 'dining table', 61: 'toilet', 62: 'tv', 63: 'laptop', 64: 'mouse', 65: 'remote', 66: 'keyboard', 67: 'cell phone', 68: 'microwave', 69: 'oven', 70: 'toaster', 71: 'sink', 72: 'refrigerator', 73: 'book', 74: 'clock', 75: 'vase', 76: 'scissors', 77: 'teddy bear', 78: 'hair drier', 79: 'toothbrush'}
orig_img: array([[[196, 179, 182],
        [196, 182, 184],
        [197, 184, 186],
        ...,
        [255, 255, 251],
        [255, 255, 251],
        [255, 255, 251]],

       [[196, 179, 182],
        [196, 182, 184],
        [197, 184, 186],
        ...,
        [255, 255, 251],
        [255, 255, 252],
        [255, 255, 251]],

       [[194, 180, 181],
        [195, 183, 183],
        [195, 185, 185],
        ...,
        [255, 255, 252],
        [255, 255, 254],
        [255, 255, 252]],

       ...,

       [[188, 191, 196],
        [188, 191, 196],
        [187, 190, 195],
        ...,
        [125, 138, 136],
        [125, 138, 136],
        [125, 138, 136]],

       [[188, 191, 196],
        [188, 191, 196],
        [187, 190, 195],
        ...,
        [124, 138, 137],
        [124, 138, 137],
        [125, 139, 138]],

       [[188, 191, 196],
        [188, 191, 196],
        [187, 190, 195],
        ...,
        [123, 139, 138],
        [125, 138, 140],
        [125, 138, 140]]], dtype=uint8)
orig_shape: (480, 640)
path: 'C:\\Users\\Quasar\\Desktop\\yolo8medium\\dog.jpg'
probs: None
save_dir: None
speed: {'preprocess': 15.631437301635742, 'inference': 609.3780994415283, 'postprocess': 31.238794326782227}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;If you want the &lt;strong&gt;bounding box&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from ultralytics import YOLO
import cv2

model = YOLO('yolov8n.pt',task='detect')

image = 'dog.jpg'

results = model(image)[0]
box = results.boxes

print(box)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;And the return :&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ultralytics.engine.results.Boxes object with attributes:

boxes: tensor([[ 50.8651,  19.0002, 580.8049, 384.9475,   0.5911,  16.0000]])
cls: tensor([16.])
conf: tensor([0.5911])
data: tensor([[ 50.8651,  19.0002, 580.8049, 384.9475,   0.5911,  16.0000]])
id: None
is_track: False
orig_shape: (480, 640)
shape: torch.Size([1, 6])
xywh: tensor([[315.8350, 201.9738, 529.9398, 365.9473]])
xywhn: tensor([[0.4935, 0.4208, 0.8280, 0.7624]])
xyxy: tensor([[ 50.8651,  19.0002, 580.8049, 384.9475]])
xyxyn: tensor([[0.0795, 0.0396, 0.9075, 0.8020]])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;You see that you have all the type of bounding box as tensor!!&lt;/p&gt;

&lt;p&gt;I like to work with &lt;em&gt;&lt;strong&gt;xyxy&lt;/strong&gt;&lt;/em&gt; dimension, so with the results List we can get everything from original image to boundings boxs and classes and confidences!!&lt;/p&gt;

&lt;p&gt;So I make a function that return the coords,the class, the confidence and the image already cropped, I make only 1 detection in this example that why I putted &lt;em&gt;max_det=1&lt;/em&gt; in the model function!&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from ultralytics import YOLO
import numpy as np
import cv2

model = YOLO('yolov8n.pt',task='detect')

image = 'dog.jpg'
Threshold=0.3

results = model(image,conf=Threshold,max_det=1)


def affRes(results):
   result = results[0]
   res = result.boxes[0] 
   cords = res.xyxy[0].tolist()
   cords = [round(x) for x in cords]
   class_id = result.names[res.cls[0].item()]
   conf = round(res.conf[0].item(), 2)
   img_cropped = cv2.resize(np.array(result.orig_img[cords[1]:cords[3],cords[0]:cords[2]]), (128, 128), interpolation=cv2.INTER_AREA)
   return cords,conf,class_id,img_cropped

box = results[0].boxes
if len(box)==0:
 print("Not detected!!")
 exit()
else:
 coords,conf,cl,img_cropped =  affRes(results)
print(coords,conf,cl)
cv2.imshow('cropped',img_cropped)
cv2.waitKey(0)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;OK that the basic of what we do with a detection model with YOLO:&lt;/p&gt;

&lt;p&gt;What is important to know is that YOLO8 accept various sources:&lt;/p&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
      &lt;div class="c-embed__cover"&gt;
        &lt;a href="https://docs.ultralytics.com/modes/predict/?source=post_page-----b60188e5803e--------------------------------#inference-sources" class="c-link s:max-w-50 align-middle" rel="noopener noreferrer"&gt;
          &lt;img alt="" src="https://res.cloudinary.com/practicaldev/image/fetch/s--h92jNnly--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/ultralytics/assets/raw/main/yolov8/banner-integrations.png" height="305" class="m-0" width="800"&gt;
        &lt;/a&gt;
      &lt;/div&gt;
    &lt;div class="c-embed__body"&gt;
      &lt;h2 class="fs-xl lh-tight"&gt;
        &lt;a href="https://docs.ultralytics.com/modes/predict/?source=post_page-----b60188e5803e--------------------------------#inference-sources" rel="noopener noreferrer" class="c-link"&gt;
          Predict - Ultralytics YOLOv8 Docs
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;p class="truncate-at-3"&gt;
          Discover how to use YOLOv8 predict mode for various tasks. Learn about different inference sources like images, videos, and data formats.
        &lt;/p&gt;
      &lt;div class="color-secondary fs-s flex items-center"&gt;
          &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://res.cloudinary.com/practicaldev/image/fetch/s--9LL5UrJp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://docs.ultralytics.com/assets/favicon.ico" width="48" height="48"&gt;
        docs.ultralytics.com
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;



&lt;p&gt;*&lt;em&gt;Test it with your video camera:&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from ultralytics import YOLO

model = YOLO('yolov8n.pt',task='detect')

Threshold=0.3

#0 for video camera source

model("0",conf=Threshold,show=True,max_det=1)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiemq534eoz8486tzs4ro.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiemq534eoz8486tzs4ro.gif" alt="cam test.gif" width="942" height="914"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;** - - -**&lt;/p&gt;
&lt;h2&gt;
  
  
  Speeding the inference time!
&lt;/h2&gt;

&lt;p&gt;First thingh we can do to speed up the inference time is to export our model to ONNX&lt;/p&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;a href="https://onnx.ai/?source=post_page-----b60188e5803e--------------------------------" rel="noopener noreferrer"&gt;
      onnx.ai
    &lt;/a&gt;
&lt;/div&gt;



&lt;p&gt;Yolo have a built in export function! We gonna export 2 ONNX models 1 for image size of 640 and one for image size of 416! These value are treated automatically with YOLO8!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from ultralytics import YOLO
import os

image = 'dog.jpg'

model = YOLO('yolov8n.pt')
model(image,imgsz=640)
model.export(format="onnx",imgsz=640,opset=12)
os.rename('yolov8n.onnx','yolov8n640.onnx')

model = YOLO('yolov8n.pt')
model(image,imgsz=416)
model.export(format="onnx",imgsz=416,opset=12)
os.rename('yolov8n.onnx','yolov8n416.onnx')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You now have 2 new model yolov8n640.onnx and yolov8n416.onnx!&lt;/p&gt;

&lt;p&gt;Yolo will automatically resize the image to the defined size before the inference! With a smaller image we will get a better inference speed, but we can loose some accuracy in the detection!&lt;/p&gt;

&lt;p&gt;We can now tet the inference time for each one, I always warm up each model so the models are loaded and ready to be used!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from ultralytics import YOLO
import time
from time import strftime, sleep

#We define the models the pt model will accept the two inference size
#but not the onnx that why we exported 2 onnx models

modelPt = YOLO('yolov8n.pt',task='detect')
modelOnnx640  = YOLO('yolov8n640.onnx',task='detect')
modelOnnx416  = YOLO('yolov8n416.onnx',task='detect')

image = 'dog.jpg'

#We warm up the models to loads them !

def warmUp():
 print("Warming Up Models!!")
 modelPt(image,verbose=False)
 modelOnnx640(image,imgsz=640,verbose=False)
 modelOnnx416(image,imgsz=416,verbose=False)

warmUp()

#####


#A function that test the inference time for 10 run and for each run!

def runTimeTest(modelname,model,imgsz):
 start = time.perf_counter()
 i=0
 arr_inf = []
 while i &amp;lt;= 10:
  si = time.perf_counter()
  model(image,imgsz=imgsz)
  se = time.perf_counter() - si
  arr_inf.append("{:.2f}".format(se))
  i += 1
 tend = time.perf_counter() - start
 print("Model:",modelname,"Time:",tend)
 print("INFERENCE ARRAY:",arr_inf)
 print("###########")

###We run the function for each model with the 2 sizes

runTimeTest('PT 640',modelPt,640)
runTimeTest('ONNX 640',modelOnnx640,640)
runTimeTest('PT 416',modelPt,416)
runTimeTest('ONNX 416',modelPt,416)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result on my I3 laptop:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Model: PT 640 Time: 3.5733098000000005
INFERENCE ARRAY: ['0.42', '0.28', '0.32', '0.32', '0.29', '0.37', '0.36', '0.31', '0.34', '0.32', '0.26']
###########
Model: ONNX 640 Time: 2.593342299999996
INFERENCE ARRAY: ['0.23', '0.25', '0.22', '0.22', '0.22', '0.24', '0.24', '0.22', '0.22', '0.25', '0.28']
###########
Model: PT 416 Time: 1.5918490999999975
INFERENCE ARRAY: ['0.23', '0.12', '0.12', '0.12', '0.17', '0.16', '0.17', '0.15', '0.12', '0.13', '0.11']
###########
Model: ONNX 416 Time: 1.5584512999999944
INFERENCE ARRAY: ['0.16', '0.13', '0.15', '0.12', '0.15', '0.15', '0.14', '0.12', '0.13', '0.15', '0.16']
###########
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We see that for the 640 image size models the &lt;em&gt;.onnx&lt;/em&gt; is better the the &lt;em&gt;.pt&lt;/em&gt;, but for the 416 image size they s no diference! But the 416 px image size reduce 50% of the time inference! That’s very good!&lt;/p&gt;

&lt;p&gt;Thanks for reading&lt;/p&gt;

</description>
      <category>yolo8</category>
      <category>python</category>
      <category>onnx</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Key/Value as simples as possible in Python</title>
      <dc:creator>SachaDee</dc:creator>
      <pubDate>Thu, 19 Dec 2019 13:56:50 +0000</pubDate>
      <link>https://dev.to/sachadee/key-value-in-python-5fk7</link>
      <guid>https://dev.to/sachadee/key-value-in-python-5fk7</guid>
      <description>&lt;p&gt;Very basic Key/Value in Python&lt;/p&gt;


&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@SachaDehe/KeyValue-in-Python?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;
?signin=true

</description>
      <category>replit</category>
      <category>python</category>
    </item>
  </channel>
</rss>
