On integrating Flask-restful API and some AI model

Introduction

Recently I’ve been working on a project using flask-restful API to deploy AI models. I am completely new to Flask (and multiprocessing programming), so here is a blog recording the issues I met.

Issues

Flask app initiated twice

Reason: when running flask app, if the debug mode is on, then the app would be initiated twice.
Reference (https://blog.csdn.net/sun_dragon/article/details/51861139):
python flask框架 app.debug=True时,启动脚本被执行了2次
The first thing it does is start the main function in a new thread so it can monitor >the source files and restart the thread when they change.
http://stackoverflow.com/questions/9276078/whats-the-right-approach-for-calling-functions-after-a-flask-app-is-run
如果你想要避免加载两次,应该设置app.run(debug=True, use_reloader=False)

Image in bytes shouldn’t be put in Queue

If you put images in bytes to a Queue in Python, then you can’t get it. (error occurs at queue.get())
Solution: convert your image to ndarray using opencv

cv2.imdecode(np.frombuffer(IMAGE_IN_BYTES, np.uint8), -1)

CUDA initialization error

Solution: add the following line to your main()

multiprocessing.set_start_method(‘spawn’)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值