single = np.array( [[[[5, 0, 8, 7, 8, 1], [1, 9, 5, 0, 7, 7], [6, 0, 2, 4, 6, 6], [9, 7, 6, 6, 8, 4], [8, 3, 8, 5, 1, 3], [7, 2, 7, 0, 1, 0]]]] ) single.shape # (1, 1, 6, 6) identity = np.array( [[[[0, 0, 0], [0, 1, 0], [0, 0, 0]]]] ) identity.shape # (1, 1, 3, 3)
region = single[:, :, 0:3, 0:3] filtered_region = region * identity total = filtered_region.sum() total # np.int64(9)
new_region = single[:, :, 0:3, (0 + 1):(3 + 1)]
new_filtered_region = new_region * identity new_total = new_filtered_region.sum() new_total # np.int64(5)
last_horizontal_region = single[:, :, 0:3, (0 + 4):(3 + 4)]
The selected region does not match the shape of the filter anymore. So, if we try to perform the element-wise multiplication, it fails:
标签:Chapter,region,PyTorchStepByStep,single,Convolutions,filtered,np,new,total From: https://www.cnblogs.com/zhangzhihui/p/18473208