如何更改阻塞到循环中的theano张量中的子集值?

时间:2017-01-24 20:32:18

标签: python deep-learning theano

layer_Fmaps的大小(1,96,236,236) 大小不等(1,96,708,708)

在layer_Fmaps中的每个3乘3矩阵中,只有值为1的单元格应替换为sitwches的相反值

我无法通过使用循环将直接值分配到某个位置来找到解决问题的方法

c.getT()

知道switchs和layer_Fmaps是tensor4

def switchs(layer_Fmaps, step=2, switches):
        for idx in range(96):
            for i in range(0, 708, step):
                for j in range(0, 708, step):
                    val = layer_Fmaps[0][idx][i/2,j/2]
                    switches = T.set_subtensor(switches[0][idx][i:i + step, j:j + step],val)
        return  switches

任何建议都将不胜感激。

1 个答案:

答案 0 :(得分:0)

def switchs(layer_Fmaps, switches, step=2):
     for idx in range(96):     
         for i in range(0, 708, step):
             for j in range(0, 708, step):
                 val = layer_Fmaps[0,idx,i/2,j/2]
                 switches = T.set_subtensor(switches[0, idx, i:i + step, j:j + step],val)
     return  switches

img = np.zeros((1,96,236,236))
sswitchs =  np.zeros((1,96,708,708))

inp = T.tensor4('img')
SW = T.tensor4('SW')

tester = switchs(inp,SW, 3)

f = theano.function([inp, SW], tester)    

d = f(img,sswitchs)

我修改了几件事:

  • 取代96为69.我猜“96”是一个错字。
  • 统一索引
  • 关键论点应该在最后。