,这是我试图在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‘的文件夹,其中有所有的脚本,还有其他名为selectors的文件夹,其中有2个脚本init和box_selector
我怎么才能解决这个问题呢?在我得到代码的那篇文章中,我提到了一些关于“相对进口”的内容,但我无法修复,谢谢。
发布于 2018-04-15 03:51:22
你需要用。用于访问文件夹中的文件的符号。
所以
from folder.python_file import ClassOrMethod在你的情况下
from selectors.box_selector import BoxSelector在选择器文件夹中拥有__init__.py是使此工作的关键。
您可以按如下方式访问任意数量的文件夹,但每个文件夹都必须包含一个__init__.py才能工作
from folder.folder1.folder2.python_file import ClassOrMethod发布于 2019-05-01 23:47:43
一个可能的混淆区域是,有一个不同的python库,称为" selectors“,它不同于本代码示例中的选择器。
https://docs.python.org/3/library/selectors.html
最后,我将此示例的“选择器”(包括目录)重命名为"boxselectors“。
这个例子来自http://www.hackevolve.com/create-your-own-object-detector/
https://stackoverflow.com/questions/49838068
复制相似问题