nazmul-karim170 / UNICON

[CVPR'22] Official Implementation of the CVPR 2022 paper "UNICON: Combating Label Noise Through Uniform Selection and Contrastive Learning"
MIT License
60 stars 14 forks source link

WebVision training bug #11

Open lxysl opened 9 months ago

lxysl commented 9 months ago
Traceback (most recent call last):
  File "/home/lxy/Documents/UNICON-Noisy-Label/Train_webvision.py", line 343, in <module>
    warmup(epoch,net1,optimizer1,warmup_trainloader)    
  File "/home/lxy/Documents/UNICON-Noisy-Label/Train_webvision.py", line 182, in warmup
    loss = CEloss(outputs, labels)   
  File "/opt/miniconda3/envs/pt2/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "/opt/miniconda3/envs/pt2/lib/python3.10/site-packages/torch/nn/modules/loss.py", line 1174, in forward
    return F.cross_entropy(input, target, weight=self.weight,
  File "/opt/miniconda3/envs/pt2/lib/python3.10/site-packages/torch/nn/functional.py", line 3029, in cross_entropy
    return torch._C._nn.cross_entropy_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index, label_smoothing)
RuntimeError: size mismatch (got input: [50], target: [96])

Hello, your Inception model does not return 2 tensors as ResNet, but you take net(inputs)[1] as outputs. The shape of net(inputs) is (96, 50), and that of net(inputs)[1] is (50), so there is an error.

lxysl commented 9 months ago
class InceptionResNetV2(nn.Module):

    def __init__(self, num_classes=1001):
        super(InceptionResNetV2, self).__init__()
        # Special attributs
        self.input_space = None
        self.input_size = (299, 299, 3)
        self.mean = None
        self.std = None
        # Modules
        self.conv2d_1a = BasicConv2d(3, 32, kernel_size=3, stride=2)
        self.conv2d_2a = BasicConv2d(32, 32, kernel_size=3, stride=1)
        self.conv2d_2b = BasicConv2d(32, 64, kernel_size=3, stride=1, padding=1)
        self.maxpool_3a = nn.MaxPool2d(3, stride=2)
        self.conv2d_3b = BasicConv2d(64, 80, kernel_size=1, stride=1)
        self.conv2d_4a = BasicConv2d(80, 192, kernel_size=3, stride=1)
        self.maxpool_5a = nn.MaxPool2d(3, stride=2)
        self.mixed_5b = Mixed_5b()
        self.repeat = nn.Sequential(
            Block35(scale=0.17),
            Block35(scale=0.17),
            Block35(scale=0.17),
            Block35(scale=0.17),
            Block35(scale=0.17),
            Block35(scale=0.17),
            Block35(scale=0.17),
            Block35(scale=0.17),
            Block35(scale=0.17),
            Block35(scale=0.17)
        )
        self.mixed_6a = Mixed_6a()
        self.repeat_1 = nn.Sequential(
            Block17(scale=0.10),
            Block17(scale=0.10),
            Block17(scale=0.10),
            Block17(scale=0.10),
            Block17(scale=0.10),
            Block17(scale=0.10),
            Block17(scale=0.10),
            Block17(scale=0.10),
            Block17(scale=0.10),
            Block17(scale=0.10),
            Block17(scale=0.10),
            Block17(scale=0.10),
            Block17(scale=0.10),
            Block17(scale=0.10),
            Block17(scale=0.10),
            Block17(scale=0.10),
            Block17(scale=0.10),
            Block17(scale=0.10),
            Block17(scale=0.10),
            Block17(scale=0.10)
        )
        self.mixed_7a = Mixed_7a()
        self.repeat_2 = nn.Sequential(
            Block8(scale=0.20),
            Block8(scale=0.20),
            Block8(scale=0.20),
            Block8(scale=0.20),
            Block8(scale=0.20),
            Block8(scale=0.20),
            Block8(scale=0.20),
            Block8(scale=0.20),
            Block8(scale=0.20)
        )
        self.block8 = Block8(noReLU=True)
        self.conv2d_7b = BasicConv2d(2080, 1536, kernel_size=1, stride=1)
        self.avgpool_1a = nn.AvgPool2d(8, count_include_pad=False)
        self.last_linear = nn.Linear(1536, num_classes)
        self.projection_head = nn.Linear(1536, 128)
        self.bnl = nn.BatchNorm1d(128)

    def features(self, input):
        x = self.conv2d_1a(input)
        x = self.conv2d_2a(x)
        x = self.conv2d_2b(x)
        x = self.maxpool_3a(x)
        x = self.conv2d_3b(x)
        x = self.conv2d_4a(x)
        x = self.maxpool_5a(x)
        x = self.mixed_5b(x)
        x = self.repeat(x)
        x = self.mixed_6a(x)
        x = self.repeat_1(x)
        x = self.mixed_7a(x)
        x = self.repeat_2(x)
        x = self.block8(x)
        x = self.conv2d_7b(x)
        return x

    def logits(self, features):
        x = self.last_linear(features)
        return x

    def forward(self, input):
        x = self.features(input)
        x = self.avgpool_1a(x)
        x = x.view(x.size(0), -1)
        x1 = self.bnl(self.projection_head(x))
        x = self.logits(x)
        return x1, x

I revised the Inception model as above, hope it is useful.

nazmul-karim170 commented 9 months ago

Thanks!

On Tue, Feb 27, 2024 at 23:10 lxysl @.***> wrote:

class InceptionResNetV2(nn.Module):

def __init__(self, num_classes=1001):
    super(InceptionResNetV2, self).__init__()
    # Special attributs
    self.input_space = None
    self.input_size = (299, 299, 3)
    self.mean = None
    self.std = None
    # Modules
    self.conv2d_1a = BasicConv2d(3, 32, kernel_size=3, stride=2)
    self.conv2d_2a = BasicConv2d(32, 32, kernel_size=3, stride=1)
    self.conv2d_2b = BasicConv2d(32, 64, kernel_size=3, stride=1, padding=1)
    self.maxpool_3a = nn.MaxPool2d(3, stride=2)
    self.conv2d_3b = BasicConv2d(64, 80, kernel_size=1, stride=1)
    self.conv2d_4a = BasicConv2d(80, 192, kernel_size=3, stride=1)
    self.maxpool_5a = nn.MaxPool2d(3, stride=2)
    self.mixed_5b = Mixed_5b()
    self.repeat = nn.Sequential(
        Block35(scale=0.17),
        Block35(scale=0.17),
        Block35(scale=0.17),
        Block35(scale=0.17),
        Block35(scale=0.17),
        Block35(scale=0.17),
        Block35(scale=0.17),
        Block35(scale=0.17),
        Block35(scale=0.17),
        Block35(scale=0.17)
    )
    self.mixed_6a = Mixed_6a()
    self.repeat_1 = nn.Sequential(
        Block17(scale=0.10),
        Block17(scale=0.10),
        Block17(scale=0.10),
        Block17(scale=0.10),
        Block17(scale=0.10),
        Block17(scale=0.10),
        Block17(scale=0.10),
        Block17(scale=0.10),
        Block17(scale=0.10),
        Block17(scale=0.10),
        Block17(scale=0.10),
        Block17(scale=0.10),
        Block17(scale=0.10),
        Block17(scale=0.10),
        Block17(scale=0.10),
        Block17(scale=0.10),
        Block17(scale=0.10),
        Block17(scale=0.10),
        Block17(scale=0.10),
        Block17(scale=0.10)
    )
    self.mixed_7a = Mixed_7a()
    self.repeat_2 = nn.Sequential(
        Block8(scale=0.20),
        Block8(scale=0.20),
        Block8(scale=0.20),
        Block8(scale=0.20),
        Block8(scale=0.20),
        Block8(scale=0.20),
        Block8(scale=0.20),
        Block8(scale=0.20),
        Block8(scale=0.20)
    )
    self.block8 = Block8(noReLU=True)
    self.conv2d_7b = BasicConv2d(2080, 1536, kernel_size=1, stride=1)
    self.avgpool_1a = nn.AvgPool2d(8, count_include_pad=False)
    self.last_linear = nn.Linear(1536, num_classes)
    self.projection_head = nn.Linear(1536, 128)
    self.bnl = nn.BatchNorm1d(128)

def features(self, input):
    x = self.conv2d_1a(input)
    x = self.conv2d_2a(x)
    x = self.conv2d_2b(x)
    x = self.maxpool_3a(x)
    x = self.conv2d_3b(x)
    x = self.conv2d_4a(x)
    x = self.maxpool_5a(x)
    x = self.mixed_5b(x)
    x = self.repeat(x)
    x = self.mixed_6a(x)
    x = self.repeat_1(x)
    x = self.mixed_7a(x)
    x = self.repeat_2(x)
    x = self.block8(x)
    x = self.conv2d_7b(x)
    return x

def logits(self, features):
    x = self.last_linear(features)
    return x

def forward(self, input):
    x = self.features(input)
    x = self.avgpool_1a(x)
    x = x.view(x.size(0), -1)
    x1 = self.bnl(self.projection_head(x))
    x = self.logits(x)
    return x1, x

I revised the Inception model as above, hope it is useful.

— Reply to this email directly, view it on GitHub https://github.com/nazmul-karim170/UNICON-Noisy-Label/issues/11#issuecomment-1968181420, or unsubscribe https://github.com/notifications/unsubscribe-auth/AF24QPLC3N7D72UVPZQQT3DYV2UZ7AVCNFSM6AAAAABD5IRM6CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNRYGE4DCNBSGA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

lxysl commented 9 months ago

Thanks! On Tue, Feb 27, 2024 at 23:10 lxysl @.> wrote: class InceptionResNetV2(nn.Module): def init(self, num_classes=1001): super(InceptionResNetV2, self).init() # Special attributs self.input_space = None self.input_size = (299, 299, 3) self.mean = None self.std = None # Modules self.conv2d_1a = BasicConv2d(3, 32, kernel_size=3, stride=2) self.conv2d_2a = BasicConv2d(32, 32, kernel_size=3, stride=1) self.conv2d_2b = BasicConv2d(32, 64, kernel_size=3, stride=1, padding=1) self.maxpool_3a = nn.MaxPool2d(3, stride=2) self.conv2d_3b = BasicConv2d(64, 80, kernel_size=1, stride=1) self.conv2d_4a = BasicConv2d(80, 192, kernel_size=3, stride=1) self.maxpool_5a = nn.MaxPool2d(3, stride=2) self.mixed_5b = Mixed_5b() self.repeat = nn.Sequential( Block35(scale=0.17), Block35(scale=0.17), Block35(scale=0.17), Block35(scale=0.17), Block35(scale=0.17), Block35(scale=0.17), Block35(scale=0.17), Block35(scale=0.17), Block35(scale=0.17), Block35(scale=0.17) ) self.mixed_6a = Mixed_6a() self.repeat_1 = nn.Sequential( Block17(scale=0.10), Block17(scale=0.10), Block17(scale=0.10), Block17(scale=0.10), Block17(scale=0.10), Block17(scale=0.10), Block17(scale=0.10), Block17(scale=0.10), Block17(scale=0.10), Block17(scale=0.10), Block17(scale=0.10), Block17(scale=0.10), Block17(scale=0.10), Block17(scale=0.10), Block17(scale=0.10), Block17(scale=0.10), Block17(scale=0.10), Block17(scale=0.10), Block17(scale=0.10), Block17(scale=0.10) ) self.mixed_7a = Mixed_7a() self.repeat_2 = nn.Sequential( Block8(scale=0.20), Block8(scale=0.20), Block8(scale=0.20), Block8(scale=0.20), Block8(scale=0.20), Block8(scale=0.20), Block8(scale=0.20), Block8(scale=0.20), Block8(scale=0.20) ) self.block8 = Block8(noReLU=True) self.conv2d_7b = BasicConv2d(2080, 1536, kernel_size=1, stride=1) self.avgpool_1a = nn.AvgPool2d(8, count_include_pad=False) self.last_linear = nn.Linear(1536, num_classes) self.projection_head = nn.Linear(1536, 128) self.bnl = nn.BatchNorm1d(128) def features(self, input): x = self.conv2d_1a(input) x = self.conv2d_2a(x) x = self.conv2d_2b(x) x = self.maxpool_3a(x) x = self.conv2d_3b(x) x = self.conv2d_4a(x) x = self.maxpool_5a(x) x = self.mixed_5b(x) x = self.repeat(x) x = self.mixed_6a(x) x = self.repeat_1(x) x = self.mixed_7a(x) x = self.repeat_2(x) x = self.block8(x) x = self.conv2d_7b(x) return x def logits(self, features): x = self.last_linear(features) return x def forward(self, input): x = self.features(input) x = self.avgpool_1a(x) x = x.view(x.size(0), -1) x1 = self.bnl(self.projection_head(x)) x = self.logits(x) return x1, x I revised the Inception model as above, hope it is useful. — Reply to this email directly, view it on GitHub <#11 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AF24QPLC3N7D72UVPZQQT3DYV2UZ7AVCNFSM6AAAAABD5IRM6CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNRYGE4DCNBSGA . You are receiving this because you are subscribed to this thread.Message ID: @.>

I am not sure about its correctness, it is just runnable. Does that match your paper?