[英]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'
Your function main
takes in the argument self
, but in your execution, main()
, you do not pass in any arguments.您的函数main
接受参数self
,但在您的执行中, main()
,您不传入任何参数。
First, self
is used in object oriented programming, when you have a class with attributes and methods.首先,当你有一个带有属性和方法的类时, self
用于面向对象的编程。 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?此外,您似乎根本没有在函数中使用self
,那么为什么要将它作为参数呢?
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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.