简体   繁体   English

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

[英]How can I change subsets value in theano tensor impeded into loop?

layer_Fmaps of size (1,96,236,236) sitwches of size (1,96,708,708) 大小(1,96,236,236)的layer_Fmaps大小(1,96,708,708)的小地图

in each 3 by 3 matrix in layer_Fmaps there is only cell having a value 1 which should be replace by the opposite value of sitwches 在layer_Fmaps的每个3 x 3矩阵中,只有一个值为1的单元格应由相反的情景

I can't find a way to solve the problem by assigning a direct value into a certain location using a loop 我找不到通过使用循环将直接值分配给特定位置来解决问题的方法

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

knowing that switchs and layer_Fmaps are tensor4 知道switch和layer_Fmaps是tensor4

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,3,SW)

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

d = f(img,sswitchs)

Any suggestion would be appreciated. 任何建议,将不胜感激。

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

And: 和:

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)

I modified several things: 我修改了几件事:

  • Replaced 96 for 69. I guess the "96" was a typo. 将96替换为69。我猜“ 96”是一个错字。
  • Uniform indexing 统一索引
  • Key arguments should be at the end. 关键论点应在结尾。

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

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