Want to do DeepLearning inference in Ruby?
Yes, you can!
Requirement
ONNXRuntime and its Ruby binding created by Andrew Kane.
Liquid error: internal
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)
Run
Input image size should be a multiple of 4
ruby st.rb in.jpg out.jpg
Generated images
https://commons.wikimedia.org/wiki/File:Arimatsushibori.JPG 1
Beautiful.
Other posts
-
Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) ↩
Top comments (0)