部署文件+resize_cls+resize_seg
This commit is contained in:
34
yemian/txt_1.py
Normal file
34
yemian/txt_1.py
Normal file
@ -0,0 +1,34 @@
|
||||
import os
|
||||
|
||||
# ================== 配置参数 ==================
|
||||
# 图片所在的文件夹路径
|
||||
image_folder = '/home/hx/yolo/yemian/resize_p' # 修改为你的图片文件夹路径
|
||||
|
||||
# 输出的txt文件路径
|
||||
output_txt = '/home/hx/yolo/yemian/image_list.txt' # 修改为你想保存的路径
|
||||
|
||||
# 支持的图片格式
|
||||
image_extensions = {'.jpg', '.jpeg', '.png', '.bmp', '.webp', '.tiff', '.gif'}
|
||||
|
||||
# 是否保存绝对路径(True)还是仅文件名(False)
|
||||
save_full_path = True # 设为 False 只保存文件名
|
||||
# =============================================
|
||||
|
||||
# 获取所有图片文件
|
||||
image_files = []
|
||||
for root, dirs, files in os.walk(image_folder):
|
||||
for file in files:
|
||||
ext = os.path.splitext(file.lower())[1]
|
||||
if ext in image_extensions:
|
||||
file_path = os.path.join(root, file)
|
||||
if save_full_path:
|
||||
image_files.append(os.path.abspath(file_path))
|
||||
else:
|
||||
image_files.append(file)
|
||||
|
||||
# 写入txt文件
|
||||
with open(output_txt, 'w', encoding='utf-8') as f:
|
||||
for img_path in image_files:
|
||||
f.write(img_path + '\n')
|
||||
|
||||
print(f"✅ 已保存 {len(image_files)} 张图片的路径到:\n {output_txt}")
|
||||
Reference in New Issue
Block a user