garmentiq.utils.check_unzipped_dir
1import os 2 3 4def check_unzipped_dir(folder): 5 """ 6 Verifies the structure and contents of an unzipped dataset directory. 7 8 This function checks that the specified folder contains: 9 - A subdirectory named 'images' with at least one `.jpg`, `.png`, `.jpeg` file. 10 - A file named 'metadata.csv'. 11 12 If any of these components are missing, a `FileNotFoundError` is raised. 13 14 Args: 15 folder (str): Path to the root folder of the unzipped dataset. 16 17 Raises: 18 FileNotFoundError: If the 'images' folder is missing, 19 if no `.jpg`, `.png`, `.jpeg` files are found in the 'images' folder, 20 or if 'metadata.csv' is missing. 21 22 Returns: 23 None 24 """ 25 image_dir = os.path.join(folder, "images") 26 metadata_path = os.path.join(folder, "metadata.csv") 27 28 if not os.path.isdir(image_dir): 29 raise FileNotFoundError(f"Missing 'images' folder in: {folder}") 30 31 jpg_files = [f for f in os.listdir(image_dir) if f.lower().endswith(".jpg") or f.lower().endswith(".png") or f.lower().endswith(".jpeg")] 32 if not jpg_files: 33 raise FileNotFoundError(f"No .jpg, .png, or .jpeg file found in: {image_dir}") 34 35 if not os.path.isfile(metadata_path): 36 raise FileNotFoundError(f"Missing 'metadata.csv' in: {folder}")
def
check_unzipped_dir(folder):
5def check_unzipped_dir(folder): 6 """ 7 Verifies the structure and contents of an unzipped dataset directory. 8 9 This function checks that the specified folder contains: 10 - A subdirectory named 'images' with at least one `.jpg`, `.png`, `.jpeg` file. 11 - A file named 'metadata.csv'. 12 13 If any of these components are missing, a `FileNotFoundError` is raised. 14 15 Args: 16 folder (str): Path to the root folder of the unzipped dataset. 17 18 Raises: 19 FileNotFoundError: If the 'images' folder is missing, 20 if no `.jpg`, `.png`, `.jpeg` files are found in the 'images' folder, 21 or if 'metadata.csv' is missing. 22 23 Returns: 24 None 25 """ 26 image_dir = os.path.join(folder, "images") 27 metadata_path = os.path.join(folder, "metadata.csv") 28 29 if not os.path.isdir(image_dir): 30 raise FileNotFoundError(f"Missing 'images' folder in: {folder}") 31 32 jpg_files = [f for f in os.listdir(image_dir) if f.lower().endswith(".jpg") or f.lower().endswith(".png") or f.lower().endswith(".jpeg")] 33 if not jpg_files: 34 raise FileNotFoundError(f"No .jpg, .png, or .jpeg file found in: {image_dir}") 35 36 if not os.path.isfile(metadata_path): 37 raise FileNotFoundError(f"Missing 'metadata.csv' in: {folder}")
Verifies the structure and contents of an unzipped dataset directory.
This function checks that the specified folder contains:
- A subdirectory named 'images' with at least one
.jpg
,.png
,.jpeg
file. - A file named 'metadata.csv'.
If any of these components are missing, a FileNotFoundError
is raised.
Arguments:
- folder (str): Path to the root folder of the unzipped dataset.
Raises:
- FileNotFoundError: If the 'images' folder is missing,
if no
.jpg
,.png
,.jpeg
files are found in the 'images' folder, or if 'metadata.csv' is missing.
Returns:
None