pandding'replicate'실행
1637 단어 컴퓨터 시각 학습
# -*- coding: utf-8 -*-
"""
Created on Sun Oct 6 14:30:58 2019
@author: Administrator
"""
import numpy as np
def compute_conv(fm,k):
[h,w]=fm.shape
r=int(k/2)
# 0 map
padding_fm=np.zeros([h+r*2,w+r*2],np.float32)
# , 4 ,
padding_fm[r:h+r,r:w+r]=fm
# 'replicate'
for j in range(r):
padding_fm[r-1-j][r-1-j] = padding_fm[r-j][r-j]
padding_fm[r-1-j][r+w+j] = padding_fm[r-j][r+w-1+j]
padding_fm[r+h+j][r-1-j] = padding_fm[r+h-1+j][r-j]
padding_fm[r+h+j][r+w+j] = padding_fm[r+h-1+j][r+w-1+j]
for i in range(r-j, r+w+j):
padding_fm[r-1-j][i] = padding_fm[r-j][i]
for i in range(r-j, r+h+j):
padding_fm[i][r+w+j] = padding_fm[i][r+w-1+j]
for i in range(r-j, r+h+j):
padding_fm[i][r-1-j] = padding_fm[i][r-j]
for i in range(r-j, r+w+j):
padding_fm[r+h+j][i] = padding_fm[r+h-1+j][i]
print(padding_fm)
weights_data=[
[ 1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
weights_data=[
[ 1, 2, 3, 4, 5],
[6, 7, 8, 9, 10],
[11,12,13,14,15],
[16,17,18,19,20],
[21,22,23,24,25]
]
fm = np.asarray(weights_data,np.float32)
compute_conv(fm,5)