{"record":{"id":"a85b783fbf657bda","repo":"WZMIAOMIAO/deep-learning-for-image-processing","slug":"vocdevkit-dose-not-in-path-a85b78","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/faster_rcnn/change_backbone_without_fpn.py","lineNumber":72,"sourceCode":"\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    # 用来保存coco_info的文件\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":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/WZMIAOMIAO/deep-learning-for-image-processing/blob/1ec3fe6f374fc9969973a61f819de25658595afa/pytorch_object_detection/faster_rcnn/change_backbone_without_fpn.py#L54-L90","documentation":"Identical guard to error 50 but in change_backbone_without_fpn.py: the script verifies that os.path.join(args.data_path, 'VOCdevkit') exists before instantiating VOCDataSet, otherwise raising FileNotFoundError with the bad root. It fails fast so the VOC dataset layout is present before training/replacing the backbone.","triggerScenarios":"Invoking change_backbone_without_fpn.py with --data-path lacking a VOCdevkit subdirectory — wrong parent folder, archive not extracted, dataset moved, or path typo.","commonSituations":"Same as [50]: pointing at VOCdevkit itself, unextracted VOC2012 archive, using COCO-style data, or relative path resolved from a different cwd.","solutions":["Point --data-path at the directory that directly contains VOCdevkit.","Extract the VOC2012 archive so <data-path>/VOCdevkit/VOC2012 exists.","Confirm the expected tree exists: <data-path>/VOCdevkit/VOC2012/ImageSets/Main/train.txt.","Use an absolute path to avoid cwd confusion.","Adapt the check/dataset if your data uses a different layout."],"exampleFix":"# before\npython change_backbone_without_fpn.py --data-path ~/data/VOCdevkit\n# after\npython change_backbone_without_fpn.py --data-path ~/data  # ~/data/VOCdevkit must exist","handlingStrategy":"validation","validationCode":"import os\nvoc_root = args.data_path\nassert os.path.isdir(os.path.join(voc_root, 'VOCdevkit')), f\"VOCdevkit missing under {voc_root}\"","typeGuard":"def is_valid_voc_root(path: str) -> bool:\n    return os.path.isdir(os.path.join(path, 'VOCdevkit', 'VOC2012'))","tryCatchPattern":"try:\n    main(args)\nexcept FileNotFoundError as e:\n    print(f'Bad --data-path: {e}. Expected <data-path>/VOCdevkit.')\n    sys.exit(2)","preventionTips":["Pass the parent of VOCdevkit as --data-path","Verify the extracted dataset layout before launching","Use absolute paths to avoid cwd issues","Keep a setup script that extracts and validates the dataset"],"tags":["filesystem","path","dataset","voc"],"backgroundTag":"dataset-path-not-found","analyzedSha":"1ec3fe6f374fc9969973a61f819de25658595afa","analyzedAt":"2026-08-30T09:19:11.901Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}