def _get_split(file_pattern, num_samples, num_views, image_size, vox_size): """Get dataset.Dataset for the given dataset file pattern and properties.""" # A dictionary from TF-Example keys to tf.FixedLenFeature instance. keys_to_features = { 'image': tf.FixedLenFeature( shape=[num_views, image_size, image_size, 3], dtype=tf.float32, default_value=None), 'mask': tf.FixedLenFeature( shape=[num_views, image_size, image_size, 1], dtype=tf.float32, default_value=None), 'vox': tf.FixedLenFeature( shape=[vox_size, vox_size, vox_size, 1], dtype=tf.float32, default_value=None), } items_to_handler = { 'image': tfexample_decoder.Tensor( 'image', shape=[num_views, image_size, image_size, 3]), 'mask': tfexample_decoder.Tensor( 'mask', shape=[num_views, image_size, image_size, 1]), 'vox': tfexample_decoder.Tensor( 'vox', shape=[vox_size, vox_size, vox_size, 1]) } decoder = tfexample_decoder.TFExampleDecoder( keys_to_features, items_to_handler) return dataset.Dataset( data_sources=file_pattern, reader=tf.TFRecordReader, decoder=decoder, num_samples=num_samples, items_to_descriptions=_ITEMS_TO_DESCRIPTIONS)
def _create_tfrecord_dataset(tmpdir): if not gfile.Exists(tmpdir): gfile.MakeDirs(tmpdir) data_sources = test_utils.create_tfrecord_files(tmpdir, num_files=1) keys_to_features = { 'image/encoded': parsing_ops.FixedLenFeature( shape=(), dtype=dtypes.string, default_value=''), 'image/format': parsing_ops.FixedLenFeature( shape=(), dtype=dtypes.string, default_value='jpeg'), 'image/class/label': parsing_ops.FixedLenFeature( shape=[1], dtype=dtypes.int64, default_value=array_ops.zeros( [1], dtype=dtypes.int64)) } items_to_handlers = { 'image': tfexample_decoder.Image(), 'label': tfexample_decoder.Tensor('image/class/label'), } decoder = tfexample_decoder.TFExampleDecoder(keys_to_features, items_to_handlers) return dataset.Dataset( data_sources=data_sources, reader=io_ops.TFRecordReader, decoder=decoder, num_samples=100, items_to_descriptions=None)
def create_dataset(self, data_source): keys_to_features = { 'image/encoded': tf.FixedLenFeature(shape=(), dtype=tf.string, default_value=''), 'image/format': tf.FixedLenFeature(shape=(), dtype=tf.string, default_value='png'), 'image/object/bbox/xmin': tf.FixedLenFeature(shape=(), dtype= tf.string, default_value=''), 'image/object/bbox/xmax': tf.FixedLenFeature(shape=(), dtype= tf.string, default_value=''), 'image/object/bbox/ymin': tf.FixedLenFeature(shape=(), dtype= tf.string, default_value=''), 'image/object/bbox/ymax': tf.FixedLenFeature(shape=(), dtype= tf.string, default_value=''), 'image/object/bbox/label': tf.FixedLenFeature(shape=(), dtype = tf.string, default_value=''), 'image/object/size': tf.FixedLenFeature(shape=(), dtype = tf.int64, default_value=0) } items_to_handlers = { 'image': tfexample_decoder.Image(), 'xmin': tfexample_decoder.Tensor('image/object/bbox/xmin'), 'xmax': tfexample_decoder.Tensor('image/object/bbox/xmax'), 'ymin': tfexample_decoder.Tensor('image/object/bbox/ymin'), 'ymax': tfexample_decoder.Tensor('image/object/bbox/ymax'), #'bbox': tfexample_decoder.BoundingBox(prefix='image/object/bbox/'), 'label': tfexample_decoder.Tensor('image/object/bbox/label'), 'size': tfexample_decoder.Tensor('image/object/size') } decoder = tfexample_decoder.TFExampleDecoder(keys_to_features, items_to_handlers) return dataset.Dataset(data_sources=data_source, reader = tf.TFRecordReader, decoder=decoder, num_samples = 1, items_to_descriptions=None)
def get_split(split_name='train', dataset_dir=None, num_classes_per_attribute=None): """Gets a dataset tuple with instructions for reading 2D shapes data. Args: split_name: A train/test split name. dataset_dir: The base directory of the dataset sources. num_classes_per_attribute: The number of labels for the classfication problem corresponding to each attribute. For example, if the first attribute is "shape" and there are three possible shapes, then then provide a value 3 in the first index, and so on. Returns: A `Dataset` namedtuple. metadata: A dictionary with some metadata about the dataset we just constructed. Raises: ValueError: if `split_name` is not a valid train/test split. """ if split_name not in _SPLITS_TO_SIZES: raise ValueError('split name %s was not recognized.' % split_name) if num_classes_per_attribute is None: num_classes_per_attribute = _NUM_CLASSES_PER_ATTRIBUTE if dataset_dir is None: dataset_dir = _DATASET_DIR file_pattern = os.path.join(dataset_dir, _FILE_PATTERN % (_SPLIT_TYPE, split_name)) keys_to_features = { 'image/encoded': tf.FixedLenFeature((), tf.string, default_value=''), 'image/format': tf.FixedLenFeature((), tf.string, default_value='raw'), 'labels': tf.FixedLenFeature([len(num_classes_per_attribute)], tf.int64), 'latents': tf.FixedLenFeature([_NUM_LATENTS], tf.float32), } items_to_handlers = { 'image': tfexample_decoder.Image(shape=[64, 64, 3]), 'labels': tfexample_decoder.Tensor('labels'), 'latents': tfexample_decoder.Tensor('latents'), } decoder = tfexample_decoder.TFExampleDecoder(keys_to_features, items_to_handlers) metadata = { 'num_classes_per_attribute': num_classes_per_attribute, 'split_type': _SPLIT_TYPE } return dataset.Dataset( data_sources=file_pattern, reader=tf.TFRecordReader, decoder=decoder, num_samples=_SPLITS_TO_SIZES[split_name], items_to_descriptions=_ITEMS_TO_DESCRIPTIONS), metadata
def get_split(split_name, dataset_dir=None): """Gets a dataset tuple with instructions for reading cifar100. Args: split_name: A train/test split name. dataset_dir: The base directory of the dataset sources. Returns: A `Dataset` namedtuple. Image tensors are integers in [0, 255]. Raises: ValueError: if `split_name` is not a valid train/test split. """ if split_name not in _SPLITS_TO_SIZES: raise ValueError('split name %s was not recognized.' % split_name) file_pattern = os.path.join(dataset_dir, _FILE_PATTERN % split_name) keys_to_features = { 'image/encoded': tf.FixedLenFeature((), tf.string, default_value=''), 'image/format': tf.FixedLenFeature((), tf.string, default_value=''), 'image/class/label': tf.FixedLenFeature([1], tf.int64, default_value=tf.zeros([1], dtype=tf.int64)), 'image/class/fine_label': tf.FixedLenFeature([1], tf.int64, default_value=tf.zeros([1], dtype=tf.int64)), } if split_name == 'train': items_to_handlers = { 'image': tfexample_decoder.Image(shape=[32, 32, 3]), 'label': tfexample_decoder.Tensor('image/class/label'), } else: items_to_handlers = { 'image': tfexample_decoder.Image(shape=[32, 32, 3]), 'label': tfexample_decoder.Tensor('image/class/fine_label'), } decoder = tfexample_decoder.TFExampleDecoder(keys_to_features, items_to_handlers) return dataset.Dataset(data_sources=file_pattern, reader=tf.TFRecordReader, decoder=decoder, num_samples=_SPLITS_TO_SIZES[split_name], num_classes=_NUM_CLASSES, items_to_descriptions=_ITEMS_TO_DESCRIPTIONS)
def _create_tfrecord_dataset(config): """Create tfrecord dataset for DatasetDataProvider. Args: config: an instance of AdsExample proto. Returns: dataset: a slim.data.dataset.Dataset instance. """ def _handle_frame_features_wrapper(keys_to_tensors): return _handle_frame_features(keys_to_tensors, 'video/features', config.feature_dims) def _handle_climax_features_wrapper(keys_to_tensors): return _handle_frame_features(keys_to_tensors, 'video/climax_features', 1) def _handle_climax_predictions_wrapper(keys_to_tensors): return _handle_frame_features(keys_to_tensors, 'video/climax_predictions', 1) def _handle_common_object_features_wrapper(keys_to_tensors): return _handle_frame_features(keys_to_tensors, 'video/common_object_features', config.common_object_feature_dims) def _handle_place_features_wrapper(keys_to_tensors): return _handle_frame_features(keys_to_tensors, 'video/place_features', config.place_feature_dims) def _handle_emotic_features_wrapper(keys_to_tensors): return _handle_frame_features(keys_to_tensors, 'video/emotic_features', config.emotic_feature_dims) def _handle_affectnet_features_wrapper(keys_to_tensors): return _handle_frame_features(keys_to_tensors, 'video/affectnet_features', config.affectnet_feature_dims) def _handle_shot_boundary_features_wrapper(keys_to_tensors): return _handle_frame_features(keys_to_tensors, 'video/shot_boundary_features', config.shot_boundary_feature_dims) def _handle_optical_flow_features_wrapper(keys_to_tensors): return _handle_frame_features(keys_to_tensors, 'video/optical_flow_features', config.optical_flow_feature_dims) def _handle_audio_features_wrapper(keys_to_tensors): return _handle_frame_features(keys_to_tensors, 'video/audio_features', config.audio_feature_dims) item_handler_frame_features = tfexample_decoder.ItemHandlerCallback( keys=['video/n_frames', 'video/features'], func=_handle_frame_features_wrapper) item_handler_climax_features = tfexample_decoder.ItemHandlerCallback( keys=['video/n_frames', 'video/climax_features'], func=_handle_climax_features_wrapper) item_handler_climax_predictions = tfexample_decoder.ItemHandlerCallback( keys=['video/n_frames', 'video/climax_predictions'], func=_handle_climax_predictions_wrapper) item_handler_common_object_features = tfexample_decoder.ItemHandlerCallback( keys=['video/n_frames', 'video/common_object_features'], func=_handle_common_object_features_wrapper) item_handler_place_features = tfexample_decoder.ItemHandlerCallback( keys=['video/n_frames', 'video/place_features'], func=_handle_place_features_wrapper) item_handler_emotic_features = tfexample_decoder.ItemHandlerCallback( keys=['video/n_frames', 'video/emotic_features'], func=_handle_emotic_features_wrapper) item_handler_affectnet_features = tfexample_decoder.ItemHandlerCallback( keys=['video/n_frames', 'video/affectnet_features'], func=_handle_affectnet_features_wrapper) item_handler_shot_boundary_features = tfexample_decoder.ItemHandlerCallback( keys=['video/n_frames', 'video/shot_boundary_features'], func=_handle_shot_boundary_features_wrapper) item_handler_optical_flow_features = tfexample_decoder.ItemHandlerCallback( keys=['video/n_frames', 'video/optical_flow_features'], func=_handle_optical_flow_features_wrapper) item_handler_audio_features = tfexample_decoder.ItemHandlerCallback( keys=['video/n_frames', 'video/audio_features'], func=_handle_audio_features_wrapper) keys_to_features = { 'video/source_id': tf.FixedLenFeature(shape=(), dtype=tf.string, default_value=''), 'video/n_frames': tf.FixedLenFeature((), tf.int64, default_value=0), 'video/features': tf.VarLenFeature(tf.float32), 'video/climax_features': tf.VarLenFeature(tf.float32), 'video/climax_predictions': tf.VarLenFeature(tf.float32), 'video/common_object_features': tf.VarLenFeature(tf.float32), 'video/place_features': tf.VarLenFeature(tf.float32), 'video/emotic_features': tf.VarLenFeature(tf.float32), 'video/affectnet_features': tf.VarLenFeature(tf.float32), 'video/shot_boundary_features': tf.VarLenFeature(tf.float32), 'video/optical_flow_features': tf.VarLenFeature(tf.float32), 'video/audio_features': tf.VarLenFeature(tf.float32), 'anno/topic': tf.FixedLenFeature((), tf.int64), 'anno/sentiment': tf.FixedLenFeature((), tf.int64), 'anno/sentiment_list': tf.FixedLenFeature([config.sentiment_num_classes], tf.float32), } items_to_handlers = { 'video_id': tfexample_decoder.Tensor('video/source_id'), 'n_frames': tfexample_decoder.Tensor('video/n_frames'), 'topic': tfexample_decoder.Tensor('anno/topic'), 'sentiment': tfexample_decoder.Tensor('anno/sentiment'), 'frame_features': item_handler_frame_features, 'climax_features': item_handler_climax_features, 'climax_predictions': item_handler_climax_predictions, 'common_object_features': item_handler_common_object_features, 'place_features': item_handler_place_features, 'emotic_features': item_handler_emotic_features, 'affectnet_features': item_handler_affectnet_features, 'shot_boundary_features': item_handler_shot_boundary_features, 'optical_flow_features': item_handler_optical_flow_features, 'audio_features': item_handler_audio_features, 'sentiment_list': tfexample_decoder.Tensor('anno/sentiment_list'), } #if config.use_sent_list: # keys_to_features['anno/sentiment_list'] = tf.FixedLenFeature([config.sentiment_num_classes], tf.float32), # items_to_handlers['sentiment_list'] = tfexample_decoder.Tensor('anno/sentiment_list') decoder = tfexample_decoder.TFExampleDecoder(keys_to_features, items_to_handlers) input_paths = [ config.input_path[i] for i in xrange(len(config.input_path)) ] return dataset.Dataset(data_sources=input_paths, reader=tf.TFRecordReader, decoder=decoder, num_samples=config.num_examples, items_to_descriptions=None)
def get_split(split_name='train', split_type="iid", dataset_dir=None, image_length=64, num_classes_per_attribute=None): """Gets a dataset tuple with instructions for reading 2D shapes data. Args: split_name: A train/test split name. split_type: str, type of split being loaded "iid" or "comp" dataset_dir: The base directory of the dataset sources. num_classes_per_attribute: The number of labels for the classfication problem corresponding to each attribute. For example, if the first attribute is "shape" and there are three possible shapes, then then provide a value 3 in the first index, and so on. Returns: A `Dataset` namedtuple. metadata: A dictionary with some metadata about the dataset we just constructed. Raises: ValueError: if `split_name` is not a valid train/test split. """ if split_name not in _SPLITS_TO_SIZES: raise ValueError('split name %s was not recognized.' % split_name) if split_type is not "iid": raise ValueError("Only IID split available for CelebA.") if num_classes_per_attribute is None: num_classes_per_attribute = _NUM_CLASSES_PER_ATTRIBUTE if dataset_dir is None or dataset_dir == '': dataset_dir = _DATASET_DIR # Load attribute label map file. label_map_json = os.path.join(dataset_dir, 'attribute_label_map.json') file_pattern = os.path.join(dataset_dir, _FILE_PATTERN % split_name) tf.logging.info('Loading from %s file.' % (file_pattern)) keys_to_features = { 'image/encoded': tf.FixedLenFeature((), tf.string, default_value=''), 'image/format': tf.FixedLenFeature((), tf.string, default_value='raw'), 'image/labels': tf.FixedLenFeature([len(num_classes_per_attribute)], tf.int64), } # TODO(vrama): See # https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/slim/python/slim/data/tfexample_decoder.py#L270 # For where changes would need to be made to preprocess the images which # get loaded. items_to_handlers = { 'image': ImageDecodeProcess(shape=[218, 178, 3], image_length=64), 'labels': tfexample_decoder.Tensor('image/labels'), } decoder = tfexample_decoder.TFExampleDecoder(keys_to_features, items_to_handlers) metadata = { 'num_classes_per_attribute': num_classes_per_attribute, 'split_type': _SPLIT_TYPE, 'label_map_json': label_map_json, } return dataset.Dataset( data_sources=file_pattern, reader=tf.TFRecordReader, decoder=decoder, num_samples=_SPLITS_TO_SIZES[split_name], items_to_descriptions=_ITEMS_TO_DESCRIPTIONS), metadata