python - 这些功能是如何实现的?
问题描述
def im2col(input_data, filter_h, filter_w, stride=1, pad=0):
N, C, H, W = input_data.shape
out_h = (H + 2 * pad - filter_h)//stride + 1
out_w = (W + 2 * pad - filter_w)//stride + 1
img = np.pad(input_data, [(0,0), (0,0), (pad, pad), (pad, pad)], 'constant')
col = np.zeros((N, C, filter_h, filter_w, out_h, out_w))
for y in range(filter_h):
y_max = y + stride*out_h
for x in range(filter_w):
x_max = x + stride * out_w
# why!!!!!
col[:, :, y, x, :, :] = img[:, :, y:y_max:stride, x:x_max:stride]
col = col.transpose(0, 4, 5, 1, 2, 3).reshape(N*out_h*out_w, -1)
# why!!!!!
return col
def col2im(col, input_shape, filter_h, filter_w, stride=1, pad=0):
N, C, H, W = input_shape
out_h = (H + 2 * pad - filter_h)//stride + 1
out_w = (W + 2 * pad - filter_w)//stride + 1
# why!!!!!
col = col.reshape(N, out_h, out_w, C, filter_h, filter_w).transpose(0, 3, 4, 5, 1, 2)
img = np.zeros((N, C, H + 2 * pad + stride - 1, W + 2 * pad + stride - 1))
for y in range(filter_h):
y_max = y + stride * out_h
for x in range(filter_w):
x_max = x + stride * out_w
# why!!!!!
img[:, :, y:y_max:stride, x:x_max:stride] += col[:, :, y, x, :, :]
return img[:, :, pad:H + pad, pad:W + pad]
我无法理解我用评论“#为什么!!!!!”标记的行下面的行。
为什么它们是多维实现的?
解决方案
推荐阅读
- python - 我们如何根据条件创建具有多个输出的 pytorch 模型?
- python - 在Python中,有没有办法通过直接访问类对象而不指定object.attribute来返回特定的属性值?
- ios - 测试依赖注入
- node.js - 有没有办法列出目录 node.js 中所有文件的文件扩展名?
- c++ - 来自 C++ SDK 的 IF 语句措辞不正确
- python - 如何让我的项目在重新启动后记住变量/列表?
- javascript - 图像滑块需要额外单击 1 次才能重置。无法修复
- google-apps-script - 电子邮件通知中出现错误“异常:单元格引用超出范围”
- javascript - 如何设置在线服务器以不断执行我的 javascript 代码?
- xcode - Flutter运行和flutter pub sec报错| 颤振驱动程序