A lot of multi-dimensional
array data types
• RMagick, OpenCV, multiarray, ...
• NArray, NMatrix, StatSample, ...
• gsl, tensorflow, ...
• Julia, Python, R, ...
Slide 21
Slide 21 text
Everything tensor
• 1-tensor (vector)
‣ e.g. 1ch sound, text, time series scalar data
• 2-tensor (matrix)
‣ e.g. 2ch sound, grayscale image, time series vector data
• 3-tensor
‣ e.g. RGB image, grayscale animation
• 4-tensor
‣ e.g. RGB animation
Slide 22
Slide 22 text
Image
Animation
Sound
Tensor
Function
Statistical
Model
Neural
Network
Slide 23
Slide 23 text
What is best for me?
• RMagick
• ruby-opencv
• hornetseye
Slide 24
Slide 24 text
Different gems have different
types for the same purpose
• RMagick: Magick::Image
• ruby-opencv: CvMat
• horneteyes: MultiArray
Slide 25
Slide 25 text
What data type is best?
• RMagick: Magick::Image
• ruby-opencv: CvMat
• horneteyes: MultiArray
A
B
G
R
component_size
shape[2] = pixel_channels
A
B
G
R
A
B
G
R
A
B
G
R
shape[1] = image_width
...
...
...
...
shape[0]
=
im
age_height
shape = (image_height, image_width, pixel_channels)
Slide 28
Slide 28 text
B
G
R
component_size
shape[2] = pixel_channels
B
G
R
B
G
R
B
G
R
shape[1] = image_width
...
...
...
shape[0]
=
im
age_height
shape = (pixel_channels, image_width, image_height)
Slide 29
Slide 29 text
0
B
G
R
shape[2] = pixel_channels = 3
0
B
G
R
0
B
G
R
0
B
G
R
shape[1] = image_width = 17
...
...
...
...
shape = (19, 17, 3)
steps[1] = 4
shape[0]
=
im
age_height
=
19
0
0
0
0
steps = (18, 4)
steps[0] = 18
Image
Animation
Sound
Tensor
Function
Statistical
Model
Neural
Network
Slide 32
Slide 32 text
With Standard Tensor
Representation
• We can separate to develop tensor
serializer and tensor operators
‣ Image, Audio, DB I/O
‣ Tensor transformation
• and easy to integrate with each other
Slide 33
Slide 33 text
I tried to make it
• IMF -- Image I/O
• NumBuffer -- Tensor data type
Slide 34
Slide 34 text
IMF
• Image Manipulation Framework
• https://github.com/mrkn/IMF
• I've aimed it to reproduce PIL
• Pluggable design
Slide 35
Slide 35 text
Current status
Detect Load Save
JPEG ○ ○
PNG ○ ○ △
GIF ○
WEBP ○
Slide 36
Slide 36 text
NumBuffer
• Tensor allocation and manipulation
• Data type conversion
• I/F for Ruby and C
• I want support both dense and sparse
tensors
• I will release a gem until RubyKaigi
Slide 37
Slide 37 text
Demonstration
• Integrating with tensorflow
Slide 38
Slide 38 text
tf-waifu2x
• Waifu2x on tensorflow
• It works, but it's incomplete
Machine Learning on Ruby
• We need standard tensor
interchanging system like numpy
• It's enough to provide the common
data type for dense tensors
‣ I can't select one library
Slide 44
Slide 44 text
If you're interested in
• SciRuby-jp
‣ https://groups.google.com/forum/#!
forum/sciruby-jp
‣ Japanese de OK
• Slack
‣ https://sciruby-jp.herokuapp.com