Face_Pytorch icon indicating copy to clipboard operation
Face_Pytorch copied to clipboard

您好,再请教一个arcfacenet的SEresnet的问题

Open satakiolo opened this issue 5 years ago • 3 comments

class SEResNet_IR(nn.Module):
    def __init__(self, num_layers, feature_dim=512, drop_ratio=0.4, mode = 'ir'):
        super(SEResNet_IR, self).__init__()
        assert num_layers in [50, 100, 152], 'num_layers should be 50, 100 or 152'
        assert mode in ['ir', 'se_ir'], 'mode should be ir or se_ir'
        blocks = get_blocks(num_layers)
        if mode == 'ir':
            unit_module = BottleNeck_IR
        elif mode == 'se_ir':
            unit_module = BottleNeck_IR_SE
        self.input_layer = nn.Sequential(nn.Conv2d(3, 64, (3, 3), 1, 1, bias=False),
                                         nn.BatchNorm2d(64),
                                         nn.PReLU(64))

        self.output_layer = nn.Sequential(nn.BatchNorm2d(512),
                                          nn.Dropout(drop_ratio),
                                          Flatten(),
                                          nn.Linear(512 * 7 * 7, feature_dim),
                                          nn.BatchNorm1d(feature_dim))

您默认的是选择resnet100的,那如果我使用50以及152,需要修改 nn.Linear(512 * 7 * 7, feature_dim)吗?或者arcfacenet这个脚本需要修改吗?

我训练到4400次时出现了个问题 ValueError: Expected more than 1 value per channel when training, got input size [1, 512],百度之后是说我batchsize存在1个样本,可是我计算了没有出现1个样本,不知道怎么解决,如果您知道的话麻烦告诉我一下

satakiolo avatar Jan 16 '19 10:01 satakiolo

  1. 不需要:无论是50,100还是152,最后一个卷积的feature map 大小都是7x7(针对112x112的输入)。
  2. 报这个错误的问题就是batch size为1导致的,你最好再仔细检查一下吧。

wujiyang avatar Jan 16 '19 15:01 wujiyang

You could try to use drop_last=true to avoid this situation

MccreeZhao avatar Jan 18 '19 05:01 MccreeZhao

好的,谢谢你们

satakiolo avatar Jan 21 '19 02:01 satakiolo