How to use yolov5 api with flask offline?
I was able to run the Flask app with yolov5 on a PC with an internet connection. I followed the steps mentioned in yolov5 docs and used this file: yolov5/utils/flask_rest_api/restapi.py,
But I need to achieve the same offline(On a particular PC). Now the issue is, when I am using the following:
model = torch.hub.load(&quot;ultralytics/yolov5&quot;, &quot;yolov5&quot;, force_reload=True)

It tries to download model from internet. And throws an error.
Urllib.error.URLError: &lt;urlopen error [Errno - 2] name or service not known&gt;

How to get the same results offline.
Thanks in advance.

If you want to run detection offline, you need to have the model already downloaded.
So, download the model (for example yolov5s.pt) from https://github.com/ultralytics/yolov5/releases and store it for example to the yolov5/models.
After that, replace
# model = torch.hub.load(&quot;ultralytics/yolov5&quot;, &quot;yolov5s&quot;, force_reload=True)  # force_reload to recache

with
model = torch.hub.load(r'C:\Users\Milan\Projects\yolov5', 'custom', path=r'C:\Users\Milan\Projects\yolov5\models\yolov5s.pt', source='local')

With this line, you can run detection also offline.
Note: When you start the app for the first time with the updated torch.hub.load, it will download the model if not present (so you do not need to download it from https://github.com/ultralytics/yolov5/releases).

