【发布时间】:2021-04-28 13:35:02
【问题描述】:
关于我的项目 我正在尝试在 pycharm MacOS 上使用 python 和 tensorflow 训练图像以进行文本检测
现在我正在将数据拆分为训练。 TrainingData 文件中有 2 个文件。每个图片文件夹有4张图片。(我知道很少,但我稍后会添加更多图片)
path = 'TrainingData'
images = []
classNo = []
myList = os.listdir(path)
print('Total No of Classes Detected...', len(myList))
noOfClasses = len(myList)
print('Importing Classes...')
for x in range(0, noOfClasses):
myPicList = os.listdir(path+'/'+str(x))
for y in myPicList:
curImg = cv2.imread(path+'/'+str(x)+'/'+y)
classNo.append(x)
print(x, end=' ')
print(' ')
但是,结果返回
File "/Users/myname/PycharmProjects/TextDetection/Playernames.py",line 37, in <module>
myPicList = os.listdir(path+"/"+str(x))
FileNotFoundError: [Errno 2] No such file or directory: 'TrainingData/0'
Total No of Classes Detected... 2
Importing Classes...
我试图解决的问题
1.检查路径是否存在
path = 'TrainingData'
if os.path.isfile(path):
print('File exists')
else:
print('Failed')
结果显示失败,所以我认为文件中不存在路径。
2:检查文件树
TrainingData 树↓
/Users/myname/PycharmProjects/TextDetection/TrainingData
├── File Name 1
│ ├── IMG_1754.jpg
│ ├── IMG_1755.jpg
│ ├── IMG_1756.jpg
│ └── IMG_1757.jpg
└── File Name 2
├── IMG_1751.jpg
├── IMG_1752.jpg
├── IMG_1753.jpg
└── IMG_1758.jpg
2 directories, 8 files
项目文件本身的树
/Users/myname/PycharmProjects/TextDetection/Playernames.py [error opening dir]
0 directories, 0 files
我想知道的
根据树,我想我需要更改 TrainingData 的位置,因为项目显示它没有任何目录或文件。 我想知道如何改变它。
我是初学者,所以我不确定我的尝试是对还是错。
【问题讨论】:
-
欢迎来到 Stack Overflow @Wasabi。我建议为此使用
pathlib,它是os.path的现代替代品。如果您想要一个功能示例,请参阅 this post 中名为 “使用 Python 3.4 中的 pathlib” 和 “在 pathlib.Path() 中使用 glob 方法” 的 2 个部分。如果您想缩小搜索范围try a tag combination like this
标签: python macos tensorflow pycharm file-not-found