Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
fadilm777 committed Jan 29, 2024
1 parent 4f6f3b2 commit 7cc9102
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions benchmarks/yolov8.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,40 @@ def __init__(self,
self.iou_thres = 0.45
super().__init__()

def predict(self, source):
def predict(self, image: Image.Image) -> Optional[BoundingBox]:
"""
Runs the model on the supplied images

Returns a list with dictionary items for each prediction
"""
im0 = np.array(image)

# Resize and transform im0 into one the model can read
im, ratio, (dw, dh) = letterbox(im0,
self.imgsz,
stride=self.model.stride,
auto=False,
scaleup=False) # padded resize
im = im.transpose((2, 0, 1)) # HWC to CHW
im = np.ascontiguousarray(im) # contiguous

im = torch.from_numpy(im).to(self.model.device)
im = im.half() if self.model.fp16 else im.float() # uint8 to fp16/32
im /= 255 # 0 - 255 to 0.0 - 1.0
if len(im.shape) == 3:
im = im[None] # expand for batch dim




results = self.model.predict(im,
conf=self.conf_thres,
iou=self.iou_thres,
imgsz=self.imgsz,
half=self.half,
device=self.device,
max_det=self.max_det,
)
print(results)

if __name__ == "__main__":
Expand All @@ -46,7 +77,8 @@ def predict(self, source):

detector = Yolov8Detector()
bundles = MultiBundleLoader(glob.glob("tmp/labelled-bundles/*"))
print(bundles.count)
benchmark(detector, bundles)




Expand Down

0 comments on commit 7cc9102

Please sign in to comment.