forked from jahongir7174/YOLOv11-pt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_directory.py
More file actions
25 lines (18 loc) · 902 Bytes
/
file_directory.py
File metadata and controls
25 lines (18 loc) · 902 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import os
from tqdm import tqdm
# Define base directory
base_dir = "D:/dataset_d/mscoco_yolo"
# Subdirectories containing images
subdirs = ["images/train2017", "images/val2017", "images/test2017"]
for subdir in subdirs:
full_path = os.path.join(base_dir, subdir)
output_file = os.path.join(base_dir, f"{subdir.replace('images/', '')}_paths.txt") # Naming files like train2017_paths.txt
relative_paths = []
if os.path.exists(full_path):
for filename in tqdm(os.listdir(full_path)):
if filename.endswith((".jpg", ".png", ".jpeg")): # Adjust file types if needed
relative_paths.append(f"./{subdir}/{filename}") # Adding `./` for relative paths
# Save paths to corresponding file
with open(output_file, "w") as f:
f.write("\n".join(relative_paths))
print(f"Saved {len(relative_paths)} image paths to {output_file}")