欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Python Flask搭建yolov3目标检测系统详解流程

程序员文章站 2022-06-23 20:19:12
【人工智能项目】python flask搭建yolov3目标检测系统后端代码from flask import flask, request, jsonifyfrom pil import image...

【人工智能项目】python flask搭建yolov3目标检测系统

Python Flask搭建yolov3目标检测系统详解流程

后端代码

from flask import flask, request, jsonify
from pil import image
import numpy as np
import base64
import io
import os

from backend.tf_inference import load_model, inference

os.environ['cuda_visible_devices'] = '0'

sess, detection_graph = load_model()

app = flask(__name__)

@app.route('/api/', methods=["post"])
def main_interface():
    response = request.get_json()
    data_str = response['image']
    point = data_str.find(',')
    base64_str = data_str[point:]  # remove unused part like this: "data:image/jpeg;base64,"

    image = base64.b64decode(base64_str)       
    img = image.open(io.bytesio(image))

    if(img.mode!='rgb'):
        img = img.convert("rgb")
    
    # convert to numpy array.
    img_arr = np.array(img)

    # do object detection in inference function.
    results = inference(sess, detection_graph, img_arr, conf_thresh=0.7)
    print(results)

    return jsonify(results)

@app.after_request
def add_headers(response):
    response.headers.add('access-control-allow-origin', '*')
    response.headers.add('access-control-allow-headers', 'content-type,authorization')
    return response


if __name__ == '__main__':
    app.run(debug=true, host='0.0.0.0')

展示部分

python -m http.server

Python Flask搭建yolov3目标检测系统详解流程

python app.py

Python Flask搭建yolov3目标检测系统详解流程

前端展示部分

Python Flask搭建yolov3目标检测系统详解流程

到此这篇关于python flask搭建yolov3目标检测系统详解流程的文章就介绍到这了,更多相关python 目标检测系统内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!