LoginSignup
296
197

More than 5 years have passed since last update.

画像認識対決 ~Microsoft VS Google VS IBM VS AWS~

Last updated at Posted at 2016-12-17

はじめに

この記事は、Life is Tech ! アドベントカレンダー2016 18日目の記事です。

はじめまして!iPhoneメンターのにっしーです。
「時間があるときに勉強しよう」と人工知能/機械学習/Deep Learning/認識技術といったトピックの記事の見つけてはストックしてきたものの、結局2016年は何一つやらずに終わろうとしているので、とにかく一歩でも足を踏み出すべく、 本質的な理解等はさておき、とにかく試してみる ということで画像認識技術に触れてみることにしました。

画像認識とは?

画像認識とは、画像データの画像内容を分析して、その形状を認識する技術のことである。
-- Weblio辞書  

画像認識では、画像データから対象物となる輪郭を抽出して、背景から分離し、その対象物が何であるかを分析するのが基本になります。
しかし、人間なら無意識化に行われていることですが、コンピュータにとっては高度で複雑な処理になります。
コンピュータでは、ピクセルの集合である画像データから、ある種のパターンを取り出し、そこから意味を読み取るという処理を行います。それは、パターン認識とも呼ばれ、画像認識だけでなく、音声認識や言語解析などにも用いられています。応用した技術としては、OCRや、顔認証、虹彩認証などがあります。

代表的な画像認識API

すごい時代になったもので、Deep Learning等を活用した最新の顔認識・物体認識サービスが各社より提供され、APIを通して簡単にアプリケーションに組み込むことができるようになってきています。APIとして利用できる代表的なサービスは、下記のようなサービスです。

このなかの代表的なものとして、Microsoft Computer Vision APIGoogle Cloud Vision APIIBM Bluemix Alchemy APIを比較してみようと思います。でも、ただ比較するだけじゃつまらないので対決させてみようと思います。  

対決方法

体力知力を競うなど色々考えたのですが、ここはにっしーの独断と偏見で評価を行います。

一位 二位 三位
3点 2点 1点

image

利用方法

Microsoft Computer Vision API

利用の際には Subscription Keyが必要になります。無料試用が可能なのでこちらからご登録ください。
登録して得られた Subscription Keyをサンプルコード上のAPIKEYで指定してください。

自分でコードを書く前にまずはどんなものか試してみたいという場合は、公式解説ページを見てもらうと準備されている画像を選ぶ or 自分の画像をアップロードして確認できるようになっているのでおすすめです。

ここでは、Microsoft Computer Visionの使い方をRubyで説明します。

インストール方法

$ gem install microsoft_computer_vision 

サンプルコード

microsoft_computer_vision.rb
require 'microsoft_computer_vision'

IMAGE_URL = ARGV[0] # 画像URL
client = MicrosoftComputerVision::Client.new('APIKEY')
options = {
  visual_features: 'Description',
  details: 'Celebrities'
}

res = client.analyze(IMAGE_URL, options)
puts res.body

Google Cloud Vision API

利用の際には、Google Cloud Platformへ登録が必要である。未登録の場合、Cloud Vision APIの「無料トライアル」ボタンを押して登録しよう。登録したら、APIKEYの発行をしましょう。

Cloud Vision APIの使い方が参考になるので、困ったらこちらを参照しましょう。

google_cloud_vision.rb
require 'base64'
require 'json'
require 'net/https'

IMAGE_FILE = './sample.jpg'

API_KEY = 'xxxxxxxx'
API_URL = "https://vision.googleapis.com/v1/images:annotate?key=#{API_KEY}"

# 画像をbase64にエンコード
base64_image = Base64.strict_encode64(File.new(IMAGE_FILE, 'rb').read)

# APIリクエスト用のJSONパラメータの組み立て
body = {
  requests: [{
    image: {
      content: base64_image
    },
    features: [
      {
        type: 'LABEL_DETECTION',
        maxResults: 5
      }
    ]
  }]
}.to_json

# Google Cloud Vision APIにリクエスト投げる
uri = URI.parse(API_URL)
https = Net::HTTP.new(uri.host, uri.port)
https.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri)
request["Content-Type"] = "application/json"
response = https.request(request, body)

# APIレスポンス出力
puts response.body

IBM Bluemix Alchemy API

APIを利用するには、まず、APIKEYを発行してもらう必要がありますので、こちらからユーザ情報の登録を行なって、APIKEYを発行します。APIKEYは登録したEメールアドレス宛てで送られてきます。
APIKEYが無事発行されたら、次はSDKの準備をします。用意されているのはRuby,PythonなどがGithub上のリポジトリに上げられています。Alchemyの公式サイトのSDKのページでは、一部アーカイブファイルになっているものをダウンロードする形になっていますが、最新はGithubから取得できます。

AWS rekognition

以下を参照ください。
http://qiita.com/kaibadash@github/items/037a5cebc35f3925fec8

東京:東京タワー

東京タワー

著作者: Luke,Ma
東京タワーは、東京都港区芝公園にある総合電波塔の愛称である。正式名称は日本電波塔。1958年12月23日竣工。東京のシンボル・観光名所として知られる。

Microsoft Computer Vision APIの結果

descriptions "outdoor","city","building",
"large","light","view","background","traffic"
,"night","boat","clock","street","tall",
"colorful","bridge","driving","tower"
captions "a view of a city at night"

Google Cloud Vision APIの結果

descriptions "skyline","metropolitan area","city",
"city","cityscape","horizon","landmark",
"human settlement","night", "metropolis"
captions なし

※ landmark APIから Tokyo Towerは得られませんでした。

IBM Bluemix Alchemy APIの結果

descriptions night,city,light,building
captions なし

AWS Rekognition APIの結果

descriptions "City","Downtown","Metropolis","Urban","Architecture","Tower","Bazaar","Market","Night","Outdoors","Lighting","Road","Street","Town","Plaza","Town Square","Intersection","Building","High Rise","Skyscraper","Convention Center"
captions なし

評価結果

一位 二位 三位
Microsoft IBM Google, AWS

東京:原宿

原宿

 著作者: ジユン
東京都渋谷区東部,JR原宿駅周辺地区の通称。旧町名。かつて相模国から奥州へ行くための鎌倉街道の宿駅があった。

Microsoft Computer Vision APIの結果

descriptions "outdoor","building","road","clock","street",
"people","walking","city","sidewalk","group","front",
"standing","large","man","parked","riding","motorcycle",
"crowd","tower","train","board","station","tall"
captions "a group of people walking down a street in front of a building"

Google Cloud Vision APIの結果

descriptions "town","tourism","nature","plaza","town square"
captions なし

※ landmark APIを用いると、descriptionに Harajuku Station が得られました!

IBM Bluemix Alchemy APIの結果

descriptions "crowd", "blue sky"
captions なし

AWS Rekognition APIの結果

descriptions "Crowd","Building","Housing","Villa","Downtown","Town","Transportation","Cabin","Hut","Rural","Shack","Shelter","Intersection","Road","Bazaar","Market","Carnival","Festival","Parade","City","Urban","Neighborhood","Architecture","Plaza","Town Square","Church","Worship","Landscape","Nature","Scenery","Metropolis","Person","Tourist"
captions なし

評価結果

一位 二位 三位
Microsoft Google, AWS IBM

沖縄:美ら海水族館

美ら海水族館

沖縄県国頭(くにがみ)郡本部(もとぶ)町の、海洋博公園内にある水族館。平成14年(2002)開館。水槽「黒潮の海」は世界最大級。サンゴや深海魚の展示もある。

Microsoft Computer Vision APIの結果

descriptions "water","table","bird","boat","group",
"people","blue","large","flying","pool","man","lake",
"airplane","flock","swimming","ocean","standing",
"laptop","beach","umbrella","plane","body","dock",
"air","woman","jet","playing"
captions "Fish swimming in the aquarium"

Google Cloud Vision APIの結果

descriptions "fish","marine biology","ocean","sea","shark"
captions なし

IBM Bluemix Alchemy APIの結果

descriptions "vehicle"
captions なし

AWS Rekognition APIの結果

descriptions "Aquarium", "Aquatic", "Sea", "Water", "Fish", "Shark", "Tuna", "Outdoors", "Sea"
captions なし

評価結果

一位 二位 三位
Microsoft Google, AWS IBM

僕に触ると赤くなっちゃ…

くま

Microsoft Computer Vision APIの結果

descriptions "clothing","person","wearing","bear","teddy",
"standing","brown","holding","hat","red","dressed",
"posing","small","sweater","stuffed","shirt",
"white","young","black","man","woman","head","blue"
captions "person with a red teddy bear"

Google Cloud Vision APIの結果

descriptions "clothing","person","red","bear","teddy"
captions なし

IBM Bluemix Alchemy APIの結果

descriptions "red","bear"
captions なし

AWS Rekognition APIの結果

descriptions "People","Person","Human","Teddy Bear","Toy","Cardigan","Clothing","Sweater","Accessories","Fleece","Jacket","Wool"
captions なし

評価結果

一位 二位 三位
Microsoft Google IBM,AWS

考察

画像のタグの部分については互角かと思いましたが、
Microsoftのcaptionsは圧倒的なものを感じました。
* 物体の位置関係も含めて説明している点
* 特に特徴すべきものについて説明している点
* AWSは肝心のredが得られませんでした。
* Googleのlandmark APIはサービスによっては影響が大きい

かなり偏った評価ではありますが....

最終結果

一位 二位 三位
Microsoft:15点 Google:9点 IBM,AWS:6点

参考文献

GoogleのCloud Vision APIをrubyで実装してrakeタスクにしたった - Qiita
AlchemyAPIのAlchemyVisionを使ってみる | Tech-Sketch
Gratisography: Free high-resolution photos

まとめ

これらの技術の驚くべきは「画像認識が出来た」だけではなく、むしろ画像に写っている物体が何なのか、どういう状況なのか、ということをシステムが学んでいくところにあります。 ここ最近、特にSFの世界に入ってきたなぁと実感してます。 今後も飛躍的に認識能力は上がっていき、様々な製品に使われることになるでしょう。

次回は、@shartsuによるSomething regarding programming with kids(訳:子供とのプログラミングに関すること)です。乞うご期待!!

296
197
6

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
296
197