图像块的访问(填充 padding,步长 stride,窗 Window/kernel/filter)

本文介绍了使用MATLAB中的utilities函数实现图像分块的方法,并详细解释了如何通过调整填充和步长来改变输出矩阵的尺寸。同时给出了具体的计算公式及遍历范围。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

无填充是有填充的特例(填充为 1)。

utilities(matlab)—— 图像分块(image2cols、cols2image)(未填充)

1. 一个图像块 ⇒ 返回一个值

输出矩阵的大小:

  • out_height = (H + 2*padding - field_height) / stride + 1;
  • out_width = (W + 2*padding - field_width) / stride + 1;

从 window 的左上角逐个遍历(未进行 padding 填充):

  • range_y = 1:stride:H-field_height+1
  • range_x = 1:stride:W-field_width+1

转载于:https://www.cnblogs.com/mtcnn/p/9422217.html

“class ResConv1DLayer(object): def __init__(self, rng, input, n_in=0, n_out=0, halfWinSize=0, dilation=1, activation=T.nnet.relu, mask=None): self.input = input self.n_in = n_in self.n_out = n_out self.halfWinSize = halfWinSize windowSize = 2*halfWinSize + 1 self.filter_size = windowSize self.dilation = (1, dilation) in4conv2D = input.dimshuffle(0, 1, 'x', 2) w_shp = (n_out, n_in, 1, windowSize) if activation == T.nnet.relu: W_values = np.asarray(rng.normal(scale=np.sqrt(2. / (n_in*windowSize + n_out)), size = w_shp), dtype=theano.config.floatX ) else: W_values = np.asarray( rng.uniform(low = - np.sqrt(6. / (n_in*windowSize + n_out)), high = np.sqrt(6. / (n_in*windowSize + n_out)), size = w_shp), dtype=theano.config.floatX ) if activation == T.nnet.sigmoid: W_values *= 4 self.W = theano.shared(value=W_values, name='ResConv1d_W', borrow=True) b_shp = (n_out,) self.b = theano.shared(np.asarray( rng.uniform(low=-.0, high=.0, size=b_shp), dtype=input.dtype), name ='ResConv1d_b', borrow=True) if dilation > 1: conv_out = T.nnet.conv2d(in4conv2D, self.W, filter_shape=w_shp, border_mode='half', filter_dilation=(1, dilation) ) else: conv_out = T.nnet.conv2d(in4conv2D, self.W, filter_shape=w_shp, border_mode='half') if activation is not None: conv_out_bias = activation(conv_out + self.b.dimshuffle('x', 0, 'x', 'x')) else: conv_out_bias = (conv_out + self.b.dimshuffle('x', 0, 'x', 'x')) out2 = conv_out_bias.dimshuffle(0, 1, 3, 2)[:, :, :, 0] if mask is not None: out2_sub = out2[:, :, :mask.shape[1] ] mask_new = mask.dimshuffle(0, 'x', 1) self.output = T.set_subtensor(out2_sub, T.mul(out2_sub, mask_new) ) else: self.output = out2 self.params=[self.W, self.b] self.paramL1 = abs(self.W).sum() + abs(self.b).sum() self.paramL2 = (self.W**2).sum() + (self.b**2).sum()”这段代码对应的“class ResConv1DLayer(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride=1, dilation=1, activation=F.relu, batch_norm=True): super().__init__() self.activation = activation self.conv = nn.Conv1d( in_channels=in_channels, out_channels=out_channels, kernel_size=kernel_size, stride=stride, padding=(kernel_size - 1) // 2 * dilation, # 适应 dilation dilation=dilation, bias=False ) self.shortcut = nn.Conv1d( in_channels=in_channels, out_channels=out_channels, kernel_size=1, stride=stride, bias=False ) if (in_channels != out_channels or stride != 1) else nn.Identity() self.bn = nn.BatchNorm1d(out_channels) if batch_norm else None nn.init.kaiming_normal_(self.conv.weight, mode='fan_out', nonlinearity='relu') if isinstance(self.shortcut, nn.Conv1d): nn.init.kaiming_normal_(self.shortcut.weight, mode='fan_out', nonlinearity='relu') def forward(self, x): residual = self.shortcut(x) out = self.conv(x) if self.bn is not None: out = self.bn(out) if self.activation is not None: out = self.activation(out) return out + residual”这段代码,有没有地方没有对应上还是怎么说,感觉怎么样
03-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值