TypeError: __init__() missing 1 required positional argument: 'out_features'
时间: 2023-11-08 08:06:09 浏览: 101
This error message is indicating that when you are initializing an object of a certain class, you are missing one positional argument that is required by the class constructor.
For example, if you are trying to initialize an object of the `nn.Linear` class in PyTorch, you need to provide the number of output features as a positional argument. If you forget to provide this argument, you will get the `TypeError: __init__() missing 1 required positional argument: 'out_features'` error.
Here is an example code snippet that would cause this error:
```
import torch.nn as nn
linear_layer = nn.Linear(10) # missing 'out_features' argument
```
To fix this error, you need to provide the missing argument in the initialization call:
```
import torch.nn as nn
linear_layer = nn.Linear(10, 5) # provide 'out_features' argument
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)