{"record":{"id":"15dbc0347c3767c1","repo":"geekcomputers/Python","slug":"dataset-directory-not-found-split-dir","errorCode":null,"errorMessage":"Dataset directory not found: {split_dir}","messagePattern":"Dataset directory not found: (.+?)","errorType":"error_code","errorClass":"FileNotFoundError","httpStatus":null,"severity":"critical","filePath":"ML/src/python/neuralforge/data/dataset.py","lineNumber":30,"sourceCode":"        root: str,\n        transform: Optional[Callable] = None,\n        target_transform: Optional[Callable] = None,\n        split: str = 'train'\n    ):\n        self.root = root\n        self.transform = transform\n        self.target_transform = target_transform\n        self.split = split\n        \n        self.samples = []\n        self.class_to_idx = {}\n        self._load_dataset()\n    \n    def _load_dataset(self):\n        split_dir = os.path.join(self.root, self.split)\n        \n        if not os.path.exists(split_dir):\n            raise FileNotFoundError(f\"Dataset directory not found: {split_dir}\")\n        \n        classes = sorted([d for d in os.listdir(split_dir) \n                         if os.path.isdir(os.path.join(split_dir, d))])\n        \n        self.class_to_idx = {cls_name: idx for idx, cls_name in enumerate(classes)}\n        \n        for class_name in classes:\n            class_dir = os.path.join(split_dir, class_name)\n            class_idx = self.class_to_idx[class_name]\n            \n            for img_name in os.listdir(class_dir):\n                if img_name.lower().endswith(('.png', '.jpg', '.jpeg', '.bmp', '.gif')):\n                    img_path = os.path.join(class_dir, img_name)\n                    self.samples.append((img_path, class_idx))\n    \n    def __len__(self) -> int:\n        return len(self.samples)\n    ","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/geekcomputers/Python/blob/40f4cd2652d75ef8e49d76e5c4d431d458712719/ML/src/python/neuralforge/data/dataset.py#L12-L48","documentation":"Raised by ImageDataset (neuralforge) when the split directory (root/<split>, e.g. data/train) does not exist on disk. The loader builds the path from the root and split arguments and immediately checks os.path.exists, failing before any class discovery. It signals a data-location or download problem, not corrupted data.","triggerScenarios":"Passing a wrong root path; using a split name that does not exist as a subdirectory ('valid' when only train/test exist); expecting download=True to fetch data but the directory was never created.","commonSituations":"Running training on a machine where the dataset was never copied/downloaded; typos in root ('./dat'); directory-layout mismatch (images flat instead of train/<class>/); download flag not actually implemented for this dataset class.","solutions":["Verify the directory exists: ls root/<split> and confirm class subdirectories","Fix the root or split argument to point at the actual dataset layout","Download/prepare the dataset first (or pass download=True if supported)","If your layout is flat, restructure into root/train/<class>/*/jpg or wrap with a loader that matches your layout"],"exampleFix":"# before\nds = ImageNetDataset(root='./data/imagenet', split='train')  # dir missing\n\n# after\nimport os\nsplit_dir = os.path.join('./data/imagenet', 'train')\nif not os.path.isdir(split_dir):\n    download_or_prepare(split_dir)\nds = ImageNetDataset(root='./data/imagenet', split='train')","handlingStrategy":"validation","validationCode":"import os\nsplit_dir = os.path.join(root, split)\nif not os.path.isdir(split_dir):\n    raise FileNotFoundError(f'Prepare {split_dir} before training')","typeGuard":"def dataset_ready(root: str, split: str) -> bool:\n    d = os.path.join(root, split)\n    return os.path.isdir(d) and any(os.path.isdir(os.path.join(d, x)) for x in os.listdir(d))","tryCatchPattern":"try:\n    ds = ImageNetDataset(root=root, split=split)\nexcept FileNotFoundError as e:\n    logger.error('Dataset missing: %s', e)\n    sys.exit(2)  # or trigger download/preparation step","preventionTips":["Assert the data directory exists in a setup script before training","Keep dataset root configurable via one config value and test it in CI","Verify layout is root/<split>/<class>/ files"],"tags":["dataset","file-not-found","data-loading","neuralforge"],"backgroundTag":"dataset-directory-missing","analyzedSha":"40f4cd2652d75ef8e49d76e5c4d431d458712719","analyzedAt":"2026-08-27T11:12:20.313Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}