gpt4 book ai didi

python - 找不到模块错误(imutils.paths)

转载 作者:行者123 更新时间:2023-12-01 09:32:33 26 4
gpt4 key购买 nike

这是我尝试在 python3.6 的虚拟环境中运行的代码。我使用 ubuntu 最新版本 17.10,我将代码运行为 python3 Gather_annotations.py

import numpy as np  
import cv2
import argparse
from imutils.paths import list_images
from selectors import BoxSelector
#parse arguments
ap = argparse.ArgumentParser()
ap.add_argument("-d","--dataset",required=True,help="path to images dataset...")
ap.add_argument("-a","--annotations",required=True,help="path to save annotations...")
ap.add_argument("-i","--images",required=True,help="path to save images")
args = vars(ap.parse_args())
#annotations and image paths
annotations = []
imPaths = []
#loop through each image and collect annotations
for imagePath in list_images(args["dataset"]):
#load image and create a BoxSelector instance
image = cv2.imread(imagePath)
bs = BoxSelector(image,"Image")
cv2.imshow("Image",image)
cv2.waitKey(0)
#order the points suitable for the Object detector
pt1,pt2 = bs.roiPts
(x,y,xb,yb) = [pt1[0],pt1[1],pt2[0],pt2[1]]
annotations.append([int(x),int(y),int(xb),int(yb)])
imPaths.append(imagePath)
#save annotations and image paths to disk
annotations = np.array(annotations)
imPaths = np.array(imPaths,dtype="unicode")
np.save(args["annotations"],annotations)
np.save(args["images"],imPaths)

And I get the following errors

我有一个名为“2”的文件夹,其中包含所有脚本和其他名为选择器的文件夹,其中有 2 个脚本 init 和 box_selector

  • 2(文件夹)

  • ----选择器/

  • ------------_ init _.py
  • ------------box_selector.py
  • ----探测器.py
  • ----gather_annotations.py
  • ----测试.py
  • ----train.py

我该如何解决这个问题,在我获取代码的帖子中提到了有关“相对导入”的内容,但我无法修复它,谢谢。

最佳答案

您需要使用 .访问文件夹内文件的符号..

所以

from folder.python_file import ClassOrMethod

就你的情况

from selectors.box_selector import BoxSelector

选择器文件夹中包含__init__.py对于完成这项工作至关重要。

您可以设置任意数量的文件夹,并且可以按如下方式访问,但每个文件夹必须包含 __init__.py 才能工作

from folder.folder1.folder2.python_file import ClassOrMethod

关于python - 找不到模块错误(imutils.paths),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49838068/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com