Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
173 views
in Technique[技术] by (71.8m points)

python - TypeError: main() missing 1 required positional argument: 'self'

My code and error is below and I was trying to understand why I am getting the error and how to fix it. I tried this without self and got another error

TypeError: load_data() takes 0 positional arguments but 1 was given. 
def main(self):

    training_loader, validation_loader, testing_loader = Utilities3.load_data(data)
    model, optimizer, criterion = Utilities3.network_construct(structure, drop, hidden_layer, learningrate, device)
    Utilities3.do_deep_learning(model, optimizer, criterion, epochs, 40, training_loader, device)
    Utilities3.save_checkpoint(model, path, structure, hidden_layer, drop, learningrate)
    print("Training is finish")


if __name__== "__main__":
    main()
TypeError                                 Traceback (most recent call last)
<ipython-input-25-77e46aea71ac> in <module>()
     49 
     50 if __name__== "__main__":
---> 51     main()

TypeError: main() missing 1 required positional argument: 'self'
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Your function main takes in the argument self, but in your execution, main(), you do not pass in any arguments.

First, self is used in object oriented programming, when you have a class with attributes and methods. But that is not what you have here. Moreover, you don't seem to be using self at all in the function, so why do you have it as an argument?

Do this instead:


def main():

    training_loader, validation_loader, testing_loader = Utilities3.load_data(data)
    model, optimizer, criterion = Utilities3.network_construct(structure, drop, hidden_layer, learningrate, device)
    Utilities3.do_deep_learning(model, optimizer, criterion, epochs, 40, training_loader, device)
    Utilities3.save_checkpoint(model, path, structure, hidden_layer, drop, learningrate)
    print("Training is finish")


if __name__== "__main__":
    main()


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...