ggml
ggml copied to clipboard
How do pixel unshuffle in ggml ?
Dear friends, We have following pytorch code in esrgan network, hope to used in ggml, would you like show us how to do in ggml ? As you know, ggml tensor default maximum dims is 4, but here view and permute is 6. We need change GGML_MAX_DIMS to 6 ?
def pixel_unshuffle(x, scale: int):
"""Pixel unshuffle."""
b, c, hh, hw = x.size()
out_channel = int(c * (scale ** 2))
assert hh % scale == 0 and hw % scale == 0
h = hh // scale
w = hw // scale
x_view = x.view(b, c, h, scale, w, scale)
x_view = x_view.permute(0, 1, 3, 5, 2, 4)
return x_view.reshape(b, out_channel, h, w)
Maybe as a sequence of views and 4D permutes:
x_view = x.view(b*c, h, scale, w*scale)
x_view = x_view.permute(0, 2, 1, 3)
x_view = x.view(b*c*scale, h, w, scale)
x_view = x_view.permute(0, 3, 1, 2)
return x_view.reshape(b, out_channel, h, w)
(not sure if this is correct so verify)
If it is correct, it would be something like this in ggml:
x = ggml_reshape_4d(ctx, x, w*scale, scale, h, b*c);
x = ggml_permute (ctx, x, 0, 2, 1, 3);
x = ggml_cont (ctx, x);
x = ggml_reshape_4d(ctx, x, scale, w, h, b*c*scale);
x = ggml_permute (ctx, x, 2, 0, 1, 3);
x = ggml_cont (ctx, x);
x = ggml_reshape_4d(ctx, x, w, h, out_channel, b);
Thanks@ggerganov , we tested, the answer is not correct.
Thanks@ggerganov , we tested, the answer is not correct.
How did you work around this?