class Magick::Image

Attributes

in_dselect[RW]

dselect内かどうかのフラグ もう少しいい書き方ないのか

Public Instance Methods

==(image) click to toggle source
# File lib/deepselect.rb, line 119
def ==(image)
        if self.in_dselect or image.in_dselect
                # guard
                unless image.class == Magick::Image
                        raise "現状dselectの比較相手はMagick::Imageのみ対応です" +
                        "images.dselect{|dselect_image| dselect_image == image} のノリで"
                end
                DSelect.compare(self, image)
        else
                return self.default_equal(image)
        end
end
Also aliased as: default_equal
comapre_vector(image) click to toggle source
# File lib/deepselect.rb, line 146
def comapre_vector(image)
        if image.class != Magick::Image # or image.class != Array
                # 文章長すぎ
                err_stdout = "Error: あとでErrorClass名追加します
                 compare対象はMagick::Imageでないと駄目です
                 compare arg must be Magick::Image"
                raise err_stdout
        end
        return DSelect.compare(self, image)
end
default_equal(image)

alias :to_v :to_vector さすがに他のライブラリと被りそうな気が

Alias for: ==
to_menoh_image() click to toggle source
# File lib/deepselect.rb, line 132
def to_menoh_image
        # TODO: DRYできていない場所が多すぎるので直す
        # model_optから引っ張ってくるのありだろうけどめんどいな
        input_shape = {
                channel_num: 3,
                width: 224,
                height: 224
        }
        image = self.resize_to_fill(input_shape[:width], input_shape[:height])
        'BGR'.split('').map do |color|
                image.export_pixels(0, 0, image.columns, image.rows, color).map { |pix| pix / 256 }
        end.flatten
end
to_vector() click to toggle source

batch処理したほうが速いだろうけど とりあえず逐次処理

# File lib/deepselect.rb, line 97
def to_vector
        return @vector if @vector

        vgg16 = DSelect.vgg16
        opt = DSelect.model_opt
        model = vgg16.make_model(opt)

        # onnx variable name
        conv1_id, fc6_id, softmax_id = DSelect.id.values
        
        image = self.to_menoh_image
        image_set = [{ name: conv1_id, data: image}]
        result = model.run(image_set)

        network_output = result.find { |x| x[:name] == fc6_id }
        @vector = network_output[:data].first

        return @vector
end