测试练习
t1={01,-1,-1,-1,01,-1,-1,-1,01,}t2={01,-1,01,-1,01,-1,01,-1,01,}t3={-1,-1,01,-1,01,-1,01,-1,-1,}o={{-1,-1},{-1,0},{-1,1},{0,-1},{0,0},{0,1},{1,-1},{1,0},{1,1},}function 卷积计算(t,特征器)local 卷积={}local 跳跃=1for y1=1,#t-跳跃*2 do --创建一个空卷积卷积[y1]={}for x1=1,#t[1]-跳跃*2 dotable.insert(卷积[y1],0)endendfor y=1,#t dofor x=1,#t[1] doif y>跳跃 and x>跳跃 and y<#t and x<#t[1] thenlocal 过滤器={}for k,v in pairs(o) dolocal a=t[y+v[2]][x+v[1]]*特征器[k]table.insert(过滤器,a)endlocal j=(过滤器[1]+过滤器[2]+过滤器[3]+过滤器[4]+过滤器[5]+过滤器[6]+过滤器[7]+过滤器[8]+过滤器[9])/9if j<0 then --负数取0j=0end卷积[y-跳跃][x-跳跃]=tonumber(string.format("%0.2f",j))endendend--print(卷积)return 卷积endfunction 池化函数(a)local 池化={}for y1=1,math.floor(#a/2+0.5) do池化[y1]={}for x1=1,math.floor(#a[1]/2+0.5) dotable.insert(池化[y1],0)endendlocal y1=0for y=1,#a,2 doy1=y1+1local x1=0for x=1,#a[1],2 dox1=x1+1local t={0,0,0,0}t[1]=a[y][x]if a[y+1]~=nil thenif a[y+1][x]~=nil thent[2]=a[y+1][x]endif a[y+1][x+1]~=nil thent[4]=a[y+1][x+1]endendif a[y][x+1]~=nil thent[3]=a[y][x+1]endtable.sort(t)池化[y1][x1]=t[#t]endendprint(池化)return 池化endt={{-1,-1,01,-1,-1,-1,-1,-1,01,-1,-1,},{-1,-1,-1,01,-1,-1,-1,01,-1,-1,-1,},{-1,-1,-1,-1,01,-1,01,-1,-1,-1,-1,},{-1,-1,-1,-1,-1,01,-1,-1,-1,-1,-1,},{-1,-1,-1,-1,01,-1,01,-1,-1,-1,-1,},{-1,-1,-1,01,-1,-1,-1,01,-1,-1,-1,},{-1,-1,01,-1,-1,-1,-1,-1,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 1,0.11,0.56,0.56,0.11, 1,1,0.33,1,0.56,0.56,} --12.03--p={1,0.56,0.56,0.56,1,0.33,0.56, 1,0.11,0.56,0.56,0.11,0.56,1,0.33,1,0.56,0.56,} --10.92--p={1,0.56,0.56,0.56,1,0.33,0.56,0.56,0.11,0.56, 1,0.11,0.56,1,0.56,1,0.56,0.56,} --11.15--p={1,0.56,0.33,0.56,1,0.33,0.56,0.56, 0, 1,0.56, 0,0.56,1,0.33,1,0.56,0.33,} --10.24--p={1,0.56,0.33,0.56,1,0.33,0.56,0.56,0,1,0.56,0,0.56,1,0.33,1,0.33,0.33,} --10.01--p={1,0.56,0.33,0.56,0.56,0.33,0.56,0.56,0,1,0.33,0,0.56,1,0.33,1,0.56,0.33,} --9.57--p={1,0.56,0.33,0.56,0.56,0.33,0.56,0.56,0,1,0.33,0,0.56,1,0.33,0.56,0.56,0.33,} --9.13--local a=0--for k,v in pairs(p) do-- a=a+v--end--print(a)--lua_exit()local 合集={}local 卷积1=卷积计算(t,t1)local 池化1=池化函数(卷积1)local 池化1=池化函数(池化1)local 卷积2=卷积计算(t,t2)local 池化2=池化函数(卷积2)local 池化2=池化函数(池化2)local 卷积3=卷积计算(t,t3)local 池化3=池化函数(卷积3)local 池化3=池化函数(池化3)print(池化1)print(池化2)print(池化3)for y=1,#池化1 dofor x=1,#池化1[1] dolocal a=池化1[y][x]table.insert(合集,a)endendfor y=1,#池化2 dofor x=1,#池化2[1] dolocal a=池化2[y][x]table.insert(合集,a)endendfor y=1,#池化3 dofor x=1,#池化3[1] dolocal a=池化3[y][x]table.insert(合集,a)endendprint(合集)
