Deploying a YOLOv5 Model with Flask

The following repository was helpful for deploying a YOLOv5 model using Flask.

github.com

It provides a simple web application with an image upload form, as well as REST API samples.

Loading a Custom Model

By modifying the arguments of the load function as follows, it was possible to load a locally trained custom model.

model = torch.hub.load("ultralytics/yolov5", "custom", path='model/best.pt', force_reload=True, autoshape=True) 

https://github.com/robmarkcole/yolov5-flask/blob/f1ee21bc3b14cdf1a1ea3bc95111a8db31172216/webapp.py#L47-L49

Adjust the path value as needed. The force_reload and autoshape options are optional, and in my environment it worked without specifying them.