Example #1
0
def _write_image_level_labels(fname, image_ids, machine=False):
    """Writes CSV with 0-10 labels per image."""
    lines = ['ImageID,Source,LabelName,Condidence']
    all_class_label = ClassLabel(names_file=py_utils.get_tfds_path(
        os.path.join('image', 'open_images_classes_all.txt')))
    trainable_class_label = ClassLabel(names_file=py_utils.get_tfds_path(
        os.path.join('image', 'open_images_classes_trainable.txt')))
    for i, image_id in enumerate(image_ids):
        if i < 1:
            # Ensure that at least some image contains trainable classes.
            labels = random.sample(trainable_class_label.names,
                                   random.randint(0, 10))
        else:
            labels = random.sample(all_class_label.names,
                                   random.randint(0, 10))
        for label in labels:
            source = random.choice(open_images.IMAGE_LEVEL_SOURCES)
            confidence = random.choice((0, 1))
            if machine:
                confidence = '%.1f' % (random.randint(0, 10) / 10.)
            else:
                confidence = random.choice((0, 1))
            lines.append('%s,%s,%s,%s' % (image_id, source, label, confidence))
    path = os.path.join(_output_dir(), fname)
    with open(path, 'w') as csv_f:
        csv_f.write('\n'.join(lines))
Example #2
0
def _write_bbox_labels(fname, image_ids):
    """Writes CSV with 0-10 labels per image."""
    lines = [
        'ImageID,Source,LabelName,Confidence,XMin,XMax,YMin,YMax,IsOccluded,'
        'IsTruncated,IsGroupOf,IsDepiction,IsInside'
    ]
    boxable_class_label = ClassLabel(names_file=py_utils.get_tfds_path(
        os.path.join('image', 'open_images_classes_boxable.txt')))
    for image_id in image_ids:
        labels = random.sample(boxable_class_label.names,
                               random.randint(0, 10))
        for label in labels:
            source = random.choice(open_images.BBOX_SOURCES)
            xmin = random.uniform(0, 1)
            xmax = random.uniform(xmin, 1)
            ymin = random.uniform(0, 1)
            ymax = random.uniform(ymin, 1)
            p1, p2, p3, p4, p5 = [
                random.randint(-1, 1) for unused_i in range(5)
            ]
            lines.append('%s,%s,%s,1,%.6f,%.6f,%.6f,%.6f,%s,%s,%s,%s,%s' %
                         (image_id, source, label, xmin, xmax, ymin, ymax, p1,
                          p2, p3, p4, p5))
    path = os.path.join(_output_dir(), fname)
    with open(path, 'w') as csv_f:
        csv_f.write('\n'.join(lines))
Example #3
0
def get_mako_template(tmpl_name):
  """Returns mako.lookup.Template object to use to render documentation.

  Args:
    tmpl_name: string, name of template to load.

  Returns:
    mako 'Template' instance that can be rendered.
  """
  tmpl_path = py_utils.get_tfds_path("scripts/templates/%s.mako.md" % tmpl_name)
  with tf.io.gfile.GFile(tmpl_path, "r") as tmpl_f:
    tmpl_content = tmpl_f.read()
  return mako.lookup.Template(tmpl_content, default_filters=["str", "trim"])