Labelbox

Tensorflow Export

Tensorflow Export

Image segmentation projects on Labelbox can now be exported as TFRecords for convenient and efficient usage by Tensorflow models.

After generating a TFRecord export from a project's export tab, a new task will appear under the "Tasks" button in the top navbar which upon completion will link to an export.json file. This file contains a string-serialized JSON object with the following properties:

  • legend - An object mapping pixel values [1-255] within a segmentation map to the class label they represent. A pixel value of 0 is used to denote unlabeled pixels.
  • tfrecord_paths - An array of Google Cloud Storage URLs containing the exported TFRecords.

Since Tensorflow provides out of the box support for reading from Google Cloud Storage, this array of URLs can be directly used as the filenames argument to instantiate a tf.data.TFRecordDataset.

Each TFRecord contains a single tf.train.Example with the following features:

  • image/encoded - A tf.string of the bytes of the encoded image. Can be decoded into a Tensor of uint8s using tf.image.decode_image.
  • image/filename - A tf.string of the Google Cloud Storage URL of this image.
  • image/ID - A tf.string of the ID of this image.
  • image/format - A tf.string of the format of this image.
  • image/height - A tf.int64 of the image's height.
  • image/width - Atf.int64` of the image's width.
  • image/channels - A tf.int64 of the number of channels in this image.
  • image/colorspace - A tf.string of the image's colorspace.
  • image/segmentation/class/encoded - A tf.string of the bytes of the encoded segmentation map. Can be decoded into a Tensor of uint8s using tf.image.decode_image.
  • image/segmentation/class/format - A tf.string representing the image format of the encoded segmentation map.

A code example which uses Tensorflow's Datasets API to decode a Labelbox TFRecord export's export.json into a directory of images and their segmentation maps is available here.

Example

This code demonstrates how to use a TFRecords export from Labelbox in a Tensorflow image segmentation model.
By leveraging Tensorflow's Datasets API,
the end-to-end example is able to read its inputs directly from cloud storage.

Walkthrough

This example was developed on Python 3.5.2.

Setting up

Configuring Google Cloud SDK application default credentials

TFRecord exports are hosted on Google Cloud Storage. To directly ingest them
from a Tensorflow Dataset Input Pipeline, Google Cloud SDK application default
credentials need to be configured.

Install the Google Cloud SDK by following these
instructions
and acquire Application
Default
Credentials

by running:

gcloud auth application-default login

Python dependencies

Install Python dependencies:

pip install -r requirements.txt

NOTE: See this issue
if you receive an "illegal hardware instruction" error. You may need to
install Tensorflow from
source
.

Running the model

python example.py export.json

Monitor the model outputs at http://localhost:6006/

Files provided

  • TODO
  • TODO

Model details

TODO: 3 layer CNN with FC layer replaced by another conv (FCN); no pooling => no upsampling