简体   繁体   English

如何将张量分为NXN块并再次从这些块重建第一个?

[英]How do I divide a tensor into NXN block and reconstruct the first from these blocks again?

I have a tensor with shape (1,32,32) that the first index in shape shows the number of channels and my images are gray. 我有一个形状的张量(1,32,32),形状中的第一个索引显示通道数,我的图像是灰色的。 now I need to divide this tensor into 8x8 blocks and do some processes on each block like DCT and after changes, replace these new blocks with the previous one. 现在我需要将这个张量分成8x8块并在每个块上做一些过程,比如DCT,在更改之后,用前一个块替换这些新块。 we have mattocell and celltomat in Matlab, but in keras, I do not know how can I do this? 我们在Matlab中有mattocellcelltomat ,但在keras中,我不知道我该怎么做? could you please tell your suggestions in Keras? 你可以在Keras告诉你的建议吗? Thank you. 谢谢。

I used this code: 我用过这段代码:

def slicAndJpeg(img):
    for i in range (int(img.shape[1].value/8)):
        for j in range(int(img.shape[2].value/8)):
            temp=img[:,i*8:i*8+8,j*8:j*8+8]
            tempb=K.zeros((8,8))
            DCT(temp,tempb)

but I do not know it is true or not?! 但我不知道这是真的吗?! could you please tell me it is possible to use the above code for tensors in keras? 你能否告诉我可以在keras上使用上面的代码进行张量? Thanks 谢谢

I used the before mentioned code and it works. 我使用前面提到的代码,它的工作原理。 based on my experiments we can do this by for loops, but if somebody has a better suggestion please put it here. 基于我的实验我们可以通过for循环来做到这一点,但如果有人有更好的建议,请把它放在这里。

 def slicAndJpeg(img):
        for i in range (int(img.shape[1].value/8)):
            for j in range(int(img.shape[2].value/8)):
                temp=img[:,i*8:i*8+8,j*8:j*8+8]
                tempb=K.zeros((8,8))
                DCT(temp,tempb)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM