(self)
return tfds.core.DatasetInfo(
        builder=self,
        description='Meta-Dataset data sources.',
        features=tfds.features.FeaturesDict({
            'image': tfds.features.Image(encoding_format='jpeg'),
            'format': tfds.features.Text(),
            'filename': tfds.features.Text(),
            'label': tfds.features.ClassLabel(num_classes=len(class_names)),
            'class_name': tfds.features.Text(),
        }),
        metadata=tfds.core.MetadataDict(
            meta_split_slices=meta_split_slices,
            relative_class_slices=relative_class_slices,
            dataset_specs=dataset_specs,
            class_names=class_names,
            total_num_examples=total_num_examples,
            class_slices=class_slices,
        ),
        # This is important, since we rely on examples of the same class being
        # contiguous to build class-specific datasets with the TFDS slicing API.
        disable_shuffling=True,
        supervised_keys=('image', 'label'),
        homepage='https://github.com/google-research/meta-dataset',
        citation=constants.CITATION,
    )
Returns the dataset metadata.
Returns the dataset metadata.
Returns the dataset metadata .
def _info(self):
    """Returns the dataset metadata."""
    dataset_spec_prefixes = self.builder_config.dataset_spec_prefixes
    dataset_specs = {}
    meta_split_slices = {}
    relative_class_slices = {}
    class_names = None
    total_num_examples = None

    for version, dataset_spec_prefix in dataset_spec_prefixes.items():
      file_path = os.path.join(DATASET_SPECS_DIR,
                               f'{dataset_spec_prefix}_dataset_spec.json')

      dataset_spec_dict = json.loads(tfds.core.as_path(file_path).read_text())
      # For ILSVRC2012, slicing entire meta-splits (i.e. "batch" training)
      # is greatly simplified if we adopt V1's label-to-name mapping. For V2
      # this doesn't change anything, since all classes are in the meta-training
      # split, but for V1 this means that we can access any meta-split with only
      # one slicing instruction.
      if dataset_spec_prefix == 'ilsvrc_2012_v2':
        dataset_spec_dict['class_names'] = dataset_specs['v1']['class_names']
      dataset_specs[version] = dataset_spec_dict
      dataset_spec = dataset_spec_lib.as_dataset_spec(dataset_spec_dict)

      # Compute start and stop indices of (relative) class-level slices in the
      # data source.
      meta_split_class_ids = {
          meta_split: dataset_spec.get_classes(getattr(learning_spec.Split,
                                                       meta_split.upper()))
          for meta_split in ('train', 'valid', 'test')
      }
      images_per_class = {
          meta_split: [dataset_spec.get_total_images_per_class(class_id)
                       for class_id in class_ids]
          for meta_split, class_ids in meta_split_class_ids.items()
      }
      cumulative_per_class = np.cumsum(
          [0] + sum(images_per_class.values(), [])).tolist()
      start_stop_per_class = zip(cumulative_per_class[:-1],
                                 cumulative_per_class[1:])
      class_slices = dict(enumerate(start_stop_per_class))
      relative_class_slices[version] = {
          meta_split: {i_rel: class_slices[i_abs] for i_rel, i_abs in
                       enumerate(class_ids)}
          for meta_split, class_ids in meta_split_class_ids.items()
      }

      # Compute start and stop indices of split-level slices in the data source.
      images_per_split = {k: sum(v) for k, v in images_per_class.items()}
      cumulative_per_meta_split = np.cumsum(
          [0] + list(images_per_split.values())).tolist()
      start_stop_per_meta_split = zip(cumulative_per_meta_split[:-1],
                                      cumulative_per_meta_split[1:])
      meta_split_slices[version] = {
          meta_split: (None if stop == start else (start, stop))
          for meta_split, (start, stop) in zip(meta_split_class_ids.keys(),
                                               start_stop_per_meta_split)
      }

      # Check for consistency between dataset specifications of different
      # versions.
      if total_num_examples and cumulative_per_class[-1] != total_num_examples:
        raise ValueError('dataset specifications have different numbers of '
                         'examples')
      total_num_examples = total_num_examples or cumulative_per_class[-1]

      if class_names and list(dataset_spec.class_names.values()) != class_names:
        raise ValueError('dataset specifications have different classes')
      class_names = class_names or list(dataset_spec.class_names.values())

    return tfds.core.DatasetInfo(
        builder=self,
        description='Meta-Dataset data sources.',
        features=tfds.features.FeaturesDict({
            'image': tfds.features.Image(encoding_format='jpeg'),
            'format': tfds.features.Text(),
            'filename': tfds.features.Text(),
            'label': tfds.features.ClassLabel(num_classes=len(class_names)),
            'class_name': tfds.features.Text(),
        }),
        metadata=tfds.core.MetadataDict(
            meta_split_slices=meta_split_slices,
            relative_class_slices=relative_class_slices,
            dataset_specs=dataset_specs,
            class_names=class_names,
            total_num_examples=total_num_examples,
            class_slices=class_slices,
        ),
        # This is important, since we rely on examples of the same class being
        # contiguous to build class-specific datasets with the TFDS slicing API.
        disable_shuffling=True,
        supervised_keys=('image', 'label'),
        homepage='https://github.com/google-research/meta-dataset',
        citation=constants.CITATION,
    )
def _info ( self ) : dataset_spec_prefixes = self . builder_config . dataset_spec_prefixes dataset_specs = { } meta_split_slices = { } relative_class_slices = { } class_names = None total_num_examples = None for version , dataset_spec_prefix in dataset_spec_prefixes . items ( ) : file_path = os . path . join ( DATASET_SPECS_DIR , f'{dataset_spec_prefix}_dataset_spec.json' ) dataset_spec_dict = json . loads ( tfds . core . as_path ( file_path ) . read_text ( ) ) # For ILSVRC2012, slicing entire meta-splits (i.e. "batch" training) # is greatly simplified if we adopt V1's label-to-name mapping. For V2 # this doesn't change anything, since all classes are in the meta-training # split, but for V1 this means that we can access any meta-split with only # one slicing instruction. if dataset_spec_prefix == 'ilsvrc_2012_v2' : dataset_spec_dict [ 'class_names' ] = dataset_specs [ 'v1' ] [ 'class_names' ] dataset_specs [ version ] = dataset_spec_dict dataset_spec = dataset_spec_lib . as_dataset_spec ( dataset_spec_dict ) # Compute start and stop indices of (relative) class-level slices in the # data source. meta_split_class_ids = { meta_split : dataset_spec . get_classes ( getattr ( learning_spec . Split , meta_split . upper ( ) ) ) for meta_split in ( 'train' , 'valid' , 'test' ) } images_per_class = { meta_split : [ dataset_spec . get_total_images_per_class ( class_id ) for class_id in class_ids ] for meta_split , class_ids in meta_split_class_ids . items ( ) } cumulative_per_class = np . cumsum ( [ 0 ] + sum ( images_per_class . values ( ) , [ ] ) ) . tolist ( ) start_stop_per_class = zip ( cumulative_per_class [ : - 1 ] , cumulative_per_class [ 1 : ] ) class_slices = dict ( enumerate ( start_stop_per_class ) ) relative_class_slices [ version ] = { meta_split : { i_rel : class_slices [ i_abs ] for i_rel , i_abs in enumerate ( class_ids ) } for meta_split , class_ids in meta_split_class_ids . items ( ) } # Compute start and stop indices of split-level slices in the data source. images_per_split = { k : sum ( v ) for k , v in images_per_class . items ( ) } cumulative_per_meta_split = np . cumsum ( [ 0 ] + list ( images_per_split . values ( ) ) ) . tolist ( ) start_stop_per_meta_split = zip ( cumulative_per_meta_split [ : - 1 ] , cumulative_per_meta_split [ 1 : ] ) meta_split_slices [ version ] = { meta_split : ( None if stop == start else ( start , stop ) ) for meta_split , ( start , stop ) in zip ( meta_split_class_ids . keys ( ) , start_stop_per_meta_split ) } # Check for consistency between dataset specifications of different # versions. if total_num_examples and cumulative_per_class [ - 1 ] != total_num_examples : raise ValueError ( 'dataset specifications have different numbers of ' 'examples' ) total_num_examples = total_num_examples or cumulative_per_class [ - 1 ] if class_names and list ( dataset_spec . class_names . values ( ) ) != class_names : raise ValueError ( 'dataset specifications have different classes' ) class_names = class_names or list ( dataset_spec . class_names . values ( ) ) return tfds . core . DatasetInfo ( builder = self , description = 'Meta-Dataset data sources.' , features = tfds . features . FeaturesDict ( { 'image' : tfds . features . Image ( encoding_format = 'jpeg' ) , 'format' : tfds . features . Text ( ) , 'filename' : tfds . features . Text ( ) , 'label' : tfds . features . ClassLabel ( num_classes = len ( class_names ) ) , 'class_name' : tfds . features . Text ( ) , } ) , metadata = tfds . core . MetadataDict ( meta_split_slices = meta_split_slices , relative_class_slices = relative_class_slices , dataset_specs = dataset_specs , class_names = class_names , total_num_examples = total_num_examples , class_slices = class_slices , ) , # This is important, since we rely on examples of the same class being # contiguous to build class-specific datasets with the TFDS slicing API. disable_shuffling = True , supervised_keys = ( 'image' , 'label' ) , homepage = 'https://github.com/google-research/meta-dataset' , citation = constants . CITATION , )