wujiyang / Face_Pytorch

face recognition algorithms in pytorch framework, including arcface, cosface, sphereface and so on
Apache License 2.0
807 stars 156 forks source link

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

Open satakiolo opened 5 years ago

satakiolo commented 5 years ago
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个样本,不知道怎么解决,如果您知道的话麻烦告诉我一下

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

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

satakiolo commented 5 years ago

好的,谢谢你们