Skip to content

Instantly share code, notes, and snippets.

@huytung228
huytung228 / nms.py
Created August 15, 2021 05:12
NMS algorithm
import torch
from iou import intersection_over_union
def nms(
predictions,
iou_threshold,
threshold,
box_format='corners'
):
'''
@huytung228
huytung228 / iou.py
Created August 15, 2021 05:11
calculate IOU
import torch
def intersection_over_union(prediction_box, label_box, box_format='corners'):
'''
Funtion to calculate IOU between boxs
Parametters:
- prediction_box: a tensor with shape (N,4) - N boxs
- label_box: a tensor with shape (N,4) - N boxs
- box_format: enum between 'corner' and 'midpoint'
'''
if box_format == 'corners':
@huytung228
huytung228 / mean_avg_precision.py
Created August 15, 2021 05:09
Calculate mAP object detection
import torch
from collections import Counter
from iou import intersection_over_union
def mean_average_precision(
pred_boxes, true_boxes, iou_threshold=0.5, box_format="midpoint", num_classes=20
):
"""
Calculates mean average precision
from abc import ABC, abstractmethod
class Polygon(ABC):
@abstractmethod
def noofsides(self):
pass
class Triangle(Polygon):
class Employee:
def __init__(self, first, last):
self.first = first
self.last = last
@property
def email(self):
return '{}.{}@email.com'.format(self.first, self.last)
class Employee:
raise_amt = 1.04
def __init__(self, first, last, pay):
self.first = first
self.last = last
self.email = first + '.' + last + '@email.com'
self.pay = pay
class Employee:
raise_amount = 1.05
num_of_emps = 0
def __init__(self, first, last, pay):
self.first = first
self.last = last
self.pay = pay
self.email = first+'.'+last+'@company.com'
class Employee:
raise_amount = 1.05
num_of_emps = 0
def __init__(self, first, last, pay):
self.first = first
self.last = last
self.pay = pay
self.email = first+'.'+last+'@company.com'
class Employee:
def __init__(self, first, last, pay):
self.first = first
self.last = last
self.pay = pay
self.email = first+'.'+last+'@company.com'
def fullname(self):
return f"{self.first} {self.last}"
import asyncio
async def count():
print("One")
await asyncio.sleep(1)
print("Two")
async def main():
await asyncio.gather(count(), count(), count())