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 app.py
前端展示部分
到此這篇關於Python Flask搭建yolov3目標檢測系統詳解流程的文章就介紹到這瞭,更多相關Python 目標檢測系統內容請搜索WalkonNet以前的文章或繼續瀏覽下面的相關文章希望大傢以後多多支持WalkonNet!
推薦閱讀:
- 基於 Python實現雲服務器的CDN域名遠程鑒權配置
- 如何使用flask將模型部署為服務
- python如何構建mock接口服務
- Python OpenCV實現人物動漫化效果
- Python實現老照片修復之上色小技巧