pairwise_transform_user.lua 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. local pairwise_utils = require 'pairwise_transform_utils'
  2. local iproc = require 'iproc'
  3. local gm = {}
  4. gm.Image = require 'graphicsmagick.Image'
  5. local pairwise_transform = {}
  6. function pairwise_transform.user(x, y, size, offset, n, options)
  7. assert(x:size(1) == y:size(1))
  8. local scale_y = y:size(2) / x:size(2)
  9. assert(x:size(3) == y:size(3) / scale_y)
  10. x, y = pairwise_utils.preprocess_user(x, y, scale_y, size, options)
  11. assert(x:size(3) == y:size(3) / scale_y and x:size(2) == y:size(2) / scale_y)
  12. local batch = {}
  13. local lowres_y = pairwise_utils.low_resolution(y)
  14. local xs, ys, ls = pairwise_utils.flip_augmentation(x, y, lowres_y)
  15. for i = 1, n do
  16. local t = (i % #xs) + 1
  17. local xc, yc = pairwise_utils.active_cropping(xs[t], ys[t], ls[t], size, scale_y,
  18. options.active_cropping_rate,
  19. options.active_cropping_tries)
  20. xc = iproc.byte2float(xc)
  21. yc = iproc.byte2float(yc)
  22. if options.rgb then
  23. else
  24. yc = image.rgb2yuv(yc)[1]:reshape(1, yc:size(2), yc:size(3))
  25. xc = image.rgb2yuv(xc)[1]:reshape(1, xc:size(2), xc:size(3))
  26. end
  27. table.insert(batch, {xc, iproc.crop(yc, offset, offset, size - offset, size - offset)})
  28. end
  29. return batch
  30. end
  31. return pairwise_transform