fabito / tfrecord-view

Consume and view contents of TFRecord files (for Tensorflow's object detection api)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

tfrecord-view

How to consume data from TFRecord files, which are used in the Tensorflow object detection api. I use it to double ensure that my augmentation pipeline and TFRecord encoding worked properly.

Currently tested in Linux. Not sure about behavior in Windows.

Usage

Creating a TFRecord file

If you need to create a TFRecord file, see voc_to_tfr.py. The images and annotation files are in annotated_images/.

Consuming a TFRecord file

If you already have TFRecord file data, then use view_records.py or view_records_tf2.py to see how to consume it and show data. The function takes in the path to the TFRecord file, the dictionary of class labels, and a couple of optional keyword arguments like stride. It will then show the images with bounding boxes and labels for each object, if applicable.

Installation

Prereqs: tensorflow, opencv, and numpy.

git clone XXX
conda create --name tfrecord-view
conda activate --name tfrecord-view
conda install python=3 opencv numpy
conda install -c anaconda tensorflow-gpu>=1.12

This also assumes you have installed the object detection api (https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/installation.md), as we will use some utilities that come with it (in particular utils.dataset_util).

For more info

Construction of TFRecord files:

On consuming TFRrecord files, there aren't a lot of great resources out there. I used this (and probably 20 other sites I can't even remember: this is one aspect of the api that keeps changing, and will surely change again once it is ported to Tensorflow 2):

I recently found this repo which is similar to this one, and has some nice ideas:

To do

  • Functionalize encoder in voc_to_tfr.py.
  • Look over tfrecord_utility repo maybe he found a way to simplify reading data?

Sources for images

The images are of cats and dogs, with one that has no label. The images were scraped from:

About

Consume and view contents of TFRecord files (for Tensorflow's object detection api)


Languages

Language:Python 100.0%