1 Star 0 Fork 1

黄阳/keras-flask-deploy-webapp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
util.py 656 Bytes
一键复制 编辑 原始数据 按行查看 历史
Fing 提交于 2019-12-18 00:12 . upgrade to tf 2.0
"""Utilities
"""
import re
import base64
import numpy as np
from PIL import Image
from io import BytesIO
def base64_to_pil(img_base64):
"""
Convert base64 image data to PIL image
"""
image_data = re.sub('^data:image/.+;base64,', '', img_base64)
pil_image = Image.open(BytesIO(base64.b64decode(image_data)))
return pil_image
def np_to_base64(img_np):
"""
Convert numpy image (RGB) to base64 string
"""
img = Image.fromarray(img_np.astype('uint8'), 'RGB')
buffered = BytesIO()
img.save(buffered, format="PNG")
return u"data:image/png;base64," + base64.b64encode(buffered.getvalue()).decode("ascii")
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/huangyang/keras-flask-deploy-webapp.git
git@gitee.com:huangyang/keras-flask-deploy-webapp.git
huangyang
keras-flask-deploy-webapp
keras-flask-deploy-webapp
master

搜索帮助

D67c1975 1850385 1daf7b77 1850385