为了账号安全,请及时绑定邮箱和手机立即绑定

并行分布式目标检测 API

标签:
大数据

项目地址

https://github.com/JasonJe/Parallel-distributed-object-detection-api

说明

项目的目标是需要开放一个接口,使用者通过该接口上传某次任务的图片集后,后台检测服务调度多个 Faster R-CNN 模型进行目标检测。(不直接采用一个模型检测完全部的类别的原因貌似是因为某些类别的训练集太少,会影响其他类别的识别,所以分多个模型实现。)

项目代码采用 Falcon 实现简单的 API 接口,利用 Redis 队列 和 NFS 服务进行实现检测图片集的分布式调度,使用多进程进行多个模型检测的并行处理。

构建

1. Falcon 构建 RESTful API

1). 图片集上传接口 /images/detection/uploads

请求方式 POST
  • GET 参数: 检测任务的ID task_id

  • POST 参数: {'file': '/path/to/file'} | 内容类型:  Content-Type: multipart/form-data

  • 请求范例:

curl -v -X POST -H "Content-Type: multipart/form-data" -F 'file=@./00001.jpg' -F 'file=@./00002.jpg' ... 'http://localhost:80/images/detection/upload?task_id=00001'

2). 图片结果取回接口 /images/detection/result

请求方式 GET
  • GET 参数: 检测任务的ID task_id

2. Redis Queue 构建分布式的任务队列

1). 安装 Redis 在主节点

# apt-get install redis-server

2). 配置 Redis 数据库开启远程登录

# vim /etc/redis/redis.conf

# bind 127.0.0.1 改为 bind 0.0.0.0,重启服务 redis-server /etc/redis/redis.conf.

3). 配置子节点 Redis 参数

# vim ./conf/config.py

修改相应内容如下:

REDIS_HOST = 'master_node_ip'
REDIS_PORT = 6379
REDIS_DB = 0

3. MySQL 数据库进行相关数据存储

# mysql -u root -p < detectionDB.sql

4. 配置 NFS 服务

1). 安装 NFS 服务在主节点并启动

# apt-get install -y nfs-kernel-server# echo "/path/to/share_path child_node_ip(rw,no_root_squash,async)" >> /etc/exports# systemctl restart nfs-server.service

2). 配置子节点挂载主节点目录

# mkdir /path/to/share_path# mount -t nfs master_node_ip:/path/to/share_path /path/to/share_path

5. API 部署

1). Gunicorn 部署 或者 uWSGI 部署(两者选其一)

  • Gunicorn 部署

# gunicorn --config ./gunconfig.py main:app
  • uWSGI 部署

# uwsgi --ini ./uwsgi.ini

2). Nginx 代理请求

# apt-get install -y Nginx# cp nginx.conf /etc/nginx/# systemctl restart nginx.service

6. 将目标检测服务加入系统服务

# cp detection-server /etc/init.d/# update-rc.d detection-server defaults# systemctl start detection-server.service

2018-09-10 JasonJe



作者:JasonJe
链接:https://www.jianshu.com/p/df9fb3100437


点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消