AttributeError: 'ReLU' object has no attribute 'dim'
I am building a GAN, and my discriminator function is defined as
class Discriminator(nn.Module):
def __init__(self):
    super(Discriminator, self).__init__()
    
    self.fc1 = nn.Linear(50*15, 32)
    self.fc2 = nn.Linear(32, 32)
    self.fc3 = nn.Linear(32, 1)

def forward(self, x):
    x = x.flatten()
    x = torch.nn.ReLU(self.fc1(x))
    x = torch.nn.ReLU(self.fc2(x))

    return torch.nn.Sigmoid(self.fc3(x))

When I was testing the code, I got an error with the following command
discriminator(gen_series)

where gen_series is a tensor with the dimension 15*50. The error occurs as
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
&lt;ipython-input-99-fa68eff35865&gt; in &lt;module&gt;
     16 valid = Variable(Tensor(piece, time).fill_(1.0), requires_grad=False)
     17 print(gen_series)
---&gt; 18 discriminator(gen_series)
     19 # g_loss = adversarial_loss(discriminator(gen_series), valid)

/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
    539             result = self._slow_forward(*input, **kwargs)
    540         else:
--&gt; 541             result = self.forward(*input, **kwargs)
    542         for hook in self._forward_hooks.values():
    543             hook_result = hook(self, input, result)

&lt;ipython-input-94-7c6c59da67f9&gt; in forward(self, x)
     27         x = x.flatten()
     28         x = torch.nn.ReLU(self.fc1(x))
---&gt; 29         x = torch.nn.ReLU(self.fc2(x))
     30 
     31         return torch.nn.Sigmoid(self.fc3(x))

/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
    539             result = self._slow_forward(*input, **kwargs)
    540         else:
--&gt; 541             result = self.forward(*input, **kwargs)
    542         for hook in self._forward_hooks.values():
    543             hook_result = hook(self, input, result)

/usr/local/lib/python3.7/dist-packages/torch/nn/modules/linear.py in forward(self, input)
     85 
     86     def forward(self, input):
---&gt; 87         return F.linear(input, self.weight, self.bias)
     88 
     89     def extra_repr(self):

/usr/local/lib/python3.7/dist-packages/torch/nn/functional.py in linear(input, weight, bias)
   1366         - Output: :math:`(N, *, out\_features)`
   1367     &quot;&quot;&quot;
-&gt; 1368     if input.dim() == 2 and bias is not None:
   1369         # fused op is marginally faster
   1370         ret = torch.addmm(bias, input, weight.t())

/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py in __getattr__(self, name)
    583                 return modules[name]
    584         raise AttributeError(&quot;'{}' object has no attribute '{}'&quot;.format(
--&gt; 585             type(self).__name__, name))
    586 
    587     def __setattr__(self, name, value):

AttributeError: 'ReLU' object has no attribute 'dim'

I didn't find any related questions. Any help is appreciated!!

You can use this code and I think it would work well
class Discriminator(nn.Module):
    def __init__(self):
        super(Discriminator, self).__init__()

        self.fc = nn.Sequential(
                  nn.Linear(50 * 15, 32),
                  nn.ReLU(),
                  nn.Linear(32, 32),
                  nn.ReLU(),
                  nn.Linear(32, 1),
                  nn.Sigmoid()
        )


    def forward(self, x):
        x = x.flatten()
        x = self.fc(x)

        return x


