【问题标题】:How do I divide a tensor into NXN block and reconstruct the first from these blocks again?如何将张量划分为 NXN 块并再次从这些块中重建第一个?
【发布时间】:2019-04-25 21:23:08
【问题描述】:

我有一个形状为 (1,32,32) 的张量,形状中的第一个索引显示通道数,我的图像是灰色的。现在我需要将此张量划分为 8x8 块,并对每个块进行一些处理,例如 DCT,并在更改后将这些新块替换为前一个块。我们在 Matlab 中有 mattocellcelltomat,但在 keras 中,我不知道该怎么做?你能告诉你在 Keras 的建议吗?谢谢。

我使用了这个代码:

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)

但不知道是真是假?!你能告诉我上面的代码可以在keras中使用张量吗?谢谢

【问题讨论】:

    标签: python tensorflow keras


    【解决方案1】:

    我使用了前面提到的代码,它可以工作。根据我的实验,我们可以通过 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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-09
      相关资源
      最近更新 更多