Exemple #1
0
  def set_features_and_args_from_config(self, coco_config):
    """Set features and arguments based on COCO config."""
    if coco_config == KEYPOINTS:
      feature_names = ['image', 'person_keypoints', 'person_boxes']
    elif coco_config == BOXES:
      feature_names = ['image', 'boxes', 'box_labels']
    elif coco_config == MSEG:
      feature_names = self.MSEG_FEATURE_NAMES + ['instance_segmentation']
    elif coco_config == ALL:
      feature_names = self.MSEG_FEATURE_NAMES + [
          'person_keypoints', 'person_boxes', 'boxes', 'box_labels',
          'instance_segmentation'
      ]
    else:
      raise ValueError(f'COCO config {coco_config} not valid!')

    feature_args = {}
    if 'person_keypoints' in feature_names:
      feature_args['person_keypoints'] = dict(
          num_keypoints=len(COCO_KEYPOINT_LABELS))

    if 'box_labels' in feature_names:
      feature_args['box_labels'] = dict(num_box_labels=len(COCO_BOX_LABELS))
    self.feature_utils = fids_features.FeatureUtils(feature_args)
    self.feature_names = feature_names

    missing_features = [
        feature for feature in COCO_POSSIBLY_MISSING_FEATURES
        if feature in feature_names
    ]
    if missing_features:
      self.splits_with_missing_features = {
          'train': missing_features,
          'validation': missing_features,
      }
Exemple #2
0
    def __init__(self,
                 name,
                 config_name,
                 feature_names,
                 splits,
                 splits_with_missing_features=None,
                 feature_args=None):
        """Constructor.

    Args:
      name: name of the dataset.
      config_name: name of the configuration of the dataset
      feature_names: list of features available in this dataset.
      splits: list of splits available in this dataset.
      splits_with_missing_features: Dictionary which maps each split to a list
        of feature_names which may be missing. By default, a missing feature
        will thow an error during dataset creation.
      feature_args: Dictionary, mapping feature_names to named arguments for
          for each feature. Example:
              feature_args={'box_labels': {'num_box_labels': 5}} See TfdsTypes
                in the fids_features module for which feature_name
                consumes which arguments.
    """
        self.name = name
        self.config_name = config_name
        self.feature_utils = fids_features.FeatureUtils(feature_args)
        self.feature_names = feature_names  # Validation depends on feature_utils
        self.splits = splits
        self.splits_with_missing_features = splits_with_missing_features

        # Set to positive value during debugging to limit the number of examples
        # which are created per split.
        self._debug_num_examples_per_split = 0
Exemple #3
0
 def setUp(self):
   super().setUp()
   feature_args = {
       'box_labels': {'num_box_labels': 5},
       'person_keypoints': {'num_keypoints': 16},
       'person_position': {'dim_per_position': 4},
   }
   self.features = fids_features.FeatureUtils(feature_args)
Exemple #4
0
 def testGetSpecificFakeFeature(
     self, feature_name, expected, feature_args=None):
   feature_utils = fids_features.FeatureUtils(feature_args)
   fake_feature = feature_utils.get_fake_feature(feature_name)
   if isinstance(expected, np.ndarray):
     self.assertAllEqual(fake_feature, expected)
   elif isinstance(expected, list):
     self._assertSequenceEqual(fake_feature, expected)
   else:
     self.assertEqual(fake_feature, expected)
Exemple #5
0
    def set_features_and_splits(self):
        box_feature_args = {'box_labels': {'num_box_labels': len(BOX_LABELS)}}
        self.feature_utils = fids_features.FeatureUtils(box_feature_args)

        mseg_segmentation_features = self.MSEG_FEATURE_NAMES.copy()
        mseg_segmentation_features.remove('image')

        if self.bdd_type == ALL_DENSE_3K:
            self.feature_names = self.MSEG_FEATURE_NAMES + [
                'boxes', 'box_labels', 'drivable', 'instance_segmentation'
            ]
            self.splits = ['train', 'test']
            self.splits_with_missing_features = {
                'test':
                mseg_segmentation_features + [
                    'boxes',
                    'box_labels',
                    'drivable',
                ]
            }
        elif self.bdd_type == MSEG:
            self.feature_names = self.MSEG_FEATURE_NAMES + [
                'instance_segmentation'
            ]
            self.splits = ['train', 'validation', 'test']
            self.splits_with_missing_features = {
                'test': mseg_segmentation_features + ['instance_segmentation']
            }
        elif self.bdd_type == DETECTION_100K:
            self.feature_names = ['image', 'boxes', 'box_labels', 'drivable']
            self.splits = ['train', 'validation', 'test']
            self.splits_with_missing_features = {
                'test': ['boxes', 'box_labels', 'drivable']
            }
        else:
            assert self.bdd_type == ALL_SPARSE_107K, (
                f'Unexpected BDD type {self.bdd_type}')

            self.feature_names = self.MSEG_FEATURE_NAMES + [
                'boxes',
                'box_labels',
                'drivable',
                'instance_segmentation',
            ]
            self.splits = ['train', 'validation', 'test']
            missing_features = mseg_segmentation_features + [
                'boxes', 'box_labels', 'drivable', 'instance_segmentation'
            ]
            self.splits_with_missing_features = {
                'train': missing_features,
                'validation': missing_features,
                'test': missing_features
            }
Exemple #6
0
 def testWrongFeatureNameInFeatureArgsRaisesAttributeError(self):
   with self.assertRaises(AttributeError):
     fids_features.FeatureUtils({'boxlabels': {'num_box_labels': 3}})
Exemple #7
0
 def testWrongNamedArgsInFeatureArgsRaisesTypeError(self, feature_args):
   with self.assertRaises(TypeError):
     fids_features.FeatureUtils(feature_args)