본문 바로가기
AI | 딥러닝/Coding

[Python] 1x1 point convolution 코드

by 고뭉나무 2023. 9. 9.

 

 

 

 

 

# loading the layer file
layer_name = 'intro.conv1.convs.1'
inp = np.load(f'npy/{layer_name}_inp.npy')
wgt = np.load(f'npy/{layer_name}_wgt.npy')
try:
	bias = np.load(f'npy/{layer_name}_bias.npy')
except:
	bias_flag = False
else:
	bias_flag = True
out = np.load(f'npy/{layer_name}_out.npy')


# changing to fixed point
inp_fxp = inp.astype(np.int64)
wgt_fxp = wgt.astype(np.int64)
psum_fxp = np.zeros_like(out).astype(np.int64)
out_ref_fxp = out.astype(np.int64)

# 1x1 point convolution
for co in range(C_OUT):
	psum_fxp[0, co, :, :] = 0
	for ci in range(C_IN):
		psum_fxp[0, co, :, :] += inp_fxp[0, ci, :, :] * wgt_fxp[co, ci, 0, 0]

# scaling
psum_fxp_scale = psum_fxp * S_y_fxp

 

반응형

댓글