WZMIAOMIAO/deep-learning-for-image-processing · error · FileNotFoundError
VOCdevkit dose not in path:'{}'.
Error message
VOCdevkit dose not in path:'{}'. What it means
train_mobilenetv2.py validates the dataset root before training: if `<VOC_root>/VOCdevkit` does not exist, it raises FileNotFoundError. This guards against a wrong or unextracted VOC dataset path.
Source
Thrown at pytorch_object_detection/faster_rcnn/train_mobilenetv2.py:65
# 检查保存权重文件夹是否存在,不存在则创建
if not os.path.exists("save_weights"):
os.makedirs("save_weights")
data_transform = {
"train": transforms.Compose([transforms.ToTensor(),
transforms.RandomHorizontalFlip(0.5)]),
"val": transforms.Compose([transforms.ToTensor()])
}
VOC_root = "./" # VOCdevkit
aspect_ratio_group_factor = 3
batch_size = 8
amp = False # 是否使用混合精度训练,需要GPU支持
# 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 aspect_ratio_group_factor >= 0:
train_sampler = torch.utils.data.RandomSampler(train_dataset)
# 统计所有图像高宽比例在bins区间中的位置索引
group_ids = create_aspect_ratio_groups(train_dataset, k=aspect_ratio_group_factor)
# 每个batch图片从同一高宽比例区间中取
train_batch_sampler = GroupedBatchSampler(train_sampler, group_ids, batch_size)
nw = min([os.cpu_count(), batch_size if batch_size > 1 else 0, 8]) # number of workers
print('Using %g dataloader workers' % nw)
View on GitHub (pinned to 1ec3fe6f37)
Solutions
- Download and extract the VOC2012 dataset so that `<data_path>/VOCdevkit` exists
- Pass the PARENT directory of VOCdevkit as --data-path (e.g. not .../VOCdevkit but .../VOCdevkit's parent)
- Verify the dataset is the expected layout: VOCdevkit/VOC2012/ImageSets/Main/train.txt
Example fix
# before python train_mobilenetv2.py --data-path ./VOCdevkit # after python train_mobilenetv2.py --data-path . # directory that contains VOCdevkit/
Defensive patterns
Strategy: validation
Validate before calling
import os
voc_root = "./data"
assert os.path.exists(os.path.join(voc_root, "VOCdevkit")), f"VOCdevkit missing under {voc_root}" Try / catch
try:
run_training(voc_root)
except FileNotFoundError as e:
if "VOCdevkit" in str(e):
download_and_extract_voc2012(voc_root)
run_training(voc_root) Prevention
- Download and extract VOC2012 before training
- Pass the parent directory of VOCdevkit as the data path
- Use absolute paths to avoid working-directory surprises
When it happens
Trigger: Running train_mobilenetv2.py with --data-path (or VOC_root) pointing to a directory that does not directly contain the VOCdevkit folder, or to the VOCdevkit folder itself instead of its parent.
Common situations: Forgetting to download/extract the VOC2012 dataset; passing the path of VOCdevkit rather than its parent; typo or relative path resolved from a different working directory.
Related errors
- VOCdevkit dose not in path:'{}'.
- VOCdevkit dose not in path:'{}'.
- VOCdevkit dose not in path:'{}'.
- image: {} isn't RGB mode.
- not find GPU device for training.
AI-assisted analysis of WZMIAOMIAO/deep-learning-for-image-processing@1ec3fe6f37 (2026-08-30).
Data as JSON: /api/errors/46d36a36dd380dbb.
Report an issue: GitHub.