如何在python中修复布尔对象错误?

问题描述 投票:-2回答:1
The error that i get while running the program for **Object Detection finetuning**..
Any one if know the solution for this, kindly help me out. More thankful to you..

File "<ipython-input-113-72bac7bde4d7>", line 41, in __getitem__
    pos = np.where(masks[i])

TypeError: 'bool' object is not subscriptable


 # This where there the problem comes

其中蒙版包含图片的坐标值... for i in range(num_objs): pos = np.where(masks[i]) xmin = np.min(pos[1]) xmax = np.max(pos[1]) ymin = np.min(pos[0]) ymax = np.max(pos[0]) boxes.append([xmin, ymin, xmax, ymax])

实际上我不知道如何清除此错误

python-3.x machine-learning pytorch object-detection object-detection-api
1个回答
0
投票

请执行:

print(type(num_objs))
for i in range(num_objs):
    print(type(masks), type(pos))
    pos = np.where(masks[i])
    xmin = np.min(pos[1])
    xmax = np.max(pos[1])
    ymin = np.min(pos[0])
    ymax = np.max(pos[0])
    boxes.append([xmin, ymin, xmax, ymax])

之所以会发生此错误,是因为某些布尔变量的特征是数组。也许要进行初始化,或者使用[index]访问变量。

© www.soinside.com 2019 - 2024. All rights reserved.