WZMIAOMIAO/deep-learning-for-image-processing · error · FileNotFoundError
VOCdevkit dose not in path:'{}'.
Error message
VOCdevkit dose not in path:'{}'. What it means
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.
Source
Thrown at pytorch_object_detection/retinaNet/train.py:53
return model
def main(args):
device = torch.device(args.device if torch.cuda.is_available() else "cpu")
print("Using {} device training.".format(device.type))
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
- 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.
Example fix
// before python train.py --data-path /data/VOCdevkit # wrong: points inside the root // after python train.py --data-path /data # /data/VOCdevkit must exist
Defensive patterns
Strategy: validation
Validate before calling
import os
VOC_root = args.data_path
if not os.path.isdir(os.path.join(VOC_root, "VOCdevkit")):
raise FileNotFoundError(f"VOCdevkit not found under {VOC_root}; pass the parent directory") Type guard
def has_voc_root(data_path: str) -> bool:
import os
return os.path.isdir(os.path.join(data_path, "VOCdevkit", "VOC2012")) Try / catch
try:
main(args)
except FileNotFoundError as e:
if "VOCdevkit" in str(e):
print(f"Fix --data-path (currently {args.data_path}); it must contain VOCdevkit/")
sys.exit(1)
raise Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- image: {} isn't RGB mode.
- dataset have {} classes, but input {}
- dataset have {} classes, but input {}
- image: {} isn't RGB mode.
- image: {} isn't RGB mode.
AI-assisted analysis of WZMIAOMIAO/deep-learning-for-image-processing@1ec3fe6f37 (2026-08-30).
Data as JSON: /api/errors/2d49561e170d5421.
Report an issue: GitHub.