背景:
以yolov3为例子,构建基于flask的微服务架构,对外提供算法能力。制定服务的接口规范,后续有新的算法模型,也可以按照此例子的做法,快速地部署。
概念:
wsgi:Web服务器网关接口(Python Web Server Gateway Interface,缩写为WSGI)是为Python语言定义的Web服务器和Web应用程序或框架之间的一种简单而通用的接口。
Flask:python web微服务开发框架
gunicorn:在unix系统运行的wsgi服务器
nginx:http和反向代理服务器(客户端无法感知代理的存在)
准备工作:
安装pytorch/flask/gunicorn/nginx
注:安装方法不在此说明,请自行百度。
下载yolov3以及其权重:
git clone https://github.com/eriklindernoren/PyTorch-YOLOv3
新建文件夹:
在项目根目录新建文件夹
static:用于存放静态文件,这里存放检测后的图片结果,用于在浏览器显示出来。
templates:存放html模板。
upload.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>上传图片</title>
</head>
<body>
<h1>欢迎使用Web目标检测服务</h1>
<form action="" enctype='multipart/form-data' method='POST'>
<input type="file" name="file" style="margin-top:20px;"/>
<br>
<input type="submit" value="上传并识别" class="button-new" style="margin-top:15px;"/>
</form>
</body>
</html>
upload_ok.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>目标检测结果</title>
</head>
<body>
<h1>欢迎使用Web目标检测服务</h1>
<form action="" enctype='multipart/form-data' method='POST'>
<input type="file" name="file" style="margin-top:20px;"/>
<br>
<input type="submit" value="上传并识别" class="button-new" style="margin-top:15px;"/>
</form>
<img src="