Exemple #1
0
def get_split(dataset_dir,file_pattern=None, reader=None):
  """Gets a dataset tuple with instructions for reading flowers.

  Args:
    split_name: A train/validation split name.
    dataset_dir: The base directory of the dataset sources.
    file_pattern: The file pattern to use when matching the dataset sources.
      It is assumed that the pattern contains a '%s' string so that the split
      name can be inserted.
    reader: The TensorFlow reader type.

  Returns:
    A `Dataset` namedtuple.

  Raises:
    ValueError: if `split_name` is not a valid train/validation split.
  """
  split_name = dataset_dir.split("_")[-1].split(".")[0]
  if split_name not in SPLITS_TO_SIZES:
    raise ValueError('split name %s was not recognized.' % split_name)


  file_pattern = dataset_dir

  # Allowing None in the signature so that dataset_factory can use the default.
  if reader is None:
    reader = tf.TFRecordReader

  keys_to_features = {
      'image/encoded': tf.FixedLenFeature((), tf.string, default_value=''),
      'image/format': tf.FixedLenFeature((), tf.string, default_value='png'),
      'image/class/label': tf.FixedLenFeature(
          [], tf.int64, default_value=tf.zeros([], dtype=tf.int64)),
  }

  items_to_handlers = {
      'image': slim.tfexample_decoder.Image(),
      'label': slim.tfexample_decoder.Tensor('image/class/label'),
  }

  decoder = slim.tfexample_decoder.TFExampleDecoder(
      keys_to_features, items_to_handlers)

  labels_to_names = None
  if dataset_utils.has_labels(dataset_dir):
    labels_to_names = dataset_utils.read_label_file(dataset_dir)

  return slim.dataset.Dataset(
      data_sources=file_pattern,
      reader=reader,
      decoder=decoder,
      num_samples=SPLITS_TO_SIZES[split_name],
      items_to_descriptions=_ITEMS_TO_DESCRIPTIONS,
      num_classes=_NUM_CLASSES,
      labels_to_names=labels_to_names)
    def get_split(self, split_name):
        file_pattern = self.dataset_name + '_' + split_name + '.tfrecord'
        file_pattern = os.path.join(self.dataset_storage_location,
                                    file_pattern)
        print("file path.." + file_pattern)
        reader = tf.TFRecordReader

        keys_to_features = {
            'image/encoded':
            tf.FixedLenFeature((), tf.string, default_value=''),
            'image/format':
            tf.FixedLenFeature((), tf.string, default_value='png'),
            'image/class/label':
            tf.FixedLenFeature([],
                               tf.int64,
                               default_value=tf.zeros([], dtype=tf.int64)),
        }

        items_to_handlers = {
            'image':
            slim.tfexample_decoder.Image(
                shape=[self.image_size, self.image_size, self.channels]),
            'label':
            slim.tfexample_decoder.Tensor('image/class/label'),
        }

        decoder = slim.tfexample_decoder.TFExampleDecoder(
            keys_to_features, items_to_handlers)

        labels_to_names = None
        label_file_name = self.dataset_name + '_labels.txt'
        if dataset_utils.has_labels(self.dataset_storage_location,
                                    label_file_name):
            labels_to_names = dataset_utils.read_label_file(
                self.dataset_storage_location, label_file_name)

        total_number_of_images = self.get_total_number_of_images(
            split_name, self.dataset_name)
        return slim.dataset.Dataset(
            data_sources=file_pattern,
            reader=reader,
            decoder=decoder,
            items_to_descriptions=self.dataset_description,
            num_classes=self.number_of_classes,
            num_samples=total_number_of_images,
            labels_to_names=labels_to_names)
def get_split(split_name, dataset_dir, file_pattern=None, reader=None):

    if split_name not in SPLITS_TO_SIZES:
        raise ValueError('split name %s was not in recognized.' % split_name)

    if not file_pattern:
        file_pattern = _FILE_PATTERN

    file_pattern = os.path.join(dataset_dir, file_pattern % split_name)

    if reader is None:
        reader = tf.TFRecordReader

    key_to_features = {
        'image/encoded':
        tf.FixedLenFeature((), tf.string, default_value=''),
        'image/label':
        tf.FixedLenFeature([],
                           tf.int64,
                           default_value=tf.zeros([], dtype=tf.int64)),
        'image/filename':
        tf.FixedLenFeature((), tf.string, default_value=''),
        'image/format':
        tf.FixedLenFeature((), tf.string, default_value='jpg')
    }

    items_to_handlers = {
        'image': slim.tfexample_decoder.Image('image/encoded'),
        'label': slim.tfexample_decoder.Tensor('image/label'),
        'filename': slim.tfexample_decoder.Tensor('image/filename')
    }

    decoder = slim.tfexample_decoder.TFExampleDecoder(key_to_features,
                                                      items_to_handlers)

    labels_to_name = None
    if dataset_utils.has_labels(dataset_dir):
        labels_to_name = dataset_utils.read_label_file(dataset_dir)

    return slim.dataset.Dataset(data_sources=file_pattern,
                                reader=reader,
                                decoder=decoder,
                                num_samples=SPLITS_TO_SIZES[split_name],
                                items_to_descriptions=_ITEMS_TO_DESCRIPTIONS,
                                num_classes=_NUM_CLASSES,
                                labels_to_names=labels_to_name)
def get_split(split_name, dataset_dir, file_pattern, reader, split_to_sizes,
              items_to_descriptions, num_classes):
    """Gets a dataset tuple with instructions for reading Pascal VOC dataset.

    Args:
      split_name: A train/test split name.
      dataset_dir: The base directory of the dataset sources.
      file_pattern: The file pattern to use when matching the dataset sources.
        It is assumed that the pattern contains a '%s' string so that the split
        name can be inserted.
      reader: The TensorFlow reader type.

    Returns:
      A `Dataset` namedtuple.

    Raises:
        ValueError: if `split_name` is not a valid train/test split.
    """
    if split_name not in split_to_sizes:
        raise ValueError('split name %s was not recognized.' % split_name)
    print(split_name)
    # file_pattern = os.path.join(dataset_dir, file_pattern % split_name)
    file_pattern = os.path.join(dataset_dir, file_pattern)
    print(file_pattern)
    # Allowing None in the signature so that dataset_factory can use the default.
    if reader is None:
        reader = tf.TFRecordReader
    # Features in Pascal VOC TFRecords.
    # 'images/label': int64_feature(label),
    # 'images/nc_roi': bytes_feature(nc_roi_data),
    # 'images/art_roi': bytes_feature(art_roi_data),
    # 'images/pv_roi': bytes_feature(pv_roi_data),
    # 'images/nc_patch': bytes_feature(nc_patch_data),
    # 'images/art_patch': bytes_feature(art_patch_data),
    # 'images/pv_patch': bytes_feature(pv_patch_data),
    # 'images/format': bytes_feature(image_format)}))
    keys_to_features = {
        'images/nc_roi': tf.FixedLenFeature((), tf.string, default_value=''),
        'images/art_roi': tf.FixedLenFeature((), tf.string, default_value=''),
        'images/pv_roi': tf.FixedLenFeature((), tf.string, default_value=''),
        'images/nc_patch': tf.FixedLenFeature((), tf.string, default_value=''),
        'images/art_patch': tf.FixedLenFeature((), tf.string,
                                               default_value=''),
        'images/pv_patch': tf.FixedLenFeature((), tf.string, default_value=''),
        'images/format': tf.FixedLenFeature((),
                                            tf.string,
                                            default_value='jpeg'),
        'images/label': tf.FixedLenFeature([1], tf.int64),
    }
    items_to_handlers = {
        'nc_roi':
        slim.tfexample_decoder.Image('images/nc_roi', 'images/format'),
        'art_roi':
        slim.tfexample_decoder.Image('images/art_roi', 'images/format'),
        'pv_roi':
        slim.tfexample_decoder.Image('images/pv_roi', 'images/format'),
        'nc_patch':
        slim.tfexample_decoder.Image('images/nc_patch', 'images/format'),
        'art_patch':
        slim.tfexample_decoder.Image('images/art_patch', 'images/format'),
        'pv_patch':
        slim.tfexample_decoder.Image('images/pv_patch', 'images/format'),
        'label':
        slim.tfexample_decoder.Tensor('images/label')
    }
    decoder = slim.tfexample_decoder.TFExampleDecoder(keys_to_features,
                                                      items_to_handlers)

    labels_to_names = None
    if dataset_utils.has_labels(dataset_dir):
        labels_to_names = dataset_utils.read_label_file(dataset_dir)
    # else:
    #     labels_to_names = create_readable_names_for_imagenet_labels()
    #     dataset_utils.write_label_file(labels_to_names, dataset_dir)

    return slim.dataset.Dataset(data_sources=file_pattern,
                                reader=reader,
                                decoder=decoder,
                                num_samples=split_to_sizes[split_name],
                                items_to_descriptions=items_to_descriptions,
                                num_classes=num_classes,
                                labels_to_names=labels_to_names)