WZMIAOMIAO/deep-learning-for-image-processing · error · FileNotFoundError
VOCdevkit dose not in path:'{}'.
Error message
VOCdevkit dose not in path:'{}'. What it means
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.
Source
Thrown at pytorch_object_detection/faster_rcnn/change_backbone_without_fpn.py:72
def main(args):
device = torch.device(args.device if torch.cuda.is_available() else "cpu")
print("Using {} device training.".format(device.type))
# 用来保存coco_info的文件
results_file = "results{}.txt".format(datetime.datetime.now().strftime("%Y%m%d-%H%M%S"))
data_transform = {
"train": transforms.Compose([transforms.ToTensor(),
transforms.RandomHorizontalFlip(0.5)]),
"val": transforms.Compose([transforms.ToTensor()])
}
VOC_root = args.data_path
# check voc root
if os.path.exists(os.path.join(VOC_root, "VOCdevkit")) is False:
raise FileNotFoundError("VOCdevkit dose not in path:'{}'.".format(VOC_root))
# load train data set
# VOCdevkit -> VOC2012 -> ImageSets -> Main -> train.txt
train_dataset = VOCDataSet(VOC_root, "2012", data_transform["train"], "train.txt")
train_sampler = None
# 是否按图片相似高宽比采样图片组成batch
# 使用的话能够减小训练时所需GPU显存,默认使用
if args.aspect_ratio_group_factor >= 0:
train_sampler = torch.utils.data.RandomSampler(train_dataset)
# 统计所有图像高宽比例在bins区间中的位置索引
group_ids = create_aspect_ratio_groups(train_dataset, k=args.aspect_ratio_group_factor)
# 每个batch图片从同一高宽比例区间中取
train_batch_sampler = GroupedBatchSampler(train_sampler, group_ids, args.batch_size)
# 注意这里的collate_fn是自定义的,因为读取的数据包括image和targets,不能直接使用默认的方法合成batch
batch_size = args.batch_size
nw = min([os.cpu_count(), batch_size if batch_size > 1 else 0, 8]) # number of workersView on GitHub (pinned to 1ec3fe6f37)
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.
Example fix
# before python change_backbone_without_fpn.py --data-path ~/data/VOCdevkit # after python change_backbone_without_fpn.py --data-path ~/data # ~/data/VOCdevkit must exist
Defensive patterns
Strategy: validation
Validate before calling
import os
voc_root = args.data_path
assert os.path.isdir(os.path.join(voc_root, 'VOCdevkit')), f"VOCdevkit missing under {voc_root}" Type guard
def is_valid_voc_root(path: str) -> bool:
return os.path.isdir(os.path.join(path, 'VOCdevkit', 'VOC2012')) Try / catch
try:
main(args)
except FileNotFoundError as e:
print(f'Bad --data-path: {e}. Expected <data-path>/VOCdevkit.')
sys.exit(2) Prevention
- 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
When it happens
Trigger: Invoking change_backbone_without_fpn.py with --data-path lacking a VOCdevkit subdirectory — wrong parent folder, archive not extracted, dataset moved, or path typo.
Common situations: Same as [50]: pointing at VOCdevkit itself, unextracted VOC2012 archive, using COCO-style data, or relative path resolved from a different cwd.
Related errors
- VOCdevkit dose not in path:'{}'.
- VOCdevkit dose not in path:'{}'.
- Image '{}' format not JPEG
- VOCdevkit dose not in path:'{}'.
- VOCdevkit dose not in path:'{}'.
AI-assisted analysis of WZMIAOMIAO/deep-learning-for-image-processing@1ec3fe6f37 (2026-08-30).
Data as JSON: /api/errors/a85b783fbf657bda.
Report an issue: GitHub.