Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This usage is out of date, please use 'application/json' as content-type #622

Open
huoshen8211 opened this issue May 23, 2020 · 7 comments
Assignees

Comments

@huoshen8211
Copy link

环境

  • PaddleHub1.7.0
  • PaddlePaddle1.7.2
  • 系统环境:Windows
  • python版本3.7

复现信息:

执行命令hub serving start -m ace2p,启动http服务,访问网页,选择图片,点击start没反应,f12查看请求回应信息为:
{"msg":{"Warnning":"This usage is out of date, please use 'application/json' as content-type to post to /predict/ace2p. See 'https://github.com/PaddlePaddle/PaddleHub/blob/release/v1.6/docs/tutorial/serving.md' for more details."}}

@Steffy-zxf
Copy link
Contributor

Steffy-zxf commented May 24, 2020

@huoshen8211
Copy link
Author

不过不知道为啥使用http返回的图片是全黑的,使用api的是正常的。

@ShenYuhan
Copy link
Contributor

您好,您是说使用的网页上的图片是全黑,还是在脚本中请求得到的返回是全黑呢?您打开的网页是我们测试使用的,不能正常使用的。

@huoshen8211
Copy link
Author

用网页的确实不能用,脚本里面返回是全黑的,api返回是正确的

@ShenYuhan
Copy link
Contributor

用网页的确实不能用,脚本里面返回是全黑的,api返回是正确的

可以看下您的脚本吗 我这边复现排查

@huoshen8211
Copy link
Author

今天换了个电脑,屏幕比较亮,发现之前的电脑可能不是全黑,轮廓是灰色的,不仔细看是全黑的,api是彩色的。

import paddlehub as hub
import cv2
import requests
import json
import base64
import numpy as np

human_parser = hub.Module(name="ace2p")
result = human_parser.segmentation(images=[cv2.imread('d:\\paddlehub\\6.png')],output_dir="d:\\paddlehub",visualization=True)
print(result)

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)
    data = cv2.imdecode(data, cv2.COLOR_RGB2BGR)
    return data

data = {'images':[cv2_to_base64(cv2.imread("d:\\paddlehub\\tw.jpg"))]}
headers = {"Content-type": "application/json"}
url = "http://127.0.0.1:8866/predict/ace2p"
r = requests.post(url=url, headers=headers, data=json.dumps(data))

print(base64_to_cv2(r.json()["results"][0]['data']))

cv2.imshow('ret.jpg',base64_to_cv2(r.json()["results"][0]['data']))
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.destroyWindow('ret.jpg')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants