-1

I have this class of NN:

class Block(nn.Module):
    def __init__(self, in_planes, out_planes, stride=1):
        super(Block, self).__init__()
        self.conv1 = nn.Conv2d(in_planes, in_planes, kernel_size=3, stride=stride,
             padding=1, groups=in_planes, bias=False)
        self.bn1 = nn.BatchNorm2d(in_planes)
  
    def forward(self, x):
        out = self.conv1(x)
        out = self.bn1(out)
        out = nn.ReLU(out)
        return out

I create a model and pass it the random input, and it shows the error:

model = Block(3,3, 1)
x = torch.rand(64, 3, 100, 100)
model(x)

I received this error: RuntimeError: Boolean value of Tensor with more than one value is ambiguous

  • 1
    Can you provide the whole error backtrace? It seems you haven't give the part of your code which is leading to that error. – Ivan May 27 '22 at 14:54
  • The issue with the code is that I cannot use the nn.ReLU in the feedforward, I need to define it in the __init()__ or I should use the relu function from import torch.nn.functional. – Muhammad Muneeb Ur Rahman May 27 '22 at 15:13

1 Answers1

1

The issue is with the nn.ReLU() in the feedforward(). I was printing it which is not possible in ipynb file.

class Block(nn.Module):

    def __init__(self, in_planes, out_planes, stride=1):
        super(Block, self).__init__()
        self.conv1 = nn.Conv2d(in_planes, in_planes, kernel_size=3, stride=stride,
             padding=1, groups=in_planes, bias=False)
        self.bn1 = nn.BatchNorm2d(in_planes)
        self.relu = nn.ReLU()

    def forward(self, x):
        out = self.conv1(x)
        out = self.bn1(out)
        out = self.relu(out)
        return out
Benjamin Breton
  • 1,388
  • 1
  • 13
  • 42