Print shape of a tensor

I am a beginner in pytorch. I have the following neural network
class FirstNN(nn.Module):
def init(self):
self.fc1 = nn.Linear(784,hidden_size)
self.act1 = nn.ReLU()
self.fc2 = nn.Linear(hidden_size,num_classes)

def forward(self,x):
    out = self.fc1(x)
    out = self.act1(out)
    out = self.fc2(out)
    return out

model = FirstNN()

I wanted to know the shape of tensor after fc1. When I tried using print function it doesn’t print anything.How can I know the shape of tensor??

Did you pass a random sample through your model?

x = torch.randn(1, 784)
model = FirstNN()
out = model(x)

No I haven’t. It’s working now. Thanks a lot.

@avinash_m How did you print shape of tensor after fc1?

The print statement is inside the ‘forward’ function. However, you need to call the function to see the result. You call the function as given above:

x = torch.randn(1, 784)
model = FirstNN()
out = model(x) #This makes a call to forward