import tensorflow as tf
from models.research.object_detection.utils import dataset_util


flags = tf.app.flags
flags.DEFINE_string('output_path', '', 'Path to output TFRecord')
FLAGS = flags.FLAGS


def create_tf_example(example):
  # TODO(user): Populate the following variables from your example.
  height = 144.0 # Image height
  width = 349.0 # Image width
  filename = "images2/gpl_37.jpeg" # Filename of the image. Empty if image is not from file
  # encoded_image_data = None # Encoded image bytes
  image_format = b'jpeg' # b'jpeg' or b'png'

  xmins = [50.0/349.0] # List of normalized left x coordinates in bounding box (1 per box)
  xmaxs = [99.0/349.0] # List of normalized right x coordinates in bounding box
             # (1 per box)
  ymins = [9.0/144.0] # List of normalized top y coordinates in bounding box (1 per box)
  ymaxs = [69.0/144.0] # List of normalized bottom y coordinates in bounding box
             # (1 per box)
  classes_text = ['gpl'] # List of string class name of bounding box (1 per box)
  classes = [1] # List of integer class id of bounding box (1 per box)

  tf_example = tf.train.Example(features=tf.train.Features(feature={
      'image/height': dataset_util.int64_feature(height),
      'image/width': dataset_util.int64_feature(width),
      'image/filename': dataset_util.bytes_feature(filename),
      'image/source_id': dataset_util.bytes_feature(filename),
      'image/encoded': dataset_util.bytes_feature(encoded_image_data),
      'image/format': dataset_util.bytes_feature(image_format),
      'image/object/bbox/xmin': dataset_util.float_list_feature(xmins),
      'image/object/bbox/xmax': dataset_util.float_list_feature(xmaxs),
      'image/object/bbox/ymin': dataset_util.float_list_feature(ymins),
      'image/object/bbox/ymax': dataset_util.float_list_feature(ymaxs),
      'image/object/class/text': dataset_util.bytes_list_feature(classes_text),
      'image/object/class/label': dataset_util.int64_list_feature(classes),
  }))
  return tf_example