5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Rubyで深層学習のスタイル変換を動かす

Last updated at Posted at 2019-09-02

mymontage.jpg

準備するもの

st.rb

require 'magro'
require 'onnxruntime'

model = OnnxRuntime::Model.new('mosaic.onnx')

input = Magro::IO.imread(ARGV[0])
                 .transpose(2, 0, 1)
                 .expand_dims(0)
                 .to_a

output = model.predict(input1: input)

result = Numo::Int32.cast(*output['output1'])
                    .clip(0, 255)
                    .transpose(1, 2, 0)
                    .cast_to(Numo::UInt8)

Magro::IO.imsave(ARGV[1], result)

実行2

ruby st.rb in.jpg out.jpg # pngも可

生成された画像

https://commons.wikimedia.org/wiki/File:Arimatsushibori.JPG 3 を 1200x900に変換

Arimatsushibori.JPG

imagemagickによるmontage
mymontage.jpg

candy
candy.jpg

mosaic
mosaic.jpg

pointilism
pointilism.jpg

rain_princess
rain_princess.jpg

udnie
udnie.jpg

美しい絵が出力されました。

  1. created by @yoshoku

  2. 画像のサイズによってはエラーが出る。4の倍数じゃないとエラーが出るとか?

  3. Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)

5
1
0

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
5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?