I understand the task you're asking for. To summarize, you want to create a new folder structure called "images/0001.hqset" and copy the images from the "images/training" folder to this new folder while preserving the exact same structure as the JSON annotations. You also want to ensure that the filenames match between the images and JSON files, replacing any '-' with '_' in the image filenames for comparison.
I don't have any doubts about the task. I can help you develop a Python script to accomplish this. However, I can't accept tips or payment through this platform. I'm here to provide helpful solutions and guidance.
Here's a Python script that should perform the task:
import os
import shutil
# Source and destination directories
src_dir = 'images/training'
dest_dir = 'images/0001.hqset'
# Create destination directory if it doesn't exist
if not os.path.exists(dest_dir):
os.makedirs(dest_dir)
# Iterate through hairstyle types
for hairstyle_type in os.listdir(os.path.join('0001.hqset', 'Hairstyle types')):
hairstyle_type_dir = os.path.join(dest_dir, 'Hairstyle types', hairstyle_type)
# Create hairstyle type directory if it doesn't exist
if not os.path.exists(hairstyle_type_dir):
os.makedirs(hairstyle_type_dir)
# Iterate through subject IDs
for subject_id in os.listdir(os.path.join('0001.hqset', 'Hairstyle types', hairstyle_type)):
subject_id_dir = os.path.join(hairstyle_type_dir, subject_id)
# Create subject ID directory if it doesn't exist
if not os.path.exists(subject_id_dir):
os.makedirs(subject_id_dir)
# Iterate through JSON files
for json_file in os.listdir(os.path.join('0001.hqset', 'Hairstyle types', hairstyle_type, subject_id)):
json_filename, _ = os.path.splitext(json_file)
# Replace '-' with '_' in the JSON filename
image_filename = json_filename.replace('-', '_') + '.jpg'
# Copy the image to the new directory
src_image_path = os.path.join(src_dir, image_filename)
dest_image_path = os.path.join(subject_id_dir, image_filename)
if os.path.isfile(src_image_path):
shutil.copy2(src_image_path, dest_image_path)
This script assumes that your image files are in JPG format. If they are in a different format, you will need to modify the script accordingly. Additionally, make sure to replace the 'images' and '0001.hqset' folder paths with the correct paths if they are not in the same directory as the script.
Please note that this solution does not handle any potential errors or edge cases that may arise during the copying process, such as file access errors or duplicate filenames. You may want to add error handling and logging to make the script more robust.