Giter Club home page Giter Club logo

stgan_bald's Introduction

stgan_bald

基于PaddleHub的秃头生成器

模型概述

秃头生成器(stgan_bald),该模型可自动根据图像生成1年、3年、5年的秃头效果。

模型效果:

详情请查看此链接:https://aistudio.baidu.com/aistudio/projectdetail/1145381

本模型为大家提供了小程序,欢迎大家体验

image

选择模型版本进行安装

$ hub install stgan_bald==1.0.0

Module API说明

bald(images, use_gpu=False)

秃头生成器预测接口,预测输入一张人像,输出三张秃头效果(1年、3年、5年)

参数

images(str): 待检测的图片路径

use_gpu(bool): 是否使用 GPU

返回

自动将预测结果输出到bald_output文件夹

API预测代码示例

import paddlehub as hub
import cv2
stgan_bald = hub.Module(name="stgan_bald")
result = stgan_bald.bald(images=[cv2.imread('/PATH/TO/IMAGE')])

服务部署

第一步:启动PaddleHub Serving

$ hub serving start -m stgan_bald

第二步:发送预测请求

import requests
import json
import base64
import cv2
import numpy as np
def cv2_to_base64(image):
    data = cv2.imencode('.jpg', image)[1]
    return base64.b64encode(data.tostring()).decode('utf8')
def base64_to_cv2(b64str):
    data = base64.b64decode(b64str.encode('utf8'))
    data = np.fromstring(data, np.uint8)
    data = cv2.imdecode(data, cv2.IMREAD_COLOR)
    return data
# 发送HTTP请求
org_im = cv2.imread('/PATH/TO/IMAGE')
data = {'images':[cv2_to_base64(org_im)]}
headers = {"Content-type": "application/json"}
url = "http://127.0.0.1:8866/predict/stgan_bald"
r = requests.post(url=url, headers=headers, data=json.dumps(data))
img0 = base64_to_cv2(r.json()["results"]['data_0'])
img1 = base64_to_cv2(r.json()["results"]['data_1'])
img2 = base64_to_cv2(r.json()["results"]['data_2'])
img = cv2.cvtColor(img0, cv2.COLOR_RGB2BGR)
cv2.imwrite('bald_0.png', img)

贡献者

刘炫、彭兆帅、郑博培

依赖

paddlepaddle >= 1.8.2

paddlehub >= 1.8.0

stgan_bald's People

Contributors

1084667371 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.