Running HAMS SeatBelt module#

[ ]:
import os
from ipywidgets import FileUpload
from omegaconf import OmegaConf

from mapping_cli.maneuvers.seat_belt import SeatBelt
from mapping_cli.config.config import Config
[ ]:
from ipywidgets import FileUpload
from IPython.display import display, Image
upload = FileUpload(accept='.mp4', multiple=False)
display(upload)

Upload a driver-facing video to detect the seatbelt

[ ]:
with open("front_video.mp4", "wb") as f:
    f.write(upload.value[0].content)

Modify the config variables depending on the need.

[ ]:
config = {
    "device": "cpu",
    "skip_frames": 25,
    "classifier_confidence_threshold": 0.75,
    "detection_percentage": 0.75,
    "model_path": ["models", "seatbelt_model.pth"],
}

Now, save the config to seatbelt.yaml, create a directory to store the outputs named output and run the seabelt module

[ ]:
with open('seatbelt.yaml', 'w') as f:
    OmegaConf.save(OmegaConf.create(config), f)
os.makedirs('output', exist_ok=True)
[ ]:
seatbelt = SeatBelt(inputs={"fpath":os.path.abspath('front_video.mp4')}, inertial_data=None, config=Config('seatbelt.yaml'), out_folder='./output')
_, found_belt, _ = seatbelt.run()

Visualize the Outputs#

[ ]:
if found_belt:
    display(Image(filename='output/seatbelt_image.jpg'))

Final Test Results#

[ ]:
import json
import ast
with open('output/report.txt', 'r') as f:
    report = json.load(f)
    print("Pass: ", ast.literal_eval(report['Seatbelt'])[1])