Pytorch Question from 'Deep Reinforcement Learning: Hands-On'
I'm reading Maxim Lapan's Deep Learning Hands On. I came across this code in chapter 2 and I don't understand a few things. Could anybody explain why the output of print(out) gives three parameters instead of the single float tensor we put in. Also, why is the super function necessary here? Finally, what is the x parameter that forward is accepting? Thank you.

class OurModule(nn.Module):
    def __init__(self, num_inputs, num_classes, dropout_prob=0.3):  #init 
        super(OurModule, self).__init__() #Call OurModule and pass the net instance (Why is this necessary?) 
        self.pipe = nn.Sequential( #net.pipe is the nn object now
            nn.Linear(num_inputs, 5),
            nn.ReLU(),
            nn.Linear(5, 20),
            nn.ReLU(),
            nn.Linear(20, num_classes),
            nn.Dropout(p=dropout_prob),
            nn.Softmax(dim=1)
        )

    def forward(self, x): #override the default forward method by passing it our net instance and (return the nn object?). x is the tensor? This is called when 'net' receives a param?
        return self.pipe(x)

if __name__ == "__main__":
    net = OurModule(num_inputs=2, num_classes=3)
    print(net)
    v = torch.FloatTensor([[2, 3]])
    out = net(v)
    print(out) #[2,3] put through the forward method of the nn? Why did we get a third param for the output?
    print("Cuda's availability is %s" % torch.cuda.is_available()) #find if gpu is available
    if torch.cuda.is_available():
        print("Data from cuda: %s" % out.to('cuda'))

OurModule.__mro__


OurModule defined a PyTorch nn.Module that accepts 2 inputs (num_inputs) and produces 3 outputs (num_classes).

It consists of:


A Linear layers that accepts 2 inputs and produces 5 outputs
A ReLU
A Linear layer that accepts 5 inputs and produces 20 outputs
A ReLU
A Linear layer that accepts 20 inputs and produces 3 (num_classes) outputs
A Dropout layer
A Softmax layer


You create v which consists of 2 inputs and pass it through this network's forward() method when you call net(v). The result of running this network (3 outputs) is then stored in out.

In your example, x takes on the value of v, torch.FloatTensor([[2, 3]])
