Python Flask搭建yolov3目标检测系统详解流程
作者:mind_programmonkey
YOLOv3没有太多的创新,主要是借鉴一些好的方案融合到YOLO里面。不过效果还是不错的,在保持速度优势的前提下,提升了预测精度,尤其是加强了对小物体的识别能力
【人工智能项目】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 app.py
前端展示部分
到此这篇关于Python Flask搭建yolov3目标检测系统详解流程的文章就介绍到这了,更多相关Python 目标检测系统内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!