Deepselect

Features

deepselect is a Ruby image recognition library using DeepLearning. This library makes it easy to search for images.

deepselectはDeepLearningを使ったRubyの画像認識ライブラリです。 簡単に画像検索ができます。

Installation

install the gem:

gem install deepselect

Synopsis

require 'rmagick'
require "deepselect"

# 5 coffeeshop logo images (famous in Japan)
image_list = [
    "logo_doutor.jpg", "logo_stmarc.png",
    "logo_komeda.jpeg", "logo_starbucks.png",
    "logo_tully's.jpg"
]

# Read Image
images = image_list.map do |name|
    image_dir = "./images/"+name
    image = Magick::Image.read(image_dir).first
end

# Read another Starbucks Image
starbucks_image = Magick::Image.read("./images/image_starbucks.png").first
puts "input: #{"./images/image_starbucks.png"} " # => ".images/image_starbucks.png"

# Search the array for the image most similar to the given image
selected_image = images.dselect{|dimage| dimage == starbucks_image}
puts "most similar image: #{selected_image.filename}" # => ".images/logo_starbucks.png"

Options

images.dselect(take: "deafult", with: "")  &block

args

  • take: Specify how many of the most similar images to retrieve. Interger 1,2,3... or String "all" are accepted.
  • with: Specify whether to output similarity and index. String are accepted. (ex. "similarity, index" )

As an example, when outputting two images with similarity:

stmark_photo_image = Magick::Image.read("./images/photo_stmarc.jpg").first
selected_image = images.dselect(take: 2, with: "similarity"){|dimage| dimage == stmark_photo_image}
p selected_image

Cache

By caching feature vectors, the speed of the second search is faster than that of the first search.
If you want to pre-store the feature vectors, use the dinit method.

images.dinit # calc feature vector

selected_image = images.dselect{|dimage| dimage == compare_image}

Requirements

deepselect requires installation of Menoh and imagemagick.
Please check the page of github Menoh for installation Menoh.

License

deepselect is MIT license.

Note: Thankfully data/VGG16.onnx is download from 'https://www.dropbox.com/s/bjfn9kehukpbmcm/VGG16.onnx?dl=1'.
That model is generated by onnx-chainer from pre-trained model which is uploaded at http://www.robots.ox.ac.uk/%7Evgg/software/very_deep/caffe/VGG_ILSVRC_16_layers.caffemodel
That pre-trained model is released under Creative Commons Attribution License.