首页 > 解决方案 > 图像和标签循环中的错误值不明确,python

问题描述

我成功上传了图片和标签(csv)。

for name, labels in df.values:
  print(name)
  imgs = read_given_images("./",name)
  labels = df['labels']
  points = np.array(labels)

我想调整图像大小(标签也会更新)。然后我想把它改成tfrecord。在单个图像上,下面的代码可以正确运行,但是当我在组上运行它时会出错

for img, img_points in zip(imgs,points):
  img_points = img_points.reshape(-1,2)
  visualize_points(img[...,::-1],img_points,radius=3,thickness=3)
  new_img, new_points = resize_with_aspect_ratio(img,224,img_points.flatten())
  new_points = new_points.reshape(-1,2)
  visualize_points(new_img[...,::-1].astype(np.uint8),new_points,radius=2,thickness=2)

错误;

The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

我必须在哪里插入 a.any() 或 a.all() 才能解决此错误?

标签: pythonfor-loopimage-resizingerror-messaging

解决方案


imgs = read_given_images("/content/images2",df.names.values)
points = df['labels'].values
points = np.array(points)

错误在 zip 中,我导入了 zipfile。这是我不应该的。python是内置的这个功能。谢谢。


推荐阅读