Skip to content

Commit 5a3c08c

Browse files
authored
Merge pull request #119 from Oneflow-Inc/support-flask-rest-api
Support flask rest api
2 parents c0fb352 + 43f5d2b commit 5a3c08c

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

utils/downloads.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def attempt_download(file, repo="Oneflow-Inc/one-yolov5", release="v1.2.0"):
6666
# Attempt file download from GitHub release assets if not found locally. release = 'latest', 'v7.0', etc.
6767
from utils.general import LOGGER
6868

69-
if file.endswith(".pt"):
69+
if str(file).endswith(".pt"):
7070
repo, release = "ultralytics/yolov5", "v7.0"
7171

7272
def github_assets(repository, version="latest"):

utils/flask_rest_api/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[REST](https://en.wikipedia.org/wiki/Representational_state_transfer) [API](https://en.wikipedia.org/wiki/API)s are
44
commonly used to expose Machine Learning (ML) models to other services. This folder contains an example REST API
5-
created using Flask to expose the YOLOv5s model from [PyTorch Hub](https://pytorch.org/hub/ultralytics_yolov5/).
5+
created using Flask to expose the YOLOv5s model from [OneFlow Hub](https://oneflow.readthedocs.io/en/master/hub.html).
66

77
## Requirements
88

utils/flask_rest_api/restapi.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55

66
import argparse
77
import io
8-
8+
import ssl
99
import oneflow as torch
1010
from flask import Flask, request
1111
from PIL import Image
1212

13+
# https://stackoverflow.com/questions/50236117/scraping-ssl-certificate-verify-failed-error-for-http-en-wikipedia-org
14+
ssl._create_default_https_context = ssl._create_unverified_context
15+
1316
app = Flask(__name__)
1417
models = {}
1518

@@ -41,8 +44,7 @@ def predict(model):
4144
parser.add_argument("--port", default=5000, type=int, help="port number")
4245
parser.add_argument("--model", nargs="+", default=["yolov5s"], help="model(s) to run, i.e. --model yolov5n yolov5s")
4346
opt = parser.parse_args()
44-
4547
for m in opt.model:
46-
models[m] = torch.hub.load("ultralytics/yolov5", m, force_reload=True, skip_validation=True)
48+
models[m] = torch.hub.load("Oneflow-Inc/one-yolov5", "custom", m, force_reload=True, skip_validation=True)
4749

4850
app.run(host="0.0.0.0", port=opt.port) # debug=True causes Restarting with stat

0 commit comments

Comments
 (0)