DEV Community

Cover image for Deep Learning Style Transformations in Ruby
kojix2
kojix2

Posted on

4

Deep Learning Style Transformations in Ruby

Want to do DeepLearning inference in Ruby?
Yes, you can!

Requirement

st.rb

require 'magro'
require 'onnxruntime'

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

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

output = model.predict(input1: input)

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

Magro::IO.imsave(ARGV[1], result)
Enter fullscreen mode Exit fullscreen mode

Run

Input image size should be a multiple of 4

ruby st.rb in.jpg out.jpg
Enter fullscreen mode Exit fullscreen mode

Generated images

https://commons.wikimedia.org/wiki/File:Arimatsushibori.JPG 1

Arimatsushibori

candy
candy.jpg

mosaic
mosaic.jpg

pointilism
pointilism

rain_princess
rain_princess.jpg

udnie
udnie.jpg

Beautiful.

Other posts


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

Image of Datadog

The Future of AI, LLMs, and Observability on Google Cloud

Datadog sat down with Google’s Director of AI to discuss the current and future states of AI, ML, and LLMs on Google Cloud. Discover 7 key insights for technical leaders, covering everything from upskilling teams to observability best practices

Learn More

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more