Search code examples
pythonclassooppytorchsuper

different between class name vs self calling in super()


isn't it same meaning of class name NeuralNet and self keyword passing in super call -
super(NeuralNet,self).__init__() # init super

here is the code snippet from example:

class NeuralNet(nn.Module):
    def __init__(self, use_batch_norm, input_size=784, hidden_dim=256, output_size=10):
        """
        Creates a PyTorch net using the given parameters.
        """
        super(NeuralNet, self).__init__() # init super
        # continues code

Solution

  • Given your question, I kindly but very strongly suggest you do the full official Python tutorial.

    And no, NeuralNet and self are NOT the same thing. The first is the NeuralNet class, the second is the current NeuralNet instance ("current": the one on which the method has been called).