之前经常使用Photoshop处理证件照片,最近学习了Paddle入门课程,发现PaddleHub人像分割在线服务接口比较方便,拿过来简单介绍一下。
首先,安装PaddleHub
pip install paddlehub==1.6.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
这里我选用的是deeplabv3p_xception65_humanseg模型,
在命令行中开户服务
hub serving start -m deeplabv3p_xception65_humanseg
下一步开始Django框架搭建
主要工作在于Views内方法编写
import requests
import json
import cv2
import base64
from .forms import UploadFileForm
from .models import *
import numpy as np
def handle_uploaded_file(f,filename):
filename_path = f'{settings.MEDIA_ROOT}{filename}' #生成文件名及路径
with open(filename_path,'wb+') as destination:
for chunk in f.chunks():
destination.write(chunk)
destination.close()
return filename_path
def