def forward(self, inps): if self._opr.name == "MaxPool2d": return F.max_pool2d( inps[0], kernel_size=self.param["kernel_size"], stride=self.param["stride"], padding=self.param["padding"], ) else: return F.avg_pool2d( inps[0], kernel_size=self.param["kernel_size"], stride=self.param["stride"], padding=self.param["padding"], mode=self.param["mode"], )
def forward(self, x): bottom_up_features = self.bottom_up(x) bottom_up_features = bottom_up_features[::-1] results = [] prev_features = self.lateral_convs[0](bottom_up_features[0]) results.append(self.output_convs[0](prev_features)) for features, lateral_conv, output_conv in zip(bottom_up_features[1:], self.lateral_convs[1:], self.output_convs[1:]): top_down_features = F.interpolate(prev_features, scale_factor=2, mode="BILINEAR") lateral_features = lateral_conv(features) prev_features = lateral_features + top_down_features results.append(output_conv(prev_features)) # p6 last_p6 = F.max_pool2d(results[0], kernel_size=1, stride=2, padding=0) results.insert(0, last_p6) return results
def forward(self, x): if not self.training or self.drop_prob <= 0.0: return x _, c, h, w = x.shape pad_h = max((self.kernel_size - 1), 0) pad_w = max((self.kernel_size - 1), 0) numel = c * h * w gamma = self.drop_prob * (w * h) / (self.kernel_size**2) / ( (w - self.kernel_size + 1) * (h - self.kernel_size + 1)) mask = mge.random.uniform(0, 1, size=(1, c, h, w)) mask[mask < gamma] = 1 mask[mask >= gamma] = 0 mask = F.max_pool2d(mask, [self.kernel_size, self.kernel_size], stride=1, padding=(pad_h // 2, pad_w // 2)) mask = 1 - mask x1 = F.expand_dims(1.0 * numel / mask.sum(axis=0), axis=0) y = F.matmul(F.matmul(x, mask), x1) return y
def fwd(data): out = F.max_pool2d(data, 2, 2) out = F.avg_pool2d(out, 2, 2) return out
True, 1000, ), ("matinv", MF.matinv, torch.inverse, [(10, 10)], [(30, 30)], True, 1000), ( "matmul", MF.matmul, torch.matmul, [(64, 32), (32, 64)], [(2048, 1024), (1024, 2048)], True, 1000, ), ( "max_pool2d", lambda x: MF.max_pool2d(x, 2), lambda x: TF.max_pool2d(x, 2), [(2, 32, 16, 16)], [(64, 512, 16, 16)], True, 1000, ), ( "normal", lambda x: mge.random.normal(0, 1, x.shape), lambda x: torch.randn(x.shape, device="cuda"), [(100, 100)], [(64, 512, 16, 16)], True, 1000, ),
def forward(self, x): return [F.max_pool2d(x, kernel_size=1, stride=2, padding=0)]