python代码 h, w = current_frame.shape 4 motion_field = np.empty((2, (h // block_size + 1), (w // block_size + 1)), dtype=np.int16) 5 AttributeError: 'NoneType' object has no attribute 'shape'
时间: 2024-04-12 18:33:56 浏览: 19
这个错误提示表明 `current_frame` 是一个 NoneType 对象,没有 `shape` 属性。这意味着 `current_frame` 并没有被正确地赋值或者是赋值为了 None。
要解决这个问题,你需要确保在执行 `current_frame.shape` 前,`current_frame` 已经被正确地初始化并且赋值为一个具有 `shape` 属性的对象。你可以检查一下 `current_frame` 的赋值过程,确保它被正确地赋值为一个图像帧。另外,还要确保你没有在赋值过程中将其设置为 None。
相关问题
H, W = vis_img.shape ValueError: too many values to unpack (expected 2)
这个错误提示是由于你尝试在一行代码中使用了太多的值来进行解包赋值。"vis_img.shape"返回一个元组,它包含了图像的高度和宽度两个值。在你的代码中,你需要确保你的变量数量与元组中的元素数量相匹配。
例如,如果你只想获取图像的宽度,你可以这样写:
```python
W = vis_img.shape[1]
```
或者如果你想同时获取图像的宽度和高度,你可以这样写:
```python
H, W = vis_img.shape[:2]
```
这样,H将会被赋值为图像的高度,W将会被赋值为图像的宽度。请根据你的实际需求进行修正。
train_size = X_train.shape[0] AttributeError: 'list' object has no attribute 'shape'
这个错误是由于你的变量 `X_train` 是列表而不是一个致的。在使用shape` 属性之前,需要将列表转为数组。你可以使用 `np.array()` 函数将列表转换为数组形式,然后再计算 `train_size`,像这:
```python
import numpy as
X_train = np.array(X_traintrain_size = X_train.shape[0]
`
这样就能够正确计算 `train_size` 的值了。
相关推荐
![h](https://img-home.csdnimg.cn/images/20210720083646.png)
![rpm](https://img-home.csdnimg.cn/images/20210720083646.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_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)