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