{"record":{"id":"2d49561e170d5421","repo":"WZMIAOMIAO/deep-learning-for-image-processing","slug":"vocdevkit-dose-not-in-path-2d4956","errorCode":null,"errorMessage":"VOCdevkit dose not in path:'{}'.","messagePattern":"VOCdevkit dose not in path:'(.+?)'\\.","errorType":"exception","errorClass":"FileNotFoundError","httpStatus":null,"severity":"error","filePath":"pytorch_object_detection/retinaNet/train.py","lineNumber":53,"sourceCode":"    return model\n\n\ndef main(args):\n    device = torch.device(args.device if torch.cuda.is_available() else \"cpu\")\n    print(\"Using {} device training.\".format(device.type))\n\n    results_file = \"results{}.txt\".format(datetime.datetime.now().strftime(\"%Y%m%d-%H%M%S\"))\n\n    data_transform = {\n        \"train\": transforms.Compose([transforms.ToTensor(),\n                                     transforms.RandomHorizontalFlip(0.5)]),\n        \"val\": transforms.Compose([transforms.ToTensor()])\n    }\n\n    VOC_root = args.data_path\n    # check voc root\n    if os.path.exists(os.path.join(VOC_root, \"VOCdevkit\")) is False:\n        raise FileNotFoundError(\"VOCdevkit dose not in path:'{}'.\".format(VOC_root))\n\n    # load train data set\n    # VOCdevkit -> VOC2012 -> ImageSets -> Main -> train.txt\n    train_dataset = VOCDataSet(VOC_root, \"2012\", data_transform[\"train\"], \"train.txt\")\n    train_sampler = None\n\n    # 是否按图片相似高宽比采样图片组成batch\n    # 使用的话能够减小训练时所需GPU显存，默认使用\n    if args.aspect_ratio_group_factor >= 0:\n        train_sampler = torch.utils.data.RandomSampler(train_dataset)\n        # 统计所有图像高宽比例在bins区间中的位置索引\n        group_ids = create_aspect_ratio_groups(train_dataset, k=args.aspect_ratio_group_factor)\n        # 每个batch图片从同一高宽比例区间中取\n        train_batch_sampler = GroupedBatchSampler(train_sampler, group_ids, args.batch_size)\n\n    # 注意这里的collate_fn是自定义的，因为读取的数据包括image和targets，不能直接使用默认的方法合成batch\n    batch_size = args.batch_size\n    nw = min([os.cpu_count(), batch_size if batch_size > 1 else 0, 8])  # number of workers","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/WZMIAOMIAO/deep-learning-for-image-processing/blob/1ec3fe6f374fc9969973a61f819de25658595afa/pytorch_object_detection/retinaNet/train.py#L35-L71","documentation":"train.py's main() verifies that args.data_path contains a VOCdevkit subdirectory before constructing VOCDataSet. If the path does not exist, it raises FileNotFoundError naming the configured root. This is an early, explicit guard against running with a wrong/empty data root, since the dataset classes would otherwise fail later with more confusing errors.","triggerScenarios":"Running python train.py --data-path <wrong dir>; data_path pointing at the parent of the parent (should be the dir containing VOCdevkit/); dataset not yet downloaded/extracted; typo in path or running from a different working directory with a relative path.","commonSituations":"Cloning the repo without downloading VOC2012; extracting the archive so the structure becomes root/VOC2012/... without the VOCdevkit folder level; Docker/colab setups where the dataset volume is mounted elsewhere; passing the VOCdevkit path itself instead of its parent.","solutions":["Pass the directory that directly contains VOCdevkit: --data-path /data (with /data/VOCdevkit/VOC2012/...).","Download and extract VOC2012 into the data root so VOCdevkit exists.","Fix extraction nesting: if you got root/VOCdevkit/VOCdevkit/..., move the inner folder up.","Verify with ls $DATA_PATH/VOCdevkit before launching training."],"exampleFix":"// before\npython train.py --data-path /data/VOCdevkit   # wrong: points inside the root\n// after\npython train.py --data-path /data             # /data/VOCdevkit must exist","handlingStrategy":"validation","validationCode":"import os\nVOC_root = args.data_path\nif not os.path.isdir(os.path.join(VOC_root, \"VOCdevkit\")):\n    raise FileNotFoundError(f\"VOCdevkit not found under {VOC_root}; pass the parent directory\")","typeGuard":"def has_voc_root(data_path: str) -> bool:\n    import os\n    return os.path.isdir(os.path.join(data_path, \"VOCdevkit\", \"VOC2012\"))","tryCatchPattern":"try:\n    main(args)\nexcept FileNotFoundError as e:\n    if \"VOCdevkit\" in str(e):\n        print(f\"Fix --data-path (currently {args.data_path}); it must contain VOCdevkit/\")\n        sys.exit(1)\n    raise","preventionTips":["Check dataset layout (ls $DATA_PATH/VOCdevkit/VOC2012) before training.","Pass the parent of VOCdevkit, not VOCdevkit itself, as --data-path.","Script the dataset download+extract step in setup docs/CI.","Use absolute paths to avoid working-directory surprises."],"tags":["python","pytorch","dataset","file-not-found"],"backgroundTag":"missing-dataset-path","analyzedSha":"1ec3fe6f374fc9969973a61f819de25658595afa","analyzedAt":"2026-08-30T09:19:11.901Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}