Spaces:
Runtime error
Runtime error
Download src/dataset_loader.py from shashankheg/FashionLensAI: direct link, hf CLI and curl.
- Browser
- Download file 1.12 kB
-
https://huggingface.co/spaces/shashankheg/FashionLensAI/resolve/main/src/dataset_loader.py
- Command line
-
hf download hf://spaces/shashankheg/FashionLensAI/src/dataset_loader.py
-
curl -L -o dataset_loader.py https://huggingface.co/spaces/shashankheg/FashionLensAI/resolve/main/src/dataset_loader.py
1.12 kB
| from pathlib import Path | |
| import pandas as pd | |
| class DatasetLoader: | |
| def __init__(self, | |
| csv_pth ="data/styles.csv", | |
| image_dir="data/images"): | |
| self.csv_path = Path(csv_pth) | |
| self.image_dir = Path(image_dir) | |
| def load(self): | |
| """ | |
| Load fashion metadata. | |
| """ | |
| df = pd.read_csv( | |
| self.csv_path, | |
| on_bad_lines="skip", | |
| ) | |
| return df | |
| def validate_images(self, df): | |
| """ | |
| Validate that all images exist in the image directory. | |
| """ | |
| df['image_path'] = df['id'].apply( | |
| lambda x: str(self.image_dir /f"{x}.jpg") | |
| ) | |
| df =df [ | |
| df["image_path"].apply( | |
| lambda x: Path(x).exists() | |
| ) | |
| ] | |
| return df.reset_index(drop=True) | |
| if __name__ == "__main__": | |
| loader = DatasetLoader() | |
| df = loader.load() | |
| print(f"Rows before validation: {len(df)}") | |
| df = loader.validate_images(df) | |
| print(f"Rows after validation: {len(df)}") | |
| print(df.head()) | |