FileNotFoundError: [Errno 2] No such file or directory: ‘Q:\M\yolov9\datasets\metalfittings\labels\12_000150.JPG.txt’
ERROR conda.cli.main_run:execute(125): conda run python Q:\M\yolov9\datasets\fish\splitDataset.py
failed. (See above for error)
修改def toLabelPath函数
def toLabelPath(img_path, label_path):
img = img_path.split('\\')[-1]
label = img.split('.jpg')[0] + '.txt'
return os.path.join(label_path, label)
修改为
def toLabelPath(img_path, label_path):
# 获取文件名,包括扩展名
img = img_path.split('\\')[-1]
# 分割文件名和扩展名,不区分大小写
parts = img.lower().split('.')
# 确保文件名和扩展名正确分离
if len(parts) > 1:
filename = '.'.join(parts[:-1]) # 文件名,不包含扩展名
extension = parts[-1].upper() # 扩展名,统一为大写
else:
filename = img
extension = ''
# 构造标签文件名,将扩展名替换为 'txt'
label = f'{filename}.txt'
# 返回完整的标签文件路径
return os.path.join(label_path, label)