bs_mean = bsize.view(-1, 3, 2).float().mean(dim=1) RuntimeError: shape '[-1, 3, 2]' is invalid for input of size 16
时间: 2024-04-29 11:25:52 浏览: 19
The error message suggests that the input tensor `bsize` has a size of 16, which is not compatible with the requested shape of `[-1, 3, 2]`.
The shape `[-1, 3, 2]` means that the first dimension can be of any size (indicated by `-1`), the second dimension should have size 3, and the third dimension should have size 2. This shape is often used to represent batches of 3D points, where each point has two coordinates.
To fix the error, you need to make sure that `bsize` has a compatible size. One way to do this is to reshape the tensor to have a total size of 16:
```
bsize = torch.randn(16)
bs_mean = bsize.view(8, 2).float().mean(dim=1)
```
This reshapes the tensor to have a shape of `[8, 2]`, which is compatible with the requested shape of `[-1, 3, 2]` when the first dimension is set to 5.
Alternatively, you could adjust the shape of `bsize` to match the requested shape:
```
bsize = torch.randn(5, 3, 2)
bs_mean = bsize.float().mean(dim=1)
```
This computes the mean along the second dimension, which has size 3, resulting in a tensor of shape `[5, 2]`.
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://img-home.csdnimg.cn/images/20210720083646.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)