Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added script to generate text file with dataset images relative paths. #8178

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions scripts/generate_dataset_images_relative_paths.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import sys
import os


def get_dataset_images_relative_paths(dataset_directory_name):
"""
Gets list of paths to the dataset images.

:param dataset_directory_name: dataset directory name
:return: dataset images relative paths
"""
os.chdir("..")
os.chdir(os.path.join("data", dataset_directory_name))

dataset_images_relative_paths = []
for dataset_image_name in os.listdir(os.getcwd()):
if dataset_image_name.endswith(".jpg"):
dataset_images_relative_paths.append(f"data/{dataset_directory_name}/{dataset_image_name}")

return dataset_images_relative_paths


def write_dataset_images_relative_paths(dataset_directory_name, dataset_images_relative_paths):
"""
Writes dataset images relative paths

:param dataset_directory_name: dataset directory name
:param dataset_images_relative_paths: dataset images relative paths
"""
os.chdir("..")

with open(f"{dataset_directory_name}.txt", "w") as dataset_images_relative_paths_file:
for dataset_image_relative_path in dataset_images_relative_paths:
dataset_images_relative_paths_file.write(f"{dataset_image_relative_path}\n")


def main():
"""
Script entry point.
"""
# Check whether dataset directory name is not provided
if len(sys.argv) != 2:
sys.exit("You need to provide dataset directory name!")

# Get dataset directory name
dataset_directory_name = sys.argv[1]

# Write dataset images relative paths
write_dataset_images_relative_paths(dataset_directory_name,
get_dataset_images_relative_paths(dataset_directory_name))


if __name__ == "__main__":
main()