def call(self, inputs): """Forward compute. :param inputs: input feature map :return: tuple of feature map """ # assert len(inputs) == len(self.in_channels) laterals = [ lateral_conv(inputs[i + self.start_level]) for i, lateral_conv in enumerate(self.lateral_convs) ] used_backbone_levels = len(laterals) for i in range(used_backbone_levels - 1, 0, -1): try: laterals[i - 1] += ops.InterpolateScale(scale_factor=2, mode='nearest')( laterals[i]) except Exception: laterals[i - 1] += ops.InterpolateScale( size=laterals[i - 1].size()[2:], mode='nearest')(laterals[i]) outs = [ self.fpn_convs[i](laterals[i]) for i in range(used_backbone_levels) ] if self.num_outs > len(outs): for i in range(self.num_outs - used_backbone_levels): outs.append(ops.MaxPool2d(1, stride=2)(outs[-1])) return {idx: out for idx, out in enumerate(outs)}
def call(self, inputs): """Forward compute. :param inputs: input feature map :return: tuple of feature map """ # assert len(inputs) == len(self.in_channels) laterals = [ lateral_conv(inputs[i + self.start_level]) for i, lateral_conv in enumerate(self.lateral_convs) ] used_backbone_levels = len(laterals) for i in range(used_backbone_levels - 1, 0, -1): laterals[i - 1] += ops.InterpolateScale(scale_factor=2, mode='nearest')( laterals[i]) outs = [ self.fpn_convs[i](laterals[i]) for i in range(used_backbone_levels) ] if self.num_outs > len(outs): if not self.add_extra_convs: for i in range(self.num_outs - used_backbone_levels): outs.append(ops.MaxPool2d(1, stride=2)(outs[-1])) else: if self.extra_convs_on_inputs: orig = inputs[self.backbone_end_level - 1] outs.append(self.fpn_convs[used_backbone_levels](orig)) else: outs.append(self.fpn_convs[used_backbone_levels](outs[-1])) for i in range(used_backbone_levels + 1, self.num_outs): if self.relu_before_extra_convs: outs.append(self.fpn_convs[i](ops.Relu()(outs[-1]))) else: outs.append(self.fpn_convs[i](outs[-1])) return tuple(outs)
def __init__(self, in_channel, out_channel, upscale, rgb_mean, blocks, candidates, cib_range, method, code, block_range): """Construct the MtMSR class. :param net_desc: config of the searched structure """ super(MtMSR, self).__init__() logging.info("start init MTMSR") current_channel = in_channel layers = list() for i, block_name in enumerate(blocks): if isinstance(block_name, list): layers.append(ChannelIncreaseBlock(block_name, current_channel)) current_channel *= len(block_name) else: if block_name == "res2": layers.append( ResidualBlock(kernel_size=2, base_channel=current_channel)) elif block_name == "res3": layers.append( ResidualBlock(kernel_size=3, base_channel=current_channel)) layers.extend([ conv(current_channel, out_channel * upscale**2), ops.PixelShuffle(upscale) ]) initialize_weights(layers[-2], 0.1) self.sub_mean = ops.MeanShift(1.0, rgb_mean) body = Sequential(*layers) upsample = ops.InterpolateScale(scale_factor=upscale) self.add = Add(body, upsample) self.head = ops.MeanShift(1.0, rgb_mean, sign=1)
def call(self, x, **kwargs): """Forward compute of resnet for detection.""" x = self.conv1(x) x = self.norm1(x) x = self.relu(x) x = self.maxpool(x) if self.parallel_code is None: outs = self.res_layers_seq(x) else: outs = [] subset_lists = [0 for i in range(self.subset_limit)] parallel_numbers = self.parallel_code.split('-') for l, layer in enumerate(self.res_layers): size = x.size()[2:] x = layer(x) x_l_k = x for k in range(int(parallel_numbers[l])): x_l_k = ops.Conv2d(self.channels[l + 1], self.channels[l], kernel_size=1).cuda()(x_l_k) x_l_k = ops.InterpolateScale(size=size, mode='nearest')(x_l_k) x_l_k = layer(subset_lists[k] + x_l_k) subset_lists[k] = x_l_k size = x_l_k.size()[2:] outs.append(x_l_k) return tuple(outs)
def call(self, inputs): """Forward compute. :param inputs: input feature map :return: tuple of feature map """ laterals = [ conv(inputs[i]) for i, conv in enumerate(self.lateral_convs) ] num_stage = len(laterals) for i in range(num_stage - 1, 0, -1): laterals[i - 1] += ops.InterpolateScale( size=laterals[i - 1].size()[2:], mode='nearest')(laterals[i]) outs = [self.fpn_convs[i](laterals[i]) for i in range(num_stage)] outs.append(ops.MaxPool2d(1, stride=2)(outs[-1])) return {idx: out for idx, out in enumerate(outs)}