__init__() takes 1 positional argument but 2 were given
时间: 2023-10-16 18:59:44 浏览: 229
问题的报错信息是"__init__() takes 1 positional argument but 2 were given",这个错误通常是由于在实例化类时传递了多余的参数导致的。根据引用\[1\]中的解决方法,你可以尝试在迭代训练之前实例化网络。在你的代码中,你可以添加以下代码来实例化网络:
```
net = Cnn()
```
这样就可以解决这个报错了。如果其他方法不起作用,你可以尝试这个方法。希望能帮到你!\[1\]
#### 引用[.reference_title]
- *1* [Pytorch报错TypeError : __init__() takes 1 positional argument but 2 were given 原因及解决方法](https://blog.csdn.net/weixin_40911578/article/details/125514556)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [TypeError: __init__() takes 1 positional argument but 2 were given](https://blog.csdn.net/weixin_44025103/article/details/126806468)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文