def _build_example(self, row, amenities, url): """ Builds an example by building a map of Proto features. Args: row: Dictionary with row information and type amenities: List of amenities of the example url: URL of the image to include """ # Map features into corresponding types feature_dict = {name: map_feature(row[name]['value'], row[name]['type']) for name, info in row.items()} # Create Sparse Column for the amenities of the row feature_dict.update({'amenities': bytes_feature(amenities)}) # Load image from url decoded_image, height, width = self.image_from_url(url, jpeg=True) # Add image metadata feature_dict.update({ 'image': bytes_feature(decoded_image), 'height': int64_feature(height), 'width': int64_feature(width), 'path': bytes_feature(url), 'format': bytes_feature('JPEG'), 'colorspace': bytes_feature('RGB') }) # Build example return tf.train.Example(features=tf.train.Features(feature=feature_dict)) # noqa
def build_examples(self, index): row = self.features[index, :] feature_dict = {} for i in range(self.features.shape[1]): feature_dict.update({str(i): float64_feature(row[i])}) feature_dict.update({'id': int64_feature(int(self.ids[index]))}) feature_dict.update({'class': int64_feature(int(self.labels[index]))}) return [ tf.train.Example(features=tf.train.Features(feature=feature_dict)) ] # noqa
def build_examples(self, index): # Get row i, subset = index img = self.train_data[i, ...] \ if subset in [DataMode.TRAINING, DataMode.VALIDATION] \ else self.test_data[i, ...] label = self.train_labels[i, ...] \ if subset in [DataMode.TRAINING, DataMode.VALIDATION] \ else self.test_labels[i, ...] # Fill features feature_dict = { 'image': bytes_feature(self.process_image_bytes(img)), 'label': int64_feature(int(label)), 'colorspace': bytes_feature('RGB') } # Add wide and deep pixel features for i in range(self.height): for j in range(self.width): feat_bytes = bytes_feature(str(img[i, j])) feat_float = float64_feature(float(img[i, j])) feature_dict.update({self._get_pixel_name(i, j): feat_bytes}) feature_dict.update( {self._get_pixel_name(i, j) + '_num': feat_float}) return [ tf.train.Example(features=tf.train.Features(feature=feature_dict)) ] # noqa
def build_examples(self, index): feature_dict = { 'image': bytes_feature(self.process_image_bytes(self.x[index, ...])), 'label': int64_feature(int(self.y[index])), } return [ tf.train.Example(features=tf.train.Features(feature=feature_dict)) ]
def build_examples(self, index): # Get row i, subset = index i = int(i) img = self.train_data[i, ...] \ if subset in [DataMode.TRAINING, DataMode.VALIDATION] \ else self.test_data[i, ...] label = self.train_labels[i, ...] \ if subset in [DataMode.TRAINING, DataMode.VALIDATION] \ else self.test_labels[i, ...] # Fill features feature_dict = { 'image': bytes_feature(self.process_image_bytes(img)), 'label': int64_feature(int(label)), 'colorspace': bytes_feature('RGB') } return [tf.train.Example(features=tf.train.Features(feature=feature_dict))] # noqa