Skip to content

Commit 35531fc

Browse files
committed
Add compile to cli
1 parent c9d4ec9 commit 35531fc

5 files changed

Lines changed: 31 additions & 5 deletions

File tree

abraia/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from dotenv import load_dotenv
33
load_dotenv()
44

5-
__version__ = '0.25.13'
5+
__version__ = '0.25.14'
66

77
from . import config
88
from .client import Abraia, APIError

abraia/utils/draw.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,15 @@ def render_region(img, region, text='', color=(255, 0, 0), opacity=0.2):
207207
draw_filled_polygon(img, region, color=color, opacity=opacity)
208208
draw_text(img, text, point, background_color=color, text_scale=text_scale)
209209
return img
210+
211+
212+
def render_resolution(img):
213+
height, width = img.shape[:2]
214+
text = f"{width}x{height}"
215+
thickness = calculate_optimal_thickness(img.shape[:2])
216+
text_scale = calculate_optimal_text_scale(img.shape[:2])
217+
text_font, text_thickness = cv2.FONT_HERSHEY_DUPLEX, 1
218+
w, h = cv2.getTextSize(text, text_font, text_scale, text_thickness)[0]
219+
padding = thickness * 3
220+
point = (width - w - 2 * padding, height)
221+
return draw_text(img, text, point, background_color=(128, 128, 128), text_scale=text_scale, padding=padding)

abraia/utils/video.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import cv2
33
import time
44
import psutil
5-
from .draw import draw_text_multiline
5+
from .draw import draw_text_multiline, render_resolution
66

77

88
def is_raspberry():
@@ -24,7 +24,7 @@ def __init__(self, src=0, resolution=(1920, 1080), fps=30, dest=None):
2424
from libcamera import Transform
2525
self.picam2 = Picamera2()
2626
self.picam2.configure(self.picam2.create_video_configuration(
27-
main={"format": 'BGR888', "size": resolution},
27+
main={"format": 'RGB888', "size": resolution},
2828
transform=Transform(hflip=True, vflip=True),
2929
controls={"FrameRate": fps}))
3030
self.picam2.start()
@@ -94,12 +94,13 @@ def show(self, frame):
9494
draw_text_multiline(frame, [f"FPS: {round(1 / (t1 - self.t0), 1)}",
9595
f"CPU: {psutil.cpu_percent()}%",
9696
f"RAM: {round(psutil.virtual_memory().used / (1024**3), 2)} GB"], (10, 40), background_color=(192, 192, 192))
97+
render_resolution(frame)
9798
self.t0 = t1
9899
if not self.win_name:
99100
self.win_name = 'Video'
100101
cv2.namedWindow(self.win_name, cv2.WINDOW_GUI_NORMAL)
101102
cv2.imshow(self.win_name, cv2.cvtColor(frame, cv2.COLOR_RGB2BGR))
102-
ch = 0xFF & cv2.waitKey(1 if self.picam2 else int(self.fps))
103+
ch = 0xFF & cv2.waitKey(int(self.fps))
103104
if (ch == 27 or ch == ord('q')) or cv2.getWindowProperty(self.win_name, cv2.WND_PROP_VISIBLE) < 1:
104105
self.quit = True
105106

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ click>=8.0.3
22
numpy>=1.21.0
33
Pillow>=8.0.0
44
filetype>=1.0.7
5-
onnxruntime>=1.18.1
5+
onnxruntime==1.18.0
66
opencv-python-headless>=4.10.0.84
77
python-dotenv>=0.21.1
88
requests>=2.27.1

scripts/abraia

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,19 @@ def train(project, epochs):
237237
training_session.save()
238238

239239

240+
@cli.command()
241+
@click.argument('project')
242+
@click.option('--device', help='Compilation device (e.g. hailo8)', default='hailo8')
243+
def compile(project, device):
244+
"""Compile a model for edge deployment."""
245+
from abraia.training import load_dataset, ModelTrainer
246+
click.echo('Loading dataset...')
247+
dataset = load_dataset(project)
248+
click.echo('Compiling model...')
249+
training_session = ModelTrainer(project, dataset.task, dataset.classes)
250+
training_session.compile(device=device)
251+
252+
240253
@cli.command()
241254
@click.argument('project')
242255
@click.argument('classes', required=False, default='')

0 commit comments

Comments
 (0)