forked from eriklindernoren/PyTorch-YOLOv3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
64 lines (49 loc) · 1.14 KB
/
Copy pathserver.py
File metadata and controls
64 lines (49 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from PIL import Image
from flask import Flask, escape, request, jsonify, Response
from score import init, preprocess, predict, postprocess
from flask_cors import CORS
import io
CONFIG = {
"model_def": "config/yolov3.cfg",
"weights_path": "weights/yolov3.weights",
"class_path": "data/coco.names",
"conf_thres": 0.8,
"nms_thres": 0.4,
"batch_size": 1,
"n_cpu": 0,
"img_size": 416,
}
# init model
# TODO need to passing config
init()
app = Flask(__name__)
CORS(app)
CONFIG = {
"model_def": "config/yolov3.cfg",
"weights_path": "weights/yolov3.weights",
"class_path": "data/coco.names",
"conf_thres": 0.8,
"nms_thres": 0.4,
"batch_size": 1,
"n_cpu": 0,
"img_size": 416,
}
@app.route("/")
def live():
return "OK!"
@app.route('/score', methods=['POST'])
def score():
data = request.data
buffer = io.BytesIO()
buffer.write(data)
buffer.seek(0)
img = Image.open(buffer)
detections = predict(img)
resp = jsonify(detections)
resp.status_code = 200
return resp
@app.route('/metadata')
def metadata():
return CONFIG
if __name__ == "__main__":
app.run()