HRNet-Image-Classification icon indicating copy to clipboard operation
HRNet-Image-Classification copied to clipboard

A solution: HRNet Backbone Adopt_different_blocks_bug(BASIC//BOTTLENECK)

Open Taylor-X76 opened this issue 5 years ago • 2 comments

https://github.com/HRNet/HRNet-Image-Classification/blob/8f158719e821836e21e6cba99a3241a12a13bc41/lib/models/cls_hrnet.py#L459~L473 If different block types are used in different stages, instead of the default bottleneck-basic-basic-basic in the original yaml file, the channel mismatch error as shown in the figure below will appear. To avoid this error, we change it in the transition layer and use conv3*3 between different stages to match the number of channels. The corrected code and results are shown in the figure below. (The demonstration is only a proof of feasibility, not an actual demonstration of the code)

Taylor-X76 avatar Sep 01 '20 07:09 Taylor-X76

HRNet_v2不同block_yaml文件 HRNet_v2不同block_bug HRNet_v2不同block_改正 HRNet_v2不同block_bug代码更改

Taylor-X76 avatar Sep 01 '20 07:09 Taylor-X76

`# ############################# Modified by Mingyang ##############################################################

##################### Adopt_different_blocks_bug(BASIC//BOTTLENECK)

    # x_list = []
    # for i in range(self.stage3_cfg['NUM_BRANCHES']):
    #     if self.transition2[i] is not None:
    #         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:
    #         x_list.append(self.transition3[i](y_list[-1]))
    #     else:
    #         x_list.append(y_list[i])
    # y_list = self.stage4(x_list)

    x_list = []
    for i in range(self.stage3_cfg['NUM_BRANCHES']):  # 3
        if self.transition2[i] is not None and i < self.stage2_cfg['NUM_BRANCHES']:  # 有通道数匹配卷积且处于平连阶段
            x_list.append(self.transition2[i](y_list[i]))   # #################bug
        elif self.transition2[i] is not None and i >= self.stage2_cfg['NUM_BRANCHES']:  # 下采样阶段
            x_list.append(self.transition2[i](y_list[-1]))  # #################bug
        else:                                      # ############应改为
            x_list.append(y_list[i])
    y_list = self.stage3(x_list)

    x_list = []
    for i in range(self.stage4_cfg['NUM_BRANCHES']): # 4
        if self.transition3[i] is not None and i < self.stage3_cfg['NUM_BRANCHES']:  # 有通道数匹配卷积且处于平连阶段:
            x_list.append(self.transition3[i](y_list[i]))   # #################bug
        elif self.transition3[i] is not None and i >= self.stage3_cfg['NUM_BRANCHES']:  # 下采样阶段
            x_list.append(self.transition3[i](y_list[-1]))  # #################bug
        else:
            x_list.append(y_list[i])
    y_list = self.stage4(x_list)  # stage4中的multi_scale_output不是False,所以产生[fuse_x0,fuse_x1,fuse_x2,fuse_x3]

############################# Adopt_different_blocks_bug(BASIC//BOTTLENECK) #############################################`

Taylor-X76 avatar Sep 01 '20 07:09 Taylor-X76