def forward(self, inputs): x = inputs['image'] conv1 = self.conv_layer1_1(x) conv2 = self.conv_layer1_2(conv1) la1 = self.la1(conv2) tr1 = self.tr1([la1]) st2 = self.st2(tr1) tr2 = self.tr2(st2) st3 = self.st3(tr2) tr3 = self.tr3(st3) st4 = self.st4(tr3) if self.upsample: # Upsampling x0_h, x0_w = st4[0].shape[2:4] x1 = F.upsample(st4[1], size=(x0_h, x0_w), mode='bilinear') x2 = F.upsample(st4[2], size=(x0_h, x0_w), mode='bilinear') x3 = F.upsample(st4[3], size=(x0_h, x0_w), mode='bilinear') x = paddle.concat([st4[0], x1, x2, x3], 1) return x res = [] for i, layer in enumerate(st4): if i == self.freeze_at: layer.stop_gradient = True if i in self.return_idx: res.append(layer) return res
def forward(self, x): x = self.conv1(x) x = self.bn1(x) x = self.relu(x) x = self.conv2(x) x = self.bn2(x) x = self.relu(x) x = self.layer1(x) x_list = [] for i in range(self.stage2_cfg['NUM_BRANCHES']): # if self.transition1[i] is not None: if self.transition1[i] is not equalmap: x_list.append(self.transition1[i](x)) else: x_list.append(x) y_list = self.stage2(x_list) x_list = [] for i in range(self.stage3_cfg['NUM_BRANCHES']): # if self.transition2[i] is not None: if self.transition2[i] is not equalmap: if i < self.stage2_cfg['NUM_BRANCHES']: x_list.append(self.transition2[i](y_list[i])) else: x_list.append(self.transition2[i](y_list[-1])) else: x_list.append(y_list[i]) y_list = self.stage3(x_list) x_list = [] for i in range(self.stage4_cfg['NUM_BRANCHES']): # if self.transition3[i] is not None: if self.transition3[i] is not equalmap: if i < self.stage3_cfg['NUM_BRANCHES']: x_list.append(self.transition3[i](y_list[i])) else: x_list.append(self.transition3[i](y_list[-1])) else: x_list.append(y_list[i]) x = self.stage4(x_list) # Upsampling # x0_h, x0_w = x[0].size(2), x[0].size(3) x0_h, x0_w = x[0].shape[2], x[0].shape[3] x1 = F.upsample(x[1], size=(x0_h, x0_w), mode='bilinear') x2 = F.upsample(x[2], size=(x0_h, x0_w), mode='bilinear') x3 = F.upsample(x[3], size=(x0_h, x0_w), mode='bilinear') # x = torch.cat([x[0], x1, x2, x3], 1) x = paddle.concat([x[0], x1, x2, x3], 1) z = {} for head in self.heads: z[head] = self.__getattr__(head)(x) return [z]
def forward(self, img_id, img_shape, inputs): outputs = [] boxes = [] scores = [] downsample = 32 feats = self.backbone(inputs) route = None for idx, feat in enumerate(feats[::-1]): if idx > 0: feat = paddle.concat(x=[route, feat], axis=1) route, tip = self.yolo_blocks[idx](feat) block_out = self.block_outputs[idx](tip) outputs.append(block_out) if idx < 2: route = self.route_blocks[idx](route) route = F.upsample(route, scale_factor=2) if self.model_mode != 'train': anchor_mask = self.anchor_masks[idx] mask_anchors = [] for m in anchor_mask: mask_anchors.append(self.anchors[2 * m]) mask_anchors.append(self.anchors[2 * m + 1]) b, s = paddle.fluid.layers.yolo_box( x=block_out, img_size=img_shape, anchors=mask_anchors, class_num=self.num_classes, conf_thresh=self.valid_thresh, downsample_ratio=downsample) boxes.append(b) scores.append(paddle.transpose(s, perm=[0, 2, 1])) downsample //= 2 if self.model_mode == 'train': return outputs preds = [ img_id, paddle.fluid.layers.multiclass_nms( bboxes=paddle.concat( boxes, axis=1), scores=paddle.concat( scores, axis=2), score_threshold=self.valid_thresh, nms_top_k=self.nms_topk, keep_top_k=self.nms_posk, nms_threshold=self.nms_thresh, background_label=-1) ] if self.model_mode == 'test': return preds # model_mode == "eval" return outputs + preds
def forward(self, input): output1 = self.conv1_fpn(input[0]) output2 = self.conv2_fpn(input[1]) up2 = F.upsample( output2, size=paddle.shape(output1)[-2:], mode='nearest') output1 = paddle.add(output1, up2) output1 = self.conv3_fpn(output1) return output1, output2
def forward(self, x): c2, c3, c4, c5 = x in5 = self.in5_conv(c5) in4 = self.in4_conv(c4) in3 = self.in3_conv(c3) in2 = self.in2_conv(c2) out4 = in4 + F.upsample( in5, size=in4.shape[2:4], mode="nearest", align_mode=1) # 1/16 out3 = in3 + F.upsample( out4, size=in3.shape[2:4], mode="nearest", align_mode=1) # 1/8 out2 = in2 + F.upsample( out3, size=in2.shape[2:4], mode="nearest", align_mode=1) # 1/4 p4 = F.upsample(out4, size=in5.shape[2:4], mode="nearest", align_mode=1) p3 = F.upsample(out3, size=in5.shape[2:4], mode="nearest", align_mode=1) p2 = F.upsample(out2, size=in5.shape[2:4], mode="nearest", align_mode=1) fuse = paddle.concat([in5, p4, p3, p2], axis=1) fuse_conv = self.fuse_conv(fuse) * 0.005 return [c5 + fuse_conv]
def forward(self, x): c2, c3, c4, c5 = x in5 = self.in5_conv(c5) in4 = self.in4_conv(c4) in3 = self.in3_conv(c3) in2 = self.in2_conv(c2) out4 = in4 + F.upsample( in5, scale_factor=2, mode="nearest", align_mode=1) # 1/16 out3 = in3 + F.upsample( out4, scale_factor=2, mode="nearest", align_mode=1) # 1/8 out2 = in2 + F.upsample( out3, scale_factor=2, mode="nearest", align_mode=1) # 1/4 p5 = self.p5_conv(in5) p4 = self.p4_conv(out4) p3 = self.p3_conv(out3) p2 = self.p2_conv(out2) p5 = F.upsample(p5, scale_factor=8, mode="nearest", align_mode=1) p4 = F.upsample(p4, scale_factor=4, mode="nearest", align_mode=1) p3 = F.upsample(p3, scale_factor=2, mode="nearest", align_mode=1) fuse = paddle.concat([p5, p4, p3, p2], axis=1) return fuse
def forward(self, x): skips = [] for i in range(self.n_skip): skips.append(getattr(self, 'ConvBlockskip' + str(i + 1))(x)) x = F.avg_pool2d(x, 2) x = getattr(self, 'ConvBlock' + str(i + 1))(x) x = self.ConvBlock5(x) for i in range(self.n_skip): x = getattr(self, 'ConvBlock' + str(i + 6))(x) x = F.upsample(x, scale_factor=2) x = skips[self.n_skip - i - 1] + x return x
def forward(self, x, res_dict=None): out = [] residual_func_idx = 0 for i in range(len(self._in_channels)): residual = x[i] for j in range(len(self._in_channels)): if j > i: xj = self.residual_func_list[residual_func_idx](x[j]) residual_func_idx += 1 xj = upsample(xj, scale_factor=2**(j - i), mode="nearest") residual = paddle.add(x=residual, y=xj) elif j < i: xj = x[j] for k in range(i - j): xj = self.residual_func_list[residual_func_idx](xj) residual_func_idx += 1 residual = paddle.add(x=residual, y=xj) residual = self.relu(residual) out.append(residual) return out
def forward(self, input): outs = [] residual_func_idx = 0 for i in range(self._actual_ch): residual = input[i] for j in range(len(self._in_channels)): if j > i: y = self.residual_func_list[residual_func_idx](input[j]) residual_func_idx += 1 y = F.upsample(y, scale_factor=2**(j - i), mode="nearest") residual = paddle.add(x=residual, y=y) elif j < i: y = input[j] for k in range(i - j): y = self.residual_func_list[residual_func_idx](y) residual_func_idx += 1 residual = paddle.add(x=residual, y=y) residual = F.relu(residual) outs.append(residual) return outs
def _upsample_like(src, tar): src = F.upsample(src, size=tar.shape[2:], mode='bilinear') return src
def _upsample_add(self, x, y): _, _, H, W = y.shape return F.upsample(x, size=(H, W), mode='bilinear') + y
def _upsample(self, x, y, scale=1): _, _, H, W = y.shape return F.upsample(x, size=(H // scale, W // scale), mode='bilinear')
def _upsample_add(self, x, y, scale=1): return F.upsample(x, scale_factor=scale, mode='bilinear') + y
def _upsample_like(src, tar): src = F.upsample(src, size=paddle.shape(tar)[2:], mode='bilinear') return src