You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

TensorFlow 2.2.0运行generate_tfrecords.py无法生成TFRecord文件求助

Troubleshooting: generate_tfrecords.py Exits With "Bye..." No TFRecords Generated

Hey there! Let's figure out why your TFRecord generation is failing silently—you've done all the prep work (cloning models, labeling, XML→CSV) so this is just a small hiccup to iron out.

First, let's recap what's happening: when you run generate_tfrecords.py, you only get an HDF5 version mismatch warning plus a "Bye..." message, with no actual TFRecord files created. Let's break down the most likely causes and fixes:

1. You Forgot (Or Messed Up) Command-Line Arguments

Most standard generate_tfrecords.py scripts require you to pass specific arguments for the input CSV, output TFRecord path, and label map. If you skip these or pass them incorrectly, the script might exit early without any useful errors (hence the vague "Bye...").

For example, the typical correct command looks like this (adjust paths to match your setup):

python generate_tfrecords.py --csv_input=data/train_labels.csv --output_path=data/train.record --label_map_path=data/label_map.pbtxt

Double-check:

  • Are you using the right flag names? Some scripts use positional arguments instead of flags (e.g., python generate_tfrecords.py train_labels.csv train.record label_map.pbtxt)—match what your script expects.
  • Did you spell paths correctly? Typos here are super common!

2. Your File Paths Are Wrong (Or Files Don't Exist)

Even if you pass arguments, relative paths can trip you up if you're running the script from the wrong directory:

  • CSV file not found: Try using absolute paths for your CSV and output (e.g., /home/yourname/project/data/train_labels.csv) instead of relative ones to eliminate confusion.
  • Output directory missing: If you're writing to data/train.record, make sure the data folder actually exists—many scripts won't create directories automatically.
  • Images can't be located: The script needs to read your images to build TFRecords. Check if the filename column in your CSV points to the correct location of your images (relative to where you're running the script).

3. Your CSV File Is Formatted Incorrectly

The script relies on the CSV having specific columns—if any are missing, misnamed, or have bad data, it might fail silently. The standard required columns are:

  • filename (e.g., dog_01.jpg)
  • width, height (image dimensions)
  • class (label name, must match exactly what's in your label map)
  • xmin, ymin, xmax, ymax (bounding box coordinates—make sure these are pixel values, not normalized, unless your script is coded to handle normalized values)

Open your CSV in a text editor or spreadsheet tool to confirm:

  • No empty rows at the top/bottom
  • Column names are spelled correctly (case-sensitive!)
  • Bounding box values are valid (e.g., xmin < xmax, values don't exceed image width/height)

4. The Script Has Silent Failure Logic

Let's look at the generate_tfrecords.py code itself—there might be checks that are failing without telling you. Add simple print statements to debug:

  1. After loading the CSV data, add:
    print(f"Successfully loaded {len(rows)} rows from the CSV file")
    
    If this prints 0, your CSV isn't being read correctly.
  2. After loading the label map, add:
    print(f"Loaded label map: {label_map}")
    
    If this doesn't show your labels, the label map path is wrong or the file is formatted incorrectly.

Also, that HDF5 warning? It's usually just a nuisance, but if your HDF5 version is way off from what TensorFlow 2.2.0 expects (TF 2.2.0 works best with HDF5 1.10.x), it could cause silent crashes. Try upgrading/downgrading HDF5 to match:

pip install h5py==2.10.0  # This is compatible with TF 2.2.0

5. Your Directory Structure Doesn't Match What The Script Expects

Make sure your files are organized in a way the script can find them. A standard setup looks like this:

your_project/
├── models/research/object_detection/
│   └── generate_tfrecords.py
├── data/
│   ├── train_labels.csv
│   ├── test_labels.csv
│   └── label_map.pbtxt
└── images/
    ├── train/
    │   └── all_train_images.jpg
    └── test/
        └── all_test_images.jpg

If your images are in a different folder, ensure the filename column in your CSV includes the full relative path (e.g., images/train/dog_01.jpg instead of just dog_01.jpg).


内容的提问来源于stack exchange,提问作者user10882820

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 09:58:12