Python datasets.dataset_utils.bytes_feature() Examples
The following are 7
code examples of datasets.dataset_utils.bytes_feature().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
datasets.dataset_utils
, or try the search function
.
Example #1
Source File: convert_celeba.py From TwinGAN with Apache License 2.0 | 5 votes |
def _convert_to_example(filename, image_data, height, width, current_file_info, common_info): colorspace = 'RGB' channels = 3 image_format = 'JPEG' example = tf.train.Example(features=tf.train.Features(feature={ 'image/height': dataset_utils.int64_feature(height), 'image/width': dataset_utils.int64_feature(width), 'image/colorspace': dataset_utils.bytes_feature(colorspace), 'image/channels': dataset_utils.int64_feature(channels), 'image/format': dataset_utils.bytes_feature(image_format), 'image/filename': dataset_utils.bytes_feature(os.path.basename(filename)), 'image/encoded': dataset_utils.bytes_feature(image_data)})) return example
Example #2
Source File: convert_danbooru_data.py From TwinGAN with Apache License 2.0 | 5 votes |
def _convert_to_example(filename, image_buffer, height, width, current_file_info, common_info): """Build an Example proto for an example. Args: filename: string, path to an image file, e.g., '/path/to/example.JPG' image_buffer: string, JPEG encoding of RGB image height: integer, image height in pixels width: integer, image width in pixels current_file_info: equivalent to label: integer, identifier for the ground truth for the network common_info: a list of tags with format: ('type', 'ambiguous', 'count', 'name', 'id') Returns: Example proto """ colorspace = 'RGB' channels = 3 image_format = 'JPEG' human_readable_tags = DanbooruDataConverter._tag_to_human_readable(current_file_info,common_info) example = tf.train.Example(features=tf.train.Features(feature={ 'image/height': dataset_utils.int64_feature(height), 'image/width': dataset_utils.int64_feature(width), 'image/colorspace': dataset_utils.bytes_feature(colorspace), 'image/channels': dataset_utils.int64_feature(channels), 'image/class/label': dataset_utils.int64_feature(current_file_info), 'image/class/text': dataset_utils.bytes_feature(human_readable_tags), 'image/format': dataset_utils.bytes_feature(image_format), 'image/filename': dataset_utils.bytes_feature(os.path.basename(filename)), 'image/encoded': dataset_utils.bytes_feature(image_buffer)})) return example
Example #3
Source File: convert_image_only.py From TwinGAN with Apache License 2.0 | 5 votes |
def _convert_to_example(filename, image_data, height, width, current_file_info, common_info): colorspace = 'RGB' channels = 3 image_format = 'JPEG' example = tf.train.Example(features=tf.train.Features(feature={ 'image/colorspace': dataset_utils.bytes_feature(colorspace), 'image/channels': dataset_utils.int64_feature(channels), 'image/format': dataset_utils.bytes_feature(image_format), 'image/filename': dataset_utils.bytes_feature(os.path.basename(filename)), 'image/encoded': dataset_utils.bytes_feature(image_data), })) return example
Example #4
Source File: pascalvoc_to_tfrecords.py From MobileNet with Apache License 2.0 | 4 votes |
def _convert_to_example(image_data, labels, labels_text, bboxes, shape, difficult, truncated): """Build an Example proto for an image example. Args: image_data: string, JPEG encoding of RGB image; labels: list of integers, identifier for the ground truth; labels_text: list of strings, human-readable labels; bboxes: list of bounding boxes; each box is a list of integers; specifying [xmin, ymin, xmax, ymax]. All boxes are assumed to belong to the same label as the image label. shape: 3 integers, image shapes in pixels. Returns: Example proto """ xmin = [] ymin = [] xmax = [] ymax = [] for b in bboxes: assert len(b) == 4 # pylint: disable=expression-not-assigned [l.append(point) for l, point in zip([ymin, xmin, ymax, xmax], b)] # pylint: enable=expression-not-assigned image_format = b'JPEG' example = tf.train.Example(features=tf.train.Features(feature={ 'image/height': int64_feature(shape[0]), 'image/width': int64_feature(shape[1]), 'image/channels': int64_feature(shape[2]), 'image/shape': int64_feature(shape), 'image/object/bbox/xmin': float_feature(xmin), 'image/object/bbox/xmax': float_feature(xmax), 'image/object/bbox/ymin': float_feature(ymin), 'image/object/bbox/ymax': float_feature(ymax), 'image/object/bbox/label': int64_feature(labels), 'image/object/bbox/label_text': bytes_feature(labels_text), 'image/object/bbox/difficult': int64_feature(difficult), 'image/object/bbox/truncated': int64_feature(truncated), 'image/format': bytes_feature(image_format), 'image/encoded': bytes_feature(image_data)})) return example
Example #5
Source File: kitti_object_to_tfrecords.py From MobileNet with Apache License 2.0 | 4 votes |
def _process_image(directory, split, name): # Read the image file. filename = os.path.join(directory, 'image_2', name + '.png') image_data = tf.gfile.FastGFile(filename, 'r').read() # Get shape img = cv2.imread(filename) shape = np.shape(img) label_list = [] type_list = [] bbox_x1_list = [] bbox_y1_list = [] bbox_x2_list = [] bbox_y2_list = [] # If 'test' split, skip annotations if re.findall(r'train', split): # Read the txt annotation file. filename = os.path.join(directory, 'label_2', name + '.txt') with open(filename) as anno_file: objects = anno_file.readlines() for object in objects: obj_anno = object.split(' ') type_txt = obj_anno[0].encode('ascii') if type_txt in CLASSES: label_list.append(CLASSES[type_txt]) type_list.append(type_txt) # Bounding Box bbox_x1 = float(obj_anno[4]) bbox_y1 = float(obj_anno[5]) bbox_x2 = float(obj_anno[6]) bbox_y2 = float(obj_anno[7]) bbox_x1_list.append(bbox_x1) bbox_y1_list.append(bbox_y1) bbox_x2_list.append(bbox_x2) bbox_y2_list.append(bbox_y2) image_format = b'PNG' example = tf.train.Example(features=tf.train.Features(feature={ 'image/encoded': bytes_feature(image_data), 'image/height': int64_feature(shape[0]), 'image/width': int64_feature(shape[1]), 'image/channels': int64_feature(shape[2]), 'image/shape': int64_feature(shape), 'image/object/bbox/xmin': float_feature(bbox_x1_list), 'image/object/bbox/xmax': float_feature(bbox_x2_list), 'image/object/bbox/ymin': float_feature(bbox_y1_list), 'image/object/bbox/ymax': float_feature(bbox_y2_list), 'image/object/bbox/label': int64_feature(label_list), 'image/object/bbox/label_text': bytes_feature(type_list), })) return example
Example #6
Source File: convert_anime_faces_from_object_detection.py From TwinGAN with Apache License 2.0 | 4 votes |
def _convert_to_example(filename, image_data, height, width, current_file_info, shared_info): colorspace = 'RGB' channels = 3 image_format = 'JPEG' (x_expanded, y_expanded, w_expanded, h_expanded, image_w, image_h, tags_id, original_image, face_xywh) = current_file_info feature = { 'image/x': dataset_utils.int64_feature(x_expanded), 'image/y': dataset_utils.int64_feature(y_expanded), 'image/height': dataset_utils.int64_feature(h_expanded), 'image/width': dataset_utils.int64_feature(w_expanded), 'image/face_xywh': dataset_utils.float_feature(face_xywh), # 'image/left_eye_xywh': dataset_utils.float_feature(left_eye_xywh), # 'image/right_eye_xywh': dataset_utils.float_feature(right_eye_xywh), # 'image/mouth_xywh': dataset_utils.float_feature(mouth_xywh), 'image/colorspace': dataset_utils.bytes_feature(colorspace), 'image/channels': dataset_utils.int64_feature(channels), 'image/format': dataset_utils.bytes_feature(image_format), 'image/filename': dataset_utils.bytes_feature(os.path.basename(filename)), 'image/encoded': dataset_utils.bytes_feature(image_data), # Encoding original takes up too much space. Not recommended. # 'image/original': dataset_utils.bytes_feature(original_image), } example = tf.train.Example(features=tf.train.Features(feature=feature)) return example ########################### # Other utility functions # ########################### # Inherits from parent class. ######## # Main # ######## # Inherits from parent class. ################ # Helper class # ################
Example #7
Source File: pascalvoc_to_tfrecords.py From SSD_tensorflow_VOC with Apache License 2.0 | 4 votes |
def _convert_to_example(image_data, labels, labels_text, bboxes, shape, difficult, truncated,name): """Build an Example proto for an image example. Args: image_data: string, JPEG encoding of RGB image; labels: list of integers, identifier for the ground truth; labels_text: list of strings, human-readable labels; bboxes: list of bounding boxes; each box is a list of integers; specifying [xmin, ymin, xmax, ymax]. All boxes are assumed to belong to the same label as the image label. shape: 3 integers, image shapes in pixels. Returns: Example proto """ xmin = [] ymin = [] xmax = [] ymax = [] for b in bboxes: assert len(b) == 4 # pylint: disable=expression-not-assigned [l.append(point) for l, point in zip([ymin, xmin, ymax, xmax], b)] # pylint: enable=expression-not-assigned image_format = b'JPEG' example = tf.train.Example(features=tf.train.Features(feature={ 'image/height': int64_feature(shape[0]), 'image/width': int64_feature(shape[1]), 'image/channels': int64_feature(shape[2]), 'image/shape': int64_feature(shape), 'image/object/bbox/xmin': float_feature(xmin), 'image/object/bbox/xmax': float_feature(xmax), 'image/object/bbox/ymin': float_feature(ymin), 'image/object/bbox/ymax': float_feature(ymax), 'image/object/bbox/label': int64_feature(labels), 'image/object/bbox/label_text': bytes_feature(labels_text), 'image/object/bbox/difficult': int64_feature(difficult), 'image/object/bbox/truncated': int64_feature(truncated), 'image/format': bytes_feature(image_format), 'image/filename': bytes_feature(name.encode('utf-8')), 'image/encoded': bytes_feature(image_data)})) return example