在Bluemix 使用OpenWhisk and AlchemyAPI 开发人脸辨识应用系统

在Bluemix 使用OpenWhisk & AlchemyAPI 开发人脸辨识应用系统

作者:陳兆麟 Email:chenlin2@ms9.hinet.net

AlchemyAPI成立于2009年,其深度学习的自然语言处理技术可利用人工智能分析理解网页、文文件、电子邮件、微博等形式的内容;它跟Google一样采用了神经网络分析(目前只有少数几家公司使用这一技术),但Google只是在大脑仿真中采用了这个技术,而Alchemy则可以在不同数据集之上的超集中处理查询; IBM自 2015 年 3月收购 AlchemyAPI,以加速IBM下一代认知运算应用的开发速度, 并把AlchemyAPI的深度学习技术整合进Watson核心平台,以提高Watson迅速辨识阶层,及理解大量数据集之间关系的能力;同时 IBM 也已将AlchemyAPI 整合至 Bluemix;以下范例是使用IBM 刚推的Openwhisk 结合 AlchemyAPI 对上传 image 作人脸辨识。

開發環境: Win7 (64 bit) , Bluemix,Openwhisk, AlchemyAPI

1.進入IBM Bluemix: https://console.ng.bluemix.net/ 點選 Sign Up 註冊後登錄 (30天試用期免費) 將 username 及 password 記錄。

建立 Organization 名稱

建立 Space 名稱

確認 Organization, Space名稱

2. 在 bluemix 樣板選擇 internet of Things Platform Starter建立 App 點選型錄 (CATALOG) =>選擇 [internet of Things Platform Starter]

3. 名稱: wangchen (名稱世界唯一不能重覆)

1 Applicaion 2 services , 點選 wangchen Application

4. 點選型錄 (CATALOG) =>選擇 [AlchemyAPI] 服務 (支援人臉辨識)

綁定 wangchen App

點選 Show Credentials

5. 將 apikey 記錄

6. 點選 [Service Credentials] [ADD CREDENTIALS]

點選 [ADD]

記錄 [username] [password] [host]

7.點選 [wangchen-cloudantNoSQLDB]

點選 [launch]

點選 Create Database , 建立 imageurl,imagedetect 資料庫

點選 imagedetect

建立索引 Status

8.點選 [Create Document and Build index]

9. 瀏覽器進入 https://new-console.ng.bluemix.net/openwhisk/ 點選 [Configure CLI]

10. 根據以下網址: 安裝 python, pip (for win 7:python-2.7.11.amd64.msi)

(https://www.python.org/downloads/release/python-2711/)

11. 將 C:\Python27\Scripts 及 C:\Python27\ 存於控制台->環境變數->path

 $ python --version
   Python 2.7.11
 $ pip --version
   pip 8.1.2

12. 在 win7 命令提示按 1,2,3 次序執行安裝及測試 wsk cli 指令

13.點選 [Edit And Debug]

(https://new-console.ng.bluemix.net/openwhisk/editor)

14.建立 imageFace Action

輸入:imageFace -> [Create Action]

將附錄 image.txt 貼入工作區 (依步驟5更新API key)

15. 建立 [writedb] package: (將步驟 6 [Service Credentials] username, password ,host 填入 xxxxx)(xxxxx 前後不要有符號)

$ wsk package bind /whisk.system/cloudant writedb -p username xxxxx -p password xxxxx -p host xxxxx -p dbname imagedetect (同一行指令)

16.建立 [myCloudant] package: (將步驟 6 [Service Credentials] username, password ,host 填入)

$wsk package bind /whisk.system/cloudant myCloudant -p username xxxxx -p password xxxxx -p host xxxxx (同一行指令)

17.建立 [cloundantTrigger] package: (將步驟 1 所得Organization, Space 填入)

$wsk trigger create cloundantTrigger --feed /Organization_Space/myCloudant/changes --param dbname imageurl --param includeDoc true (同一行指令)

18. 建立 [sequence for Cloudant image Trigger] sequence

$ wsk action create "sequence for Cloudant image Trigger" --sequence imageFace,writedb/write

19. 建立 [Cloudant image Trigger] rule

$ wsk rule create --enable "Cloudant image Trigger" cloundantTrigger "sequence for Cloudant image Trigger"

20.點選 [wangchen.mybluemix.net] 進入 http://wangchen.mybluemix.net

21. 點選 [Go to your Node-Red flow editor] (http://xxxxxxx.mybluemix.net/red/)

進入 Nord-Red 編輯器: 點選 + 新增 flow3 工作區

刪除系統預設範例 flow1

22. 將附錄 face.json 匯入 (文中 xxxxx 要修正為步驟 3 的名稱)

23. 點選 [deploy]

24. 進入影像上傳網頁 http://xxxxxx.mybluemix.net/imageTrigger,點選 sample1

25.顯示分析結果,可將 .jpg 人像填入 umage url 後點選 (sample 請參考附錄)

上傳 sample 檔 (如附錄) 執行人臉分析

26. jpg 檔上傳後點選 [view Dashboard] 可看到每階段執行是否有誤

27. 分析每階段執行過程及結果

$wsk activation list
activations
10b44997fb9b46ecb70652b00e9e4cba  write                       
cdee36240b914150a012f8de1fd2c525   imageface 
7ae4cd35757045c2b09c3b0aed31a39e  sequence for Cloudant image Trigger
6f758c3794ec4ff99a10095db9479793   Cloudant image Trigger
b69847fd49864ded957e1cebc502e0fc   cloundantTrigger2

28.例如查詢 Trigger [cloundantTrigger2] 階段執行過程

$wsk  activation get   b69847fd49864ded957e1cebc502e0fc
ok: got activation /_/b69847fd49864ded957e1cebc502e0fc     {
     "activationId": "b69847fd49864ded957e1cebc502e0fc",         "annotations": [],
     "end": 0,
     "logs": [],
    "name": "cloundantTrigger2",
    "namespace": "liuchenwang12345678@gmail.com",
    "publish": false,
    "response": {
         "result": {
             "_id": "c8dbae94ee85f7f5d135a26338492fdf",
             "_rev": "1-f89b3696b27a66ed4f1edf7e97bc7b24",
             "url": {
                 "url": "http://screenshot.net/o7w7xix.jpg"
             }
         },
         "status": "success",
         "success": true
     },
     "start": 1466127949074,
     "subject": "liuchenwang12345678@gmail.com",
     "version": "0.0.1"
  }
29.刪除資料庫內容

點選 [鉛筆]

刪除資料

30. 上傳 image會斷線,程式有 bug 須修正。

Openwhisk 現階段為測試使用,功能可能會修改;屆時程式也必須修改才能使用

31. 上傳 image 若一直無法連線則須刪除 package, trigger 重設

  $ wsk list  (查詢 package 及 trigger)
  $ wsk package delete /Organization_Space/myCloudantwsk
  $ wsk trigger delete /Organization_Space/cloundantTrigger
  重做步驟 15, 16 即可上傳image

附錄

1 win32diskmanager 安裝及使用:
http://chakra-zh.blogspot.tw/2012/04/windows-win32diskimager-live-usb.html
2.putty安裝及使用:
http://www.ascc.sinica.edu.tw/putty
3.人臉 sample 檔
http://screenshot.net/o7w7xix.jpg
http://screenshot.net/yq4q3io.jpg
http://screenshot.net/e662b2k.jpg
http://screenshot.net/z1g51s2.jpg
http://screenshot.net/d15wztg.jpg
http://screenshot.net/xvkdxfq.jpg
http://screenshot.net/xdq2kag.jpg
http://screenshot.net/qxd2bpo.jpg
4.
image.txt: https://drive.google.com/file/d/0B16KfawnoTbmSnU2d0kzdFZZOEk/view?usp=sharing
apikey=xxxxx (xxxxx 由步驟 5 apiky 取代)
face.json:
https://drive.google.com/file/d/0B16KfawnoTbmd0VLbXpfZFdvTVk/view?usp=sharing
xxxxx.mybluemix.net (xxxxx由步驟 3 name 取代)

參考文獻:

  1. http://www.slideshare.net/HsuanJuLin/bluemixopenwhisk
  2. http://www.ithome.com.tw/news/94335
  3. https://www.ibm.com/developerworks/cn/cognitive/library/cc-analyze-notes-alchemyapi-trs-bluemix/
  4. http://www.infoq.com/cn/news/2014/04/Alchemy-Deep-Learning-Landscape
  5. http://cht.0430.com/us/web17557/
  6. http://www.ithome.com.tw/news/103863
  7. http://www.ithome.com.tw/news/104644
  8. https://drive.google.com/folderview?id=0B7_CUSsY2cbnbm90UTNDWmcwaGs&usp=sharing
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值