百度云图像识别系统接入

in #cn6 years ago (edited)

深度学习的浪潮正在全世界漫延,而深度学习对图像的识别训练需要大量的样本和算力支持,普通人从无到有搭建一个图像识别系统需要大量的时间,幸运的是互联网巨头为我们提供了云服务,在云端为我们训练好了识别系统,我们只需要支付低廉的费用就可以调用API实现高精度的图像识别。
这里我们使用百度云提供的图像识别接口。首先,在百度云注册账号进入控制台新建一个图像识别应用,可以看到图像识别包括图像主体检测、logo商标识别、菜品识别、车型识别、动物识别和植物识别六个类别。

我们新建一个应用,然后在管理应用界面可以看到API Key和Secret Key,记录下这两个值。百度云的鉴权认证机制需要使用这两个值获取Access Token。

百度云提供了bash、PHP、JAVA、Python、C++和C#六种语言接口,这里我是用了Python3。官方文档给的Python示例基于Python2,所以我们需要对其进行一些修改。例如Python3中urllib和urllib2已经被合并,urllib2的功能被urllib.request所替代,整体获取Access Token的代码如下。

我们在获取到的json文件头就可以看到我们所需的Access Token值,将其记录下来。接下来以车辆识别为例,去网上下载一张车辆图片,将图片路径和Access Token填入下列代码。这里与官方例程不同的是,Python3中发送和接收数据需要使用utf-8来编码和解码。

最终我们将如下图片上传,返回的JSON显示这辆车有0.985的概率是一辆法拉利599。

11.jpg

如果要对植物、动物或其他种类图像进行识别只需要相应修改request_url即可。百度云每天提供500次免费识别,并且在百度云控制台可以获得相应的流量统计。

参考文档https://ai.baidu.com/docs#/ImageClassify-API/top
代码已上传至https://github.com/HaoHuaqing/BaiduImageAPI

Sort:  

Congratulations @haohuaqing! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

You published your First Post

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

By upvoting this notification, you can help all Steemit users. Learn how here!

Congratulations @haohuaqing! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

You made your First Vote

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

By upvoting this notification, you can help all Steemit users. Learn how here!

您好。我是 steem 中文区的机器人。昨天,您在 steem 的 cn 社区第一次发布文章。为了让更多的人读到新人的文章,您的文章被列入了中文区新人之家的“希望工程”,欢迎点击查看

新人之家欢迎你,这里有帮助新手了解 steem 的指南。请注意,新手最容易忽视的两点:1. 千万不要丢失您的密码;2.千万不要抄袭,非原创的文字、图片、视频资料请务必注明出处,否则可能会得到差评并列入黑名单。

欢迎参加之家举办的各种活动,并期待您在未来继续发布优质原创文章!

您不必回复我。当然,如果您回复,我会非常高兴的,即使我只是个卑微的机器人!

Hello. I am a bot from Steem CN community. Yesterday you posted in CN category for the first time. Your post is listed in the Welcome Center for New Steemians. Welcome to CN community. Please do not forget your password. Do not plagiarise. Looking forward to more high-quality posts from you in the future!

You do not have to reply me. But if you reply me, I would be happy, even I am a bot!

Congratulations @haohuaqing! You have received a personal award!

1 Year on Steemit
Click on the badge to view your Board of Honor.

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @haohuaqing! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!

Coin Marketplace

STEEM 0.36
TRX 0.12
JST 0.040
BTC 70446.49
ETH 3571.68
USDT 1.00
SBD 4.73