An error occurred when I try to initialize a member of the subclass of nn.Module

Hi ,everyone. After I initialized the following class, no attribute can be found in the initialized member, let alone the subsequent training process. However, if I erase the nn.Module, not setting the InceptionTime as a subclass of nn.Module, the initialized member contain all the attributes as designed. I am curious about the phenomenon. Excuse me for my somewhat naive question.

class InceptionTime(nn.Module):

def __init__(self, input_channel, num_class,

    # Build and save the models.
    self.the_models = [
            input_size= input_channel,
            num_classes= num_class,
        ) for _ in range(models)
    self.length_before_classification = 4 * filters

Hi Hann!

You need to explicitly initialize the superclass, Module, as well as the class
itself, InceptionTime.

Add super().__init__() to InceptionTime’s __init__() method. Doing
so will call the superclass’s (Module’s) __init__() method (with no explicit

(Unlike some other languages, python does not automatically initialize a
class’s superclass, even with the superclass’s “default constructor.”)


K. Frank

1 Like

Thank you very much, I thought it was a compiler, python version, pytorch version, or deployment issue, but now I feel so stupid that I am embarrassed to read this question again. :face_exhaling: