(self)
Implements DatasetConverter.create_dataset_specification_and_records.
Implements DatasetConverter.create_dataset_specification_and_records.
Implements DatasetConverter . create_dataset_specification_and_records .
def create_dataset_specification_and_records(self):
    """Implements DatasetConverter.create_dataset_specification_and_records."""
    splits = self.get_splits()
    # Get the names of the classes assigned to each split.
    train_classes = splits['train']
    valid_classes = splits['valid']
    test_classes = splits['test']

    self.classes_per_split[learning_spec.Split.TRAIN] = len(train_classes)
    self.classes_per_split[learning_spec.Split.VALID] = len(valid_classes)
    self.classes_per_split[learning_spec.Split.TEST] = len(test_classes)

    imagelabels_path = os.path.join(self.data_root, 'imagelabels.mat')
    with tf.io.gfile.GFile(imagelabels_path, 'rb') as f:
      labels = loadmat(f)['labels'][0]
    filepaths = collections.defaultdict(list)
    for i, label in enumerate(labels):
      filepaths[label].append(
          os.path.join(self.data_root, 'jpg', 'image_{:05d}.jpg'.format(i + 1)))

    all_classes = list(
        itertools.chain(train_classes, valid_classes, test_classes))
    # Class IDs are constructed in such a way that
    #   - training class IDs lie in [0, num_train_classes),
    #   - validation class IDs lie in
    #     [num_train_classes, num_train_classes + num_validation_classes), and
    #   - test class IDs lie in
    #     [num_train_classes + num_validation_classes, num_classes).
    for class_id, class_label in enumerate(all_classes):
      logging.info('Creating record for class ID %d (%s)...', class_id,
                   class_label)
      # We encode the original ID's in the label.
      original_id = int(class_label[:self.ID_LEN])
      class_paths = filepaths[original_id]
      class_records_path = os.path.join(
          self.records_path, self.dataset_spec.file_pattern.format(class_id))
      self.class_names[class_id] = class_label
      self.images_per_class[class_id] = len(class_paths)
      # Create and write the tf.Record of the examples of this class.
      write_tfrecord_from_image_files(class_paths, class_id, class_records_path)
def create_dataset_specification_and_records ( self ) : splits = self . get_splits ( ) # Get the names of the classes assigned to each split. train_classes = splits [ 'train' ] valid_classes = splits [ 'valid' ] test_classes = splits [ 'test' ] self . classes_per_split [ learning_spec . Split . TRAIN ] = len ( train_classes ) self . classes_per_split [ learning_spec . Split . VALID ] = len ( valid_classes ) self . classes_per_split [ learning_spec . Split . TEST ] = len ( test_classes ) imagelabels_path = os . path . join ( self . data_root , 'imagelabels.mat' ) with tf . io . gfile . GFile ( imagelabels_path , 'rb' ) as f : labels = loadmat ( f ) [ 'labels' ] [ 0 ] filepaths = collections . defaultdict ( list ) for i , label in enumerate ( labels ) : filepaths [ label ] . append ( os . path . join ( self . data_root , 'jpg' , 'image_{:05d}.jpg' . format ( i + 1 ) ) ) all_classes = list ( itertools . chain ( train_classes , valid_classes , test_classes ) ) # Class IDs are constructed in such a way that #   - training class IDs lie in [0, num_train_classes), #   - validation class IDs lie in #     [num_train_classes, num_train_classes + num_validation_classes), and #   - test class IDs lie in #     [num_train_classes + num_validation_classes, num_classes). for class_id , class_label in enumerate ( all_classes ) : logging . info ( 'Creating record for class ID %d (%s)...' , class_id , class_label ) # We encode the original ID's in the label. original_id = int ( class_label [ : self . ID_LEN ] ) class_paths = filepaths [ original_id ] class_records_path = os . path . join ( self . records_path , self . dataset_spec . file_pattern . format ( class_id ) ) self . class_names [ class_id ] = class_label self . images_per_class [ class_id ] = len ( class_paths ) # Create and write the tf.Record of the examples of this class. write_tfrecord_from_image_files ( class_paths , class_id , class_records_path )