【人工智能项目】Python Flask搭建yolov3目标检测系统
2021/10/30 17:15:15
本文主要是介绍【人工智能项目】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目标检测系统的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-21Python编程基础教程
- 2024-11-20Python编程基础与实践
- 2024-11-20Python编程基础与高级应用
- 2024-11-19Python 基础编程教程
- 2024-11-19Python基础入门教程
- 2024-11-17在FastAPI项目中添加一个生产级别的数据库——本地环境搭建指南
- 2024-11-16`PyMuPDF4LLM`:提取PDF数据的神器
- 2024-11-16四种数据科学Web界面框架快速对比:Rio、Reflex、Streamlit和Plotly Dash
- 2024-11-14获取参数学习:Python编程入门教程
- 2024-11-14Python编程基础入门