Esempio n. 1
0
 def backProp_conv(dcfm,cfm,fm,ct,w,b):
     '将卷积层反向传播'
     'dcfm 误差关于cfm的偏导数'
     'cfm 卷基层的输出'
     'fm 卷基层的输入'
     'ct fm和cfm之间的连接表'
     'w 卷积核'
     'b 偏置'
     dfm=np.zeros(fm.shape)
     dw=np.zeros(w.shape)
     db=np.zeros(b.shape)
     dcfm=dcfm*fun.dsigmoid(cfm)
     for i in xrange(0,b.shape[0]):
         this_dcfm=dcfm[i]
         db[i]=np.sum(this_dcfm)
     for i in xrange(0,w.shape[0]):
         this_fm=fm[ct[0,i]]
         this_w=w[i]
         this_dcfm=dcfm[ct[1,i]]
         '误差关于dfm的偏导数'
         this_dfm=fun.dconv2_in(this_dcfm, this_w,this_w)
         dfm[ct[0,i]]=dfm[ct[0,i]]+this_dfm
         '误差关于dw的偏导数'
         dw[i]=fun.dconv2_kernel(this_dcfm, this_fm,this_w)
     return [dfm,dw,db]
Esempio n. 2
0
 def backPropSubsampling(dsfm,sfm,fm,sw,sb,pool_size,stride):
     dims,height,width=fm.shape
     dfm=np.zeros((dims,height,width))
     dsw=np.zeros(sw.shape)
     dsb=np.zeros(sb.shape)
     dsfm=dsfm*fun.dsigmoid(sfm)
     kernel=np.ones(pool_size)
     for i in xrange(0,dims):
         this_dsfm=dsfm[i]
         this_kernel=kernel*sw[i]
         dsb[i]=np.sum(this_dsfm[:])
         dsfm_beforeSubsampling=np.zeros((height-pool_size[0]+1,width-pool_size[1]+1))
         dx=0
         dy=0
         for y in xrange(0,dsfm_beforeSubsampling.shape[0],stride):
             dx=0
             for x in xrange(0,dsfm_beforeSubsampling.shape[1],stride):
                 dsfm_beforeSubsampling[y,x]=this_dsfm[dy,dx]
                 dx+=1
             dy+=1
         dfm[i]=fun.dconv2_in(dsfm_beforeSubsampling, fm[i],this_kernel)
         dthis_kernel=fun.dconv2_kernel(dsfm_beforeSubsampling,fm[i],this_kernel)
         dsw[i]=np.sum(dthis_kernel)
     return [dfm,dsw,dsb]