Upgrade to Pro — share decks privately, control downloads, hide ads and more …

IMF and tensor interchange system

IMF and tensor interchange system

tokyorubykaigi11

Kenta Murata

May 28, 2016
Tweet

More Decks by Kenta Murata

Other Decks in Technology

Transcript

  1. OMG

  2. Answer • Use Python • Use Pillow for processing images

    • Use Chainer for building CNN • NumPy bridges Pillow and Chainer
  3. What are missing? • Processing images ‣ Loading / saving

    ‣ Resizing ‣ Horizontal flipping ‣ Average image calculation ‣ Multi-dimensional array conversion RMagick ruby-opencv hornetseye
  4. What are missing? • Processing images ‣ Loading / saving

    ‣ Resizing ‣ Horizontal flipping ‣ Average image calculation ‣ Multi-dimensional array conversion hornetseye
 (MultiArray) ruby-opencv
 (CvMat) NArray (Numo) NMatrix
  5. What are missing? • Building CNN ‣ Tensor calculation ‣

    Convolutional filter calculation ‣ GPGPU ‣ Neural network builder ‣ Gradient descent optimizer hornetseye
 (MultiArray) ruby-opencv
 (CvMat) NArray (Numo) NMatrix
  6. What are missing? • Building CNN ‣ Tensor calculation ‣

    Convolutional filter calculation ‣ GPGPU ‣ Neural network builder ‣ Gradient descent optimizer
  7. What are missing? • Building CNN ‣ Tensor calculation ‣

    Convolutional filter calculation ‣ GPGPU ‣ Neural network builder ‣ Gradient descent optimizer
  8. Library relationship Image RMagick ruby-opencv hornetseye Tensor NArray (Numo) NMatrix

    MultiArray
 (hornetseye) CvMat
 (ruby-opencv) Others GPGPU DL OpenCV ML
 (ruby-opencv) decisiontree liblinear gsl_matrix
 (rb-gsl)
  9. A lot of multi-dimensional array data types • RMagick, OpenCV,

    multiarray, ... • NArray, NMatrix, StatSample, ... • gsl, tensorflow, ... • Julia, Python, R, ...
  10. 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
  11. Different gems have different types for the same purpose •

    RMagick: Magick::Image • ruby-opencv: CvMat • horneteyes: MultiArray
  12. Generic Tensor • 4 parameters ‣ component type (size) ‣

    dimension ‣ shape ‣ steps / strides
  13. 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)
  14. 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)
  15. 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
  16. Generic Tensor • 4 parameters ‣ component type (size) ‣

    dimension ‣ shape ‣ steps / strides
  17. 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
  18. I tried to make it • IMF -- Image I/O

    • NumBuffer -- Tensor data type
  19. 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
  20. IMF tf-wife2x tensorflow MPBEJNBHF XSBQX
 /VN#V⒎FS $POWFSUUPqPBUUFOTPS
 GPSUFOTPSqPXGSPN /VN#V⒎FS MPBEUFOTPSqPX


    NPEFM BQQMZNPEFM $POWFSUUP
 VJOU/VN#V⒎FS
 GPSPVUQVU NBLFJNBHF
 GSPN/VN#V⒎FS TBWFJNBHF
  21. waifu2x 7-step
 CNN Magnify x2
 Nearest
 Neighbor Pixel value
 adjustment

    7-pixel padding insertion ↑ prepared ↑ omitted ↑ incomplete ↑ OK https://github.com/mrkn/tf-waifu2x/blob/master/convert_waifu2x.py
  22. IMF tf-wife2x tensorflow MPBEJNBHF XSBQX
 /VN#V⒎FS $POWFSUUPqPBUUFOTPS
 GPSUFOTPSqPXGSPN /VN#V⒎FS MPBEUFOTPSqPX


    NPEFM BQQMZNPEFM $POWFSUUP
 VJOU/VN#V⒎FS
 GPSPVUQVU NBLFJNBHF
 GSPN/VN#V⒎FS TBWFJNBHF
  23. 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