TensorFlow自定义目标检测报错:文件不存在及自制数据集失效求助
Hey there, let's dig into why your custom dataset is throwing that "No such file or directory" error. I’ve worked with this repo and TensorFlow 1.x before, so here are the most likely fixes to try:
Windows uses backslashes (\) but TensorFlow/Python often expects forward slashes (/). Even if you mirrored the sample structure, verify:
- All paths in
train.txt,test.txt, and config files (likepipeline.config) use forward slashes. For example, replaceC:\Users\You\Custom-Object-Detection\images\train\img1.jpgwithC:/Users/You/Custom-Object-Detection/images/train/img1.jpg. - Avoid spaces or special characters in paths/filenames. Rename files like
my image.jpgtomy_image.jpg—Python/TensorFlow can choke on unescaped spaces. - Confirm every path listed in
train.txtandtest.txtactually exists. A tiny typo (e.g.,img001.jpgvsimg01.jpg) will trigger this error. You can quickly validate paths with a short Python script that loops through each line and checksos.path.exists().
The repo relies on a strict folder layout. Make yours looks like this:
Custom-Object-Detection/ ├─ images/ │ ├─ train/ │ │ ├─ Your training images │ │ └─ Corresponding .xml annotations (from LabelImg) │ └─ test/ │ ├─ Your test images │ └─ Corresponding .xml annotations ├─ annotations/ │ ├─ train_labels.csv │ ├─ test_labels.csv │ └─ label_map.pbtxt └─ ... other repo files
- Did you run
xml_to_csv.pyto generate the CSV files? This step converts your LabelImg annotations into the format the model expects—skip it, and the pipeline won’t find valid labels. - Ensure
label_map.pbtxtmatches the sample format exactly. For a class nameddog, it should look like:
Double-check that class IDs match what’s in your CSV files, and there are no typos in class names.item { id: 1 name: 'dog' }
pipeline.config The training/pipeline.config file has hardcoded placeholder paths. Update these to point to your actual files:
- Look for lines like
input_path: "PATH_TO_BE_CONFIGURED/train.record"and replacePATH_TO_BE_CONFIGUREDwith your full repo path (using forward slashes). - Repeat for
test_input_pathandlabel_map_path. For example:label_map_path: "C:/Users/You/Custom-Object-Detection/annotations/label_map.pbtxt" - Also confirm you ran
generate_tfrecord.pyto createtrain.recordandtest.record—these are the TFRecord files the model reads. If they’re missing or misdirected, you’ll get the file-not-found error.
Windows defaults to hiding known file extensions. So img1.jpg might actually be img1.jpg.jpg without you noticing. Fix this:
- Open File Explorer > View tab > Check "File name extensions".
- Verify all images have
.jpg(or your chosen format) and annotations have.xmlextensions.
Sometimes Windows restricts access to certain folders. Try:
- Running your command prompt or IDE as Administrator.
- Moving the
Custom-Object-Detectionfolder out of restricted locations likeProgram Files—use your Documents or Desktop instead.
If you’ve tried all these and still hit issues, paste the exact error message (including the full path it’s trying to access) and we can narrow it down further.
内容的提问来源于stack exchange,提问作者Markus Mikkonen

