{"record":{"id":"fc59475fb564b37b","repo":"WZMIAOMIAO/deep-learning-for-image-processing","slug":"file-i-does-not-exists","errorCode":null,"errorMessage":"file {i} does not exists.","messagePattern":"file (.+?) does not exists\\.","errorType":"exception","errorClass":"FileNotFoundError","httpStatus":null,"severity":"error","filePath":"pytorch_segmentation/unet/my_dataset.py","lineNumber":21,"sourceCode":"import numpy as np\nfrom torch.utils.data import Dataset\n\n\nclass DriveDataset(Dataset):\n    def __init__(self, root: str, train: bool, transforms=None):\n        super(DriveDataset, self).__init__()\n        self.flag = \"training\" if train else \"test\"\n        data_root = os.path.join(root, \"DRIVE\", self.flag)\n        assert os.path.exists(data_root), f\"path '{data_root}' does not exists.\"\n        self.transforms = transforms\n        img_names = [i for i in os.listdir(os.path.join(data_root, \"images\")) if i.endswith(\".tif\")]\n        self.img_list = [os.path.join(data_root, \"images\", i) for i in img_names]\n        self.manual = [os.path.join(data_root, \"1st_manual\", i.split(\"_\")[0] + \"_manual1.gif\")\n                       for i in img_names]\n        # check files\n        for i in self.manual:\n            if os.path.exists(i) is False:\n                raise FileNotFoundError(f\"file {i} does not exists.\")\n\n        self.roi_mask = [os.path.join(data_root, \"mask\", i.split(\"_\")[0] + f\"_{self.flag}_mask.gif\")\n                         for i in img_names]\n        # check files\n        for i in self.roi_mask:\n            if os.path.exists(i) is False:\n                raise FileNotFoundError(f\"file {i} does not exists.\")\n\n    def __getitem__(self, idx):\n        img = Image.open(self.img_list[idx]).convert('RGB')\n        manual = Image.open(self.manual[idx]).convert('L')\n        manual = np.array(manual) / 255\n        roi_mask = Image.open(self.roi_mask[idx]).convert('L')\n        roi_mask = 255 - np.array(roi_mask)\n        mask = np.clip(manual + roi_mask, a_min=0, a_max=255)\n\n        # 这里转回PIL的原因是，transforms中是对PIL数据进行处理\n        mask = Image.fromarray(mask)","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/WZMIAOMIAO/deep-learning-for-image-processing/blob/1ec3fe6f374fc9969973a61f819de25658595afa/pytorch_segmentation/unet/my_dataset.py#L3-L39","documentation":"DriveDataset.__init__ builds paths to the '1st_manual' folder (ground-truth manual segmentations named <id>_manual1.gif) and raises FileNotFoundError if any expected manual file is missing from the DRIVE dataset directory. The dataset validates all files up front so failures surface at construction, not during epoch iteration.","triggerScenarios":"Constructing DriveDataset with a data_root whose DRIVE/train/1st_manual (or test/1st_manual) directory lacks the <id>_manual1.gif file for one of the img_names, or img_names don't follow the DRIVE naming convention (e.g. 21_training.png expects 21_manual1.gif).","commonSituations":"Incomplete/partial download of the DRIVE dataset, renamed manual files, extracting only the 'images' folder, or pointing data_path at a custom dataset not structured like DRIVE.","solutions":["Re-download/restore the full DRIVE dataset so 1st_manual contains all <id>_manual1.gif files","Verify each images/<id>_training.png has a matching 1st_manual/<id>_manual1.gif","If using your own data, restructure it to the DRIVE layout or edit my_dataset.py to match your naming"],"exampleFix":"// before\nself.manual = [os.path.join(data_root, \"1st_manual\", i.split(\"_\")[0] + \"_manual1.gif\") for i in img_names]\n// after\n# ensure the file exists, e.g. restore DRIVE/1st_manual/21_manual1.gif missing from the download","handlingStrategy":"validation","validationCode":"import os, glob\nmanual_dir = os.path.join(data_root, \"DRIVE\", \"train\", \"1st_manual\")\nmissing = [os.path.basename(p) for p in glob.glob(os.path.join(img_dir, \"*_training.png\"))\n           if not os.path.exists(os.path.join(manual_dir, os.path.basename(p).split(\"_\")[0] + \"_manual1.gif\"))]\nassert not missing, f\"missing manual files: {missing}\"","typeGuard":"def drive_manual_ok(data_root: str, split: str = \"train\") -> bool:\n    return os.path.isdir(os.path.join(data_root, \"DRIVE\", split, \"1st_manual\"))","tryCatchPattern":"try:\n    dataset = DriveDataset(data_root, train=True, transforms=transforms)\nexcept FileNotFoundError as e:\n    print(f\"dataset incomplete, re-extract DRIVE: {e}\"); raise","preventionTips":["Verify the DRIVE archive checksum after download","Extract all subfolders (images, 1st_manual, mask) — not just images","Check name pairing: <id>_training.png ↔ <id>_manual1.gif"],"tags":["python","file-not-found","dataset"],"backgroundTag":"missing-dataset-file","analyzedSha":"1ec3fe6f374fc9969973a61f819de25658595afa","analyzedAt":"2026-08-30T09:19:11.901Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}