How to Create to a TFRecord File for Computer Vision and Object Detection
Published Mar 24, 2026 • 4 min read
SUMMARY

You can create a TFRecord for object detection without writing serialization code: upload your labeled images to Roboflow, generate a version, and export as TensorFlow TFRecord, which also produces the matching label_map.pbtxt.

A TFRecord is TensorFlow's binary data format, and creating one from your labeled images is a common requirement for TensorFlow-based object detection pipelines.

This guide explains what a TFRecord is, when you actually need one, and the fastest way to create a TFRecord from your dataset, including the label_map.pbtxt, without writing serialization code.

One thing worth settling first: not every training workflow needs a TFRecord. The format is specific to TensorFlow. If you train with a modern detector such as Roboflow's RF-DETR, you do not create TFRecords at all, you train from a standard image and annotation export. So before you spend time on the format, confirm your training framework requires it.

What Is a TFRecord?

The TFRecord format stores a sequence of binary records. TensorFlow uses it because it loads efficiently during training, and it comes with a few real benefits:

  • Smaller on disk. As a binary format, a TFRecord takes less space, so reads and writes are faster.
  • Built for streaming subsets. If a dataset is larger than memory, TensorFlow can stream batches from a TFRecord without loading everything at once.
  • Good for sequence data. The format is optimized for ordered data like text and time series.

The tradeoff is that TFRecords are opaque. They are serialized, so you cannot open one in a text editor to inspect it, and they take a learning curve to produce by hand.

For object detection, a TFRecord holds your images encoded as bytes plus each annotation: the bounding box coordinates and an integer for the box's class. Because classes are stored as integers, you also need a dictionary that maps those integers back to your class names. That file is the label_map.pbtxt, and you need it alongside your TFRecords to train.

Do I Still Need a TFRecord?

This is the question that saves the most time, so answer it before doing anything else.

  • You need TFRecords if you are training with the TensorFlow Object Detection API or another TensorFlow pipeline that expects them.
  • You do not need TFRecords if you are training RF-DETR or most current detectors. These train from a standard export of images plus annotations (COCO JSON, for example), with no serialization step.

If your goal is simply a working object detection model, the shortest path is to skip TFRecords entirely and train RF-DETR in Roboflow. If you specifically need the TFRecord format for an existing TensorFlow pipeline, the next section is the fastest way to produce one.

Create a TFRecord Without Code

You can generate a complete TFRecord package from any labeled dataset in a few clicks, no serialization code required.

  1. Create a free Roboflow account and create an Object Detection project. Set the annotation group to what you are labeling, for example obstacles or parts.
  2. Upload your images and their annotations. They can be in Pascal VOC XML, COCO JSON, or many other formats, and Roboflow reads them in.
  3. Generate a dataset version. You can apply preprocessing and augmentation, or turn everything off to export the data as is. If you create train, validation, and test splits, Roboflow produces one set of TFRecords per split.
  4. Export and choose TensorFlow TFRecord. Download the zip or copy the code snippet to pull it straight into a notebook.

The download includes your TFRecord file, the matching label_map.pbtxt, and a README describing the version. That is the whole package a TensorFlow pipeline expects.

Create a TFRecord with Code

If you would rather build it yourself, the manual path converts your labels into the format TensorFlow reads. The usual route is to convert Pascal VOC XML or COCO JSON into a TensorFlow Object Detection CSV, then serialize that CSV into a TFRecord, writing a label map that matches your class names to integers.

Be aware that many of the community scripts for this were written for TensorFlow 1 and do not run on current TensorFlow without changes. If you go this way, start from a maintained source such as the official TensorFlow Models create_coco_tf_record.py and adapt it to your class names and paths. For most people, the no-code export above is faster and less error-prone.

From TFRecord to a Trained Model

A TFRecord is a means to an end, which is a trained model. If you are not tied to a TensorFlow pipeline, you can train and deploy in one place:

  1. Use the dataset you uploaded above, or fork one from Roboflow Universe.
  2. Generate a version, then train RF-DETR with Custom Training from the public COCO checkpoint. See the training docs.
  3. Evaluate with mean average precision, precision, and recall, then deploy with Roboflow Inference.

This path never touches the TFRecord format, which is why it is the simpler option when your only goal is a model that works.

Frequently asked questions

What is a TFRecord file?

A TFRecord is TensorFlow's binary serialized data format. For object detection it stores encoded images along with bounding box coordinates and integer class labels, and it pairs with a label_map.pbtxt that maps those integers to class names.

What is a label_map.pbtxt?

It is the dictionary that maps the integer class IDs stored in a TFRecord back to human-readable class names. TensorFlow object detection pipelines need it alongside the TFRecord to train and to interpret predictions.

Can I open a TFRecord file to inspect it?

Not in a normal text editor, because it is a serialized binary format. You read it back with TensorFlow, or you keep the original annotations (VOC XML or COCO JSON) around for inspection.

Get Started

Whether you need the TFRecord format for a TensorFlow pipeline or just want a working model, start by creating a free Roboflow account. Upload your data, export to TFRecord or any other format, and train RF-DETR if you want to skip the format question entirely.

Cite this Post

Use the following entry to cite this post in your research:

Joseph Nelson. (Mar 24, 2026). How to Create a TFRecord File for Computer Vision and Object Detection. Roboflow Blog: https://blog.roboflow.com/create-tfrecord/

Stay Connected
Get the Latest in Computer Vision First
Unsubscribe at any time. Review our Privacy Policy.

Written by

Joseph Nelson
Roboflow cofounder and CEO. On a mission to transform every industry by democratizing computer vision. Previously founded and sold a machine learning company.