Skip to content

Commit

Permalink
完善文档和接口
Browse files Browse the repository at this point in the history
  • Loading branch information
ILG2021 committed Feb 16, 2023
1 parent d4eb71f commit 5121f5c
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 22 deletions.
Binary file modified README.md
Binary file not shown.
35 changes: 35 additions & 0 deletions client/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import fetch from "node-fetch";

var url = "https://ultralytics.com/images/zidane.jpg"
var type = 'jpg'
var imgData = await fetch(url).then(r => r.buffer()).then(buf => `data:image/${type};base64,`+buf.toString('base64'));

var response = await fetch('http://127.0.0.1:1235/persons',
{method: 'POST', body: JSON.stringify({
"img": [
imgData
]
}),
"headers": {
"content-type": "application/json"
}
}
);
var data = await response.json();

console.log("persons:" , data);

response = await fetch('http://127.0.0.1:1235/objects',
{method: 'POST', body: JSON.stringify({
"img": [
imgData
]
}),
"headers": {
"content-type": "application/json"
}
}
);
data = await response.json();

console.log("objects:" , data);
File renamed without changes.
20 changes: 0 additions & 20 deletions node_client.js

This file was deleted.

19 changes: 17 additions & 2 deletions yolov5.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def index():


@app.route('/persons', methods=["POST"])
def analyze():
def persons():
if request.method != "POST":
return
instances = request.get_json()['img']
Expand All @@ -36,8 +36,23 @@ def analyze():
print(len(output_dict))
return jsonify(results)

@app.route('/objects', methods=["POST"])
def objects():
if request.method != "POST":
return
instances = request.get_json()['img']
results = []
if instances and len(instances) > 0:
for instance in instances:
encoded_data = instance.split(',')[1]
im = Image.open(io.BytesIO(base64.b64decode(encoded_data)))
ai_results = models['yolov5s'](im, size=320) # reduce size=320 for faster inference
input_dict = json.loads(ai_results.pandas().xyxy[0].to_json(orient="records"))
results.append(input_dict)
return json.dumps(results)

if __name__ == "__main__":
print("人物检测v1.0")
print("对象检测v1.0")
parser = argparse.ArgumentParser(description="Flask API exposing YOLOv5 model")
parser.add_argument("--port", default=1235, type=int, help="port number")
parser.add_argument('--model', nargs='+', default=['yolov5s'], help='model(s) to run, i.e. --model yolov5n yolov5s')
Expand Down

0 comments on commit 5121f5c

Please sign in to comment.