ultralytics / JSON2YOLO

Convert JSON annotations into YOLO format.

Home Page:https://docs.ultralytics.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

May be this is a bug in save folder file names in txt files.

WangFengtu1996 opened this issue · comments

def image_folder2file(folder="images/"): # from utils import *; image_folder2file()

def image_folder2file(folder="images/"):  # from utils import *; image_folder2file()
    # write a txt file listing all imaged in folder
    s = glob.glob(f"{folder}/*.*")

    with open(f"{folder}.txt", "w") as file:
        for l in s:
            file.write(l + "\n")  # write image list

@WangFengtu1996 hello!

Thank you for reaching out with your concern. 🙏 It looks like you're referring to the functionality for generating a text file containing all image paths within a given folder. If your concern is regarding the format or the content of the generated .txt file, this method indeed lists all files in the specified folder, including images, by matching any extension with *.*.

If your intention is to filter only specific image file types (e.g., .jpg, .png), you might want to adjust the glob pattern accordingly. Here's a quick example:

import glob

def image_folder2file(folder="images/"):
    # Adjusted to include only .jpg and .png files
    extensions = ['jpg', 'png']
    files = []
    for ext in extensions:
        files.extend(glob.glob(f"{folder}/*.{ext}"))

    with open(f"{folder}.txt", "w") as file:
        for filepath in files:
            file.write(filepath + "\n")

This modification allows you to specify which file extensions to include in your .txt file, helping to ensure that only desired image files are listed.

Please let me know if this addresses your concern or if you have any further questions. For more details, do visit our documentation at Ultralytics Docs.

Cheers!

thanks.

@WangFengtu1996 you're welcome! If you have any more questions or need further clarification, feel free to ask. Happy coding! 😄